From patchwork Sun Aug 2 20:16:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 502926 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 11509140129 for ; Mon, 3 Aug 2015 06:17:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=yhJ/woRt; dkim-atps=neutral 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:from:date:message-id:subject:to :cc:content-type; q=dns; s=default; b=k6ASL7VbixSSgjRiujijpDrRsw LlMFM123lqDkMJtKGw02+VFRCaqjM5RxZxqJUNjkxeVdfU069ey1VxHqd6pSgoog 7g4Neb9G/F2pfWdrINr45CoFtuAPFc3NUWzL+sk0PgyMqO/9pfYocxJt6qqplzeh NwXXOUQ4mf/TzpdvA= 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:from:date:message-id:subject:to :cc:content-type; s=default; bh=NwQukQMPjkv/ro00evqBgH609zg=; b= yhJ/woRt91JZrxKW3YX19D3+80uGZzMdR7udlb3SolBE9kE7Yh9LBSpe8lBZ5Icm kgA1F8kF3RUKIxpvQ3+aD4ugbxrPJ3cfcYX2FhIkZX3z8rCXVDYmHF2Dp079k1nF epUMd8aUMopZN3XuyK6dc7X+OXR+m7bgQ6w7ogPKv/s= Received: (qmail 109570 invoked by alias); 2 Aug 2015 20:17:07 -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 109557 invoked by uid 89); 2 Aug 2015 20:17:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vk0-f41.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:cc:content-type; bh=l4COuJMhxEV+8Gfae9eI2BkFTlzs5HsEw9MlY8RWfDk=; b=gnjHpv7LGXgJCE31jMtMU0gstx8B+JkKQeMcfSnv6wUYm/vWQZCUTuLr+2c3b2bD1A Y4xFDLA098t4uDz97yNr0PjnwaR5Y13aoYrQq2Vm33YEWJ47JelS3b+lAgqRRbxsnS0Q 3Lm9Mzr42v+CEd6h6YhOgONj74hQgHZMYr0B5QKevGYj0mhJGM2sa2NgJeKFiF/eSJK6 iE2Os4ruHzXBL6Nya4EeG48kJEfxfJOAkLpuaj4mdKOHewjVM12cR1sglTCE1HU5U/BK fMfNIGLY3afX04xLxWL3RpXCwU77qTx8GUIOMepYbsPAMAN5O2DDWTbb/MayYqoDnRSc KVKw== X-Gm-Message-State: ALoCoQnPivN7IJyMVN+tOyfp4WGlPWkQM5R67KNZ4HXr69PvnB+EjSsTU39XjAa8pqL4bSanvllQ X-Received: by 10.52.112.67 with SMTP id io3mr22317500vdb.58.1438546623523; Sun, 02 Aug 2015 13:17:03 -0700 (PDT) MIME-Version: 1.0 From: Paul Pluzhnikov Date: Sun, 2 Aug 2015 13:16:33 -0700 Message-ID: Subject: Fix BZ 18756 (fmemopen(..., 0, ...) does not fail) To: GLIBC Devel Cc: adhemerval.zanella@linaro.org, "Carlos O'Donell" Greetings, Attached trivial patch fixes BZ 18756 and adds a test case for it. Since this is new breakage in 2.22, I say it should go in despite the hard freeze. Thanks, 2015-08-02 Paul Pluzhnikov [BZ #18756] * libio/fmemopen.c (__fmemopen): Check for 0 len. * libio/test-fmemopen.c (do_bz18756): New test. diff --git a/libio/fmemopen.c b/libio/fmemopen.c index 3ab3e8d..c58f376 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -150,6 +150,12 @@ __fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; + if (__glibc_unlikely (len == 0)) + { + __set_errno (EINVAL); + return NULL; + } + c = (fmemopen_cookie_t *) calloc (sizeof (fmemopen_cookie_t), 1); if (c == NULL) return NULL; diff --git a/libio/test-fmemopen.c b/libio/test-fmemopen.c index 63ca89f..81371fa 100644 --- a/libio/test-fmemopen.c +++ b/libio/test-fmemopen.c @@ -24,6 +24,27 @@ static char buffer[] = "foobar"; #include static int +do_bz18756 (void) +{ + int ch; + int ret = 0; + FILE *stream; + + errno = 0; + stream = fmemopen (&ch, 0, "w"); + if (stream != NULL || errno != EINVAL) + { + printf ("fmemopen zero-sized buffer: stream = %p, %m\n", stream); + ret = 1; + } + + if (stream != NULL) + fclose (stream); + + return ret; +} + +static int do_test (void) { int ch; @@ -44,7 +65,7 @@ do_test (void) fclose (stream); - return ret; + return ret + do_bz18756 (); } #define TEST_FUNCTION do_test ()