From patchwork Sun Feb 22 19:44:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 442308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 235691400EA for ; Mon, 23 Feb 2015 06:44:53 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; q=dns; s=default; b= YCy850/UnEUM0TClUML42/YIxVAETTQdEIAyNTBlvuac1891p62e1AZnpRLbq8Vl eKAsbogfIV7I/K0qAYENIia3KUAp/PVXX6tkg3N5+CcX1V22mhrcPtV0DtZUNORB nN++PLp9AI+d6SOXIIgnXrNjJGzXyRUTAVs4dVMIl9E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; s=default; bh=MDWE7 UjR6xzUxEpzvfP+wIF2mfY=; b=I+BsPFkXIFGVVL/g1m5qnh3MSuJOZd5O8ihhR ODmKIYFHo+zKHjNSrpFfGgaUpY4vzA1sO0HLs+v4YFTxD4lLY92umOOsXFFdSViw wKPvIAWQaYNkgaWyZzlwepERe+4Z148uznVF6vxifjbSL8MMjG61DGDm0NaaUgLP lKxVk4= Received: (qmail 23349 invoked by alias); 22 Feb 2015 19:44:47 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 23339 invoked by uid 89); 22 Feb 2015 19:44:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ig0-f180.google.com MIME-Version: 1.0 X-Received: by 10.42.52.200 with SMTP id k8mr8138426icg.26.1424634283880; Sun, 22 Feb 2015 11:44:43 -0800 (PST) In-Reply-To: <87fv9yfdsx.fsf@mid.deneb.enyo.de> References: <87fv9yfdsx.fsf@mid.deneb.enyo.de> Date: Sun, 22 Feb 2015 11:44:43 -0800 Message-ID: Subject: Re: [patch] Fix BZ #17269 _IO_wstr_overflow integer overflow From: Paul Pluzhnikov To: Florian Weimer Cc: GLIBC Devel On Sun, Feb 22, 2015 at 2:20 AM, Florian Weimer wrote: > “new_size == SIZE_MAX / sizeof (wchar_t)” should still be okay, > shouldn't it? Right. 2015-02-22 Paul Pluzhnikov [BZ #17269] * NEWS: Mention 17269 * libio/wstrops.c (_IO_wstr_overflow): Guard against integer overflow (enlarge_userbuf): Likewise. diff --git a/NEWS b/NEWS index 5eb79d2..28ef45d 100644 --- a/NEWS +++ b/NEWS @@ -9,9 +9,9 @@ Version 2.22 * The following bugs are resolved with this release: - 4719, 13064, 14094, 15319, 15467, 15790, 16560, 17569, 17588, 17792, - 17912, 17932, 17944, 17949, 17964, 17965, 17967, 17969, 17978, 17987, - 17991, 17996, 17998, 17999. + 4719, 13064, 14094, 15319, 15467, 15790, 16560, 17269, 17569, 17588, + 17792, 17912, 17932, 17944, 17949, 17964, 17965, 17967, 17969, 17978, + 17987, 17991, 17996, 17998, 17999. * Character encoding and ctype tables were updated to Unicode 7.0.0, using new generator scripts contributed by Pravin Satpute and Mike FABIAN (Red diff --git a/libio/wstrops.c b/libio/wstrops.c index 43d847d..3993579 100644 --- a/libio/wstrops.c +++ b/libio/wstrops.c @@ -95,8 +95,11 @@ _IO_wstr_overflow (fp, c) wchar_t *old_buf = fp->_wide_data->_IO_buf_base; size_t old_wblen = _IO_wblen (fp); _IO_size_t new_size = 2 * old_wblen + 100; - if (new_size < old_wblen) + + if (__glibc_unlikely (new_size < old_wblen) + || __glibc_unlikely (new_size > SIZE_MAX / sizeof (wchar_t))) return EOF; + new_buf = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (new_size * sizeof (wchar_t)); @@ -186,6 +189,9 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading) return 1; _IO_size_t newsize = offset + 100; + if (__glibc_unlikely (newsize > SIZE_MAX / sizeof (wchar_t))) + return 1; + wchar_t *oldbuf = wd->_IO_buf_base; wchar_t *newbuf = (wchar_t *) (*((_IO_strfile *) fp)->_s._allocate_buffer) (newsize