From patchwork Thu Dec 21 22:54:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 852162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88520-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="SQ7PM6GU"; dkim-atps=neutral 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 3z2n6Y399cz9s7F for ; Fri, 22 Dec 2017 09:55:33 +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:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=enbrJ5owtVoaBXB1MLQy8YwUnFJfdGK 280o22XVbNgKM1dedD2tEuGJELgCar8ohmYXeXBIuYYcMQqC6hrF389om7mUOdLo DOeIPKgschBLsND1H0OrzRjSpmTzXJ6bZPSlkSnFjhsKFU+iyb6tJHQgk5WeEkAK AYvlRt6ahz5w= 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:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=6/UZPk4LJC2bRqC2GPfTGI0aFCk=; b=SQ7PM 6GUOanIAO13xB9Fz5naxpCF8mq7J/SJtyLPUh6hij1QtnEoFJg/GulC7Ur4UHXg9 zCNqBpj7WQpwZcatsisB2kgInJcx6+VCukhU0QwVc7Yp46WngOKldQOpAw+lyMwM 28CcJSYiYeo/thklxLj4RLQOxSBOStn2ScaFRc= Received: (qmail 50394 invoked by alias); 21 Dec 2017 22:55:06 -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 50165 invoked by uid 89); 21 Dec 2017 22:55:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1260 X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 1/3] tst-realloc: do not check for errno on success [BZ #22611] Date: Thu, 21 Dec 2017 23:54:51 +0100 Message-Id: <20171221225453.13158-2-aurelien@aurel32.net> In-Reply-To: <20171221225453.13158-1-aurelien@aurel32.net> References: <20171221225453.13158-1-aurelien@aurel32.net> POSIX explicitly says that applications should check errno only after failure, so the errno value can be clobbered on success as long as it is not set to zero. Changelog: [BZ #22611] * malloc/tst-realloc.c (do_test): Remove the test checking that errno is unchanged on success. Reviewed-by: Carlos O'Donell --- ChangeLog | 6 ++++++ malloc/tst-realloc.c | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55295b1368..cb41a07a25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-12-21 Aurelien Jarno + + [BZ #22611] + * malloc/tst-realloc.c (do_test): Remove the test checking that errno + is unchanged on success. + 2017-12-21 Szabolcs Nagy * scripts/build-many-glibcs.py (Context.add_all_configs): Add diff --git a/malloc/tst-realloc.c b/malloc/tst-realloc.c index 31a58bd026..d942c6e536 100644 --- a/malloc/tst-realloc.c +++ b/malloc/tst-realloc.c @@ -66,10 +66,6 @@ do_test (void) if (p == NULL) merror ("realloc (NULL, 10) failed."); - /* errno should be clear on success (POSIX). */ - if (p != NULL && save != 0) - merror ("errno is set but should not be"); - free (p); p = calloc (20, 1); From patchwork Thu Dec 21 22:54:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 852163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88521-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="H44gBSfx"; dkim-atps=neutral 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 3z2n6j1mdXz9s7F for ; Fri, 22 Dec 2017 09:55:41 +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:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=CnE9+Z3A3IAXZNifK2ajZkf/tU8w8NH Cv8UiqNJglNiwIJfsuz1HmBfhu3qjwY6LsrZlnMw/qlYelShA70UWxCK0E1kvQT2 vzSgDSId/rqytseSXJTkyAGzulbzogz/5l1uycCj5zwd80CLWG2D4YHpU+feitg6 1X6Ov38J2xpU= 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:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=liruIIXgALRcWUbNniK6aWcyFns=; b=H44gB SfxCrfxAFVxw0wd+B4AOtTHPMyjatKzZlNsHOqmZNm0RgeyRGrfMu6gSbWgHF23X +GIXdofnwUjZesp4z9GN4GnDR8ZD7tTMBuEyYIjcjTwrnLh7C2POtwKTKHM7vwsN Z9TZAAtD9NO9g7Fz7PabVl9XtSh2yrm880Kl7I= Received: (qmail 50407 invoked by alias); 21 Dec 2017 22:55:06 -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 50197 invoked by uid 89); 21 Dec 2017 22:55:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 2/3] manual: clarify errno value on success [BZ #22615] Date: Thu, 21 Dec 2017 23:54:52 +0100 Message-Id: <20171221225453.13158-3-aurelien@aurel32.net> In-Reply-To: <20171221225453.13158-1-aurelien@aurel32.net> References: <20171221225453.13158-1-aurelien@aurel32.net> The current glibc manual is ambiguous about the errno value on success and suggests that it is left unchanged. Some functions might and sometimes do change the errno value, however they never set it to 0. This patch clarifies this section of the manual. Changelog: [BZ #22615] * manual/errno.texi (Checking for Errors): Explicitly say that errno might be set on success. Reviewed-by: Carlos O'Donell --- ChangeLog | 6 ++++++ manual/errno.texi | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index cb41a07a25..7bf30d27ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-12-21 Aurelien Jarno + + [BZ #22615] + * manual/errno.texi (Checking for Errors): Explicitly say that errno + might be set on success. + 2017-12-21 Aurelien Jarno [BZ #22611] diff --git a/manual/errno.texi b/manual/errno.texi index 3e0b862c4e..eaac8e6dca 100644 --- a/manual/errno.texi +++ b/manual/errno.texi @@ -50,12 +50,12 @@ possibility except when writing signal handlers. The initial value of @code{errno} at program startup is zero. Many library functions are guaranteed to set it to certain nonzero values when they encounter certain kinds of errors. These error conditions are -listed for each function. These functions do not change @code{errno} -when they succeed; thus, the value of @code{errno} after a successful -call is not necessarily zero, and you should not use @code{errno} to -determine @emph{whether} a call failed. The proper way to do that is -documented for each function. @emph{If} the call failed, you can -examine @code{errno}. +listed for each function. These functions never set @code{errno} to zero +and might set it to a non-zero value when they succeed; thus, the value of +@code{errno} after a successful call is not necessarily zero, and you +should not use @code{errno} to determine @emph{whether} a call failed. +The proper way to do that is documented for each function. @emph{If} the +call failed, you can examine @code{errno}. Many library functions can set @code{errno} to a nonzero value as a result of calling other library functions which might fail. You should From patchwork Thu Dec 21 22:54:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 852161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88519-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Sv/lbdtD"; dkim-atps=neutral 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 3z2n6P1kl9z9s7F for ; Fri, 22 Dec 2017 09:55:25 +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:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=Ai0nX/hnyHf8ovm+jexaCQnulfyV9Vu O94jVtnLo0gv55n5GUa4StpypoIsP0klq4p8AWucXuvwry1OcDtJ9zuekGzmH9B/ z+zIJ1Ie7byCeyf0H6J/DZe5wNrvoTGaWi81LoWM02PiWvtzeiVMH8AM24lSxNZq 6/mwqucC7L2U= 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:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=fkDKlhsHmNBqctlAtTe4its2ZCY=; b=Sv/lb dtDJBMO2B3XxY/PbcTNB4VrB4Yua7J5OOkhgVHQyJ1MHFDcjMP8NLY2kmX6pHf6U FGyFz7Edg/bvq+iau0trTVl/KiM0VjSUJWGaVHMhOKQksOaKhgeJ+ivMGFPT7NYq UWYWDIJ/6vr0dkEYFetcuJ7IMa102rCOJ3X5nI= Received: (qmail 50274 invoked by alias); 21 Dec 2017 22:55:06 -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 50178 invoked by uid 89); 21 Dec 2017 22:55:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1662 X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH 3/3] scandir: fix wrong assumption about errno [BZ #17804] Date: Thu, 21 Dec 2017 23:54:53 +0100 Message-Id: <20171221225453.13158-4-aurelien@aurel32.net> In-Reply-To: <20171221225453.13158-1-aurelien@aurel32.net> References: <20171221225453.13158-1-aurelien@aurel32.net> malloc and realloc may set errno to ENOMEM even if they are successful. The scandir code wrongly assume that they do not change errno, this causes scandir to fail with ENOMEM even if malloc succeed. The code already handles that readdir might set errno by calling __set_errno (0) to clear the error. Move that part at the end of the loop to also take malloc and realloc into account. Changelog: [BZ #17804] * dirent/scandir-tail.c (SCANDIR_TAIL): Move __set_errno (0) at the end of the loop. Reviewed-by: Carlos O'Donell --- ChangeLog | 6 ++++++ dirent/scandir-tail.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7bf30d27ef..31fddf5794 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-12-21 Aurelien Jarno + + [BZ #17804] + * dirent/scandir-tail.c (SCANDIR_TAIL): Move __set_errno (0) at the + end of the loop. + 2017-12-21 Aurelien Jarno [BZ #22615] diff --git a/dirent/scandir-tail.c b/dirent/scandir-tail.c index 068c644c4e..00fe9ef030 100644 --- a/dirent/scandir-tail.c +++ b/dirent/scandir-tail.c @@ -61,8 +61,6 @@ SCANDIR_TAIL (DIR *dp, if (!selected) continue; } - else - __set_errno (0); if (__glibc_unlikely (c.cnt == vsize)) { @@ -81,6 +79,11 @@ SCANDIR_TAIL (DIR *dp, if (vnew == NULL) break; v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize); + + /* Ignore errors from readdir, malloc or realloc. These functions + might have changed errno. It was zero before and it need to be + again to make the latter tests work. */ + __set_errno (0); } if (__glibc_likely (errno == 0))