From patchwork Tue May 12 12:52:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 38971 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DE52383F84C; Tue, 12 May 2020 12:52:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DE52383F84C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589287959; bh=XKwnjHGJy5j7PH/roHdtbzC7avqbIBZyDf4S3nEUc6I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dOXhJCJzZZGz253V0nsvckYTfzyksWD/8Zz1cj45BQalEpq/iLfFU+/KS3BSNn1An 16qxyj/c4scVIBp8s81JR7+b1wNeWb6HI+5Smwen+cRA5GC2FCeWyfoE/G+o3uajLa yzchJII5plkprPmVd92/Q7icU8bMqAHs23iX/DmE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 4E41C386F83F for ; Tue, 12 May 2020 12:52:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4E41C386F83F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-UzFElKTOPd6ZRFPIOXIK_g-1; Tue, 12 May 2020 08:52:34 -0400 X-MC-Unique: UzFElKTOPd6ZRFPIOXIK_g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC602800687 for ; Tue, 12 May 2020 12:52:33 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-115-98.ams2.redhat.com [10.36.115.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28C835D9E5 for ; Tue, 12 May 2020 12:52:33 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] nss_compat: internal_end*ent may clobber errno, hiding ERANGE [BZ #25976] Date: Tue, 12 May 2020 14:52:31 +0200 Message-ID: <8736859uy8.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Change the internal_end*ent functions to preserve errno because they are called on error-returning paths, where the value of errno matters. For the external-facing _nss_compat_end*ent functions, this is not required because they always report success, so they may clobber errno. ----- nss/nss_compat/compat-grp.c | 3 +++ nss/nss_compat/compat-initgroups.c | 3 +++ nss/nss_compat/compat-pwd.c | 3 +++ nss/nss_compat/compat-spwd.c | 3 +++ 4 files changed, 12 insertions(+) diff --git a/nss/nss_compat/compat-grp.c b/nss/nss_compat/compat-grp.c index 14aadc6f01..173c71abd5 100644 --- a/nss/nss_compat/compat-grp.c +++ b/nss/nss_compat/compat-grp.c @@ -147,6 +147,8 @@ _nss_compat_setgrent (int stayopen) static enum nss_status internal_endgrent (ent_t *ent) { + int saved_errno = errno; + if (ent->stream != NULL) { fclose (ent->stream); @@ -162,6 +164,7 @@ internal_endgrent (ent_t *ent) else ent->blacklist.current = 0; + __set_errno (saved_errno); return NSS_STATUS_SUCCESS; } diff --git a/nss/nss_compat/compat-initgroups.c b/nss/nss_compat/compat-initgroups.c index 67a4c100f6..60c8af64a3 100644 --- a/nss/nss_compat/compat-initgroups.c +++ b/nss/nss_compat/compat-initgroups.c @@ -137,6 +137,8 @@ internal_setgrent (ent_t *ent) static enum nss_status internal_endgrent (ent_t *ent) { + int saved_errno = errno; + if (ent->stream != NULL) { fclose (ent->stream); @@ -155,6 +157,7 @@ internal_endgrent (ent_t *ent) if (ent->need_endgrent && endgrent_impl != NULL) endgrent_impl (); + __set_errno (saved_errno); return NSS_STATUS_SUCCESS; } diff --git a/nss/nss_compat/compat-pwd.c b/nss/nss_compat/compat-pwd.c index dfb454f777..7fbce88e7e 100644 --- a/nss/nss_compat/compat-pwd.c +++ b/nss/nss_compat/compat-pwd.c @@ -264,6 +264,8 @@ _nss_compat_setpwent (int stayopen) static enum nss_status internal_endpwent (ent_t *ent) { + int saved_errno = errno; + if (ent->stream != NULL) { fclose (ent->stream); @@ -286,6 +288,7 @@ internal_endpwent (ent_t *ent) give_pwd_free (&ent->pwd); + __set_errno (saved_errno); return NSS_STATUS_SUCCESS; } diff --git a/nss/nss_compat/compat-spwd.c b/nss/nss_compat/compat-spwd.c index 0a1fde1ea4..39eed87de8 100644 --- a/nss/nss_compat/compat-spwd.c +++ b/nss/nss_compat/compat-spwd.c @@ -220,6 +220,8 @@ _nss_compat_setspent (int stayopen) static enum nss_status internal_endspent (ent_t *ent) { + int saved_errno = errno; + if (ent->stream != NULL) { fclose (ent->stream); @@ -243,6 +245,7 @@ internal_endspent (ent_t *ent) give_spwd_free (&ent->pwd); + __set_errno (saved_errno); return NSS_STATUS_SUCCESS; }