From patchwork Fri Aug 14 05:52:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 507275 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 9B8771401EF for ; Fri, 14 Aug 2015 16:22:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=gVtGjrnt; 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 :content-type; q=dns; s=default; b=E7rINBqpKowxqe5AuEHYFtm0NX/pZ zyzeoUk30KMYq7qS4ycOjS1uh66pnm9OQ+MjkNI6cy8zHK2MQuVz6BTg8L4UWzUz RFQ+CTLKwxIr/QmB2hjxrbafx1JZap8illjtLZfrEUEUeBVgF3ozjEFzS7cEy3V1 cc7ydtlD+gcsWA= 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 :content-type; s=default; bh=/4xt0Be7PJuVIQFhljff0UtXuOw=; b=gVt Gjrntt9dyobd6WTuLmOwlmXRZw1wjn/wyiI3AV72u6VdYTi8wNm5aAWr5RX2aQwB lkNRuYO78a1JQGvPuJkkrAN9UfCE6Cv4PMjtywfIXRSw/CpZ1mdtAQ5jZgj3B65m nKUpb5pr0KThtM56hARWEF/k8qBpyGw36MIGAspk= Received: (qmail 39439 invoked by alias); 14 Aug 2015 06:22:22 -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 39413 invoked by uid 89); 14 Aug 2015 06:22:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 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-f42.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:content-type; bh=AvO4W75zygXsQPJE2QD6z97P/ZofH3CIN2fA8n0A0Uw=; b=ckwiOhW1ZjW4MXQFsvXv2QOlupuv6HcwTSHZZl5Pa+ksCM6aa5q7o54hCwUIbqFsqS vXyY3o44pAFKNAKGPvzP0UZUHlg3jhwVNT9lMv5JEGZ3PQwt3ZmIHrg+8noOGygRVGt3 VpcLqDKshIla6JqYX3j6LgKsL71B8lcTBpxXoMaw3qTg5nQKlRI5bJvJnPtjaMtJRQVl xdW4i4PIr5fwznY+TxFDc7v3ULSRUS7o9520tf2DbJ8ZbQElxXgB1SNMpMaPA2x8BvCR pzFP40eft9J9ZozYOlqh4P2q0XTQNL5Viqy1eympVyYKUuc2aoTWGf1PvH+p1Auy2r1M II7g== X-Gm-Message-State: ALoCoQk8Ddo/4CkAIA+M+wr0U+8eKuFttPehJa6GbzD3JfNgGKu+eiFGToVzLG1i6PeF1FvhTovM X-Received: by 10.52.98.131 with SMTP id ei3mr51517119vdb.2.1439531561091; Thu, 13 Aug 2015 22:52:41 -0700 (PDT) MIME-Version: 1.0 From: Paul Pluzhnikov Date: Thu, 13 Aug 2015 22:52:11 -0700 Message-ID: Subject: Fix BZ #18757 - fmemopen fails to set errno on failure To: GLIBC Devel Greetings, Attached patch fixes BZ #18757 - fmemopen fails to set errno when failure is caused by invalid mode, or request for too much memory. The added test is currently failing due to a bug in mtrace.pl: https://sourceware.org/ml/libc-alpha/2015-08/msg00546.html So this patch would need to go in after mtrace is fixed. Thanks, 2015-08-13 Paul Pluzhnikov [BZ #18757] * libio/iofopncook.c (_IO_fopencookie): Set errno on failure * libio/test-fmemopen.c (do_bz18820): Extend the test to cover BZ #18757 diff --git a/libio/iofopncook.c b/libio/iofopncook.c index b845d29..ecf40ac 100644 --- a/libio/iofopncook.c +++ b/libio/iofopncook.c @@ -189,6 +189,7 @@ _IO_fopencookie (cookie, mode, io_functions) read_write = _IO_NO_READS|_IO_IS_APPENDING; break; default: + __set_errno (EINVAL); return NULL; } if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) @@ -196,7 +197,10 @@ _IO_fopencookie (cookie, mode, io_functions) new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE)); if (new_f == NULL) - return NULL; + { + __set_errno (ENOMEM); + return NULL; + } #ifdef _IO_MTSAFE_IO new_f->cfile.__fp.file._lock = &new_f->lock; #endif diff --git a/libio/test-fmemopen.c b/libio/test-fmemopen.c index e8e757f..a62f664 100644 --- a/libio/test-fmemopen.c +++ b/libio/test-fmemopen.c @@ -19,6 +19,7 @@ static char buffer[] = "foobar"; +#include #include #include #include @@ -30,6 +31,7 @@ do_bz18820 (void) char ch; FILE *stream; + errno = 0; stream = fmemopen (&ch, 1, "?"); if (stream) { @@ -37,6 +39,11 @@ do_bz18820 (void) fclose (stream); return 1; } + if (errno != EINVAL) + { + printf ("fmemopen: got %i, expected EINVAL (%i)\n", errno, EINVAL); + return 10; + } stream = fmemopen (NULL, 42, "?"); if (stream) @@ -46,6 +53,20 @@ do_bz18820 (void) return 2; } + errno = 0; + stream = fmemopen (NULL, ~0, "w"); + if (stream) + { + printf ("fmemopen: expected NULL, got %p\n", stream); + fclose (stream); + return 3; + } + if (errno != ENOMEM) + { + printf ("fmemopen: got %i, expected ENOMEM (%i)\n", errno, ENOMEM); + return 20; + } + return 0; }