From patchwork Wed Jun 27 20:14:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 28085 Received: (qmail 82107 invoked by alias); 27 Jun 2018 20:14:28 -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 82093 invoked by uid 89); 27 Jun 2018 20:14:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=H*M:20622, H*r:0700 X-HELO: 9pmail.ess.barracuda.com Date: Wed, 27 Jun 2018 21:14:01 +0100 From: "Maciej W. Rozycki" To: DJ Delorie CC: Subject: [committed v3] nisplus: Correct pwent parsing issue and resulting build error [BZ #23266] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Return-Path: macro@mips.com X-BESS-Apparent-Source-IP: 12.201.5.32 Copy and null-terminate NIS+ password file UID and GID entries whose length is non-zero and are not terminated, in addition to empty ones, fixing a bug and a compilation issue causing an error with GCC 8: nss_nisplus/nisplus-parser.c: In function '_nss_nisplus_parse_pwent': nss_nisplus/nisplus-parser.c:90:7: error: 'strncpy' destination unchanged after copying no bytes [-Werror=stringop-truncation] strncpy (first_unused, numstr, len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ nss_nisplus/nisplus-parser.c:106:7: error: 'strncpy' destination unchanged after copying no bytes [-Werror=stringop-truncation] strncpy (first_unused, numstr, len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ introduced with commit ac05397075f6: commit ac05397075f621cfdbe1db527c96167a58b6d18e Author: Ulrich Drepper Date: Sun Apr 30 07:01:26 2006 +0000 * nis/nss_nisplus/nisplus-parser.c: Minor optimizations and cleanups. Avoid copying data if it can be used in the old place. (no mailing list reference available). Obviously regardless of the recently added compiler diagnostics causing a build error this code has been long non-functional, so I guess NIS+ servers have been supplying strings that are non-empty and have already been null-terminated. Which in turn made it unnecessary to make a null-terminated copy, masking this bug. [BZ #23266] * nis/nss_nisplus/nisplus-parser.c (_nss_nisplus_parse_pwent): Copy and null-terminate entries that are not terminated, in addition to empty ones. --- On Mon, 25 Jun 2018, DJ Delorie wrote: > > Ping for: > > > > > > > > Previous discussion: > > > > > > LGTM Thanks, applied now, with two minor updates: * s/compilation/build/ in the heading so that it fits in 79 columns with GIT's indentation applied, * a comma added after "are not terminated" in the description and ChangeLog, for clarity, which I have decided that qualify as trivial and therefore not requiring further consensus. Here's the actual version committed, for future reference. Maciej --- ChangeLog | 7 +++++++ nis/nss_nisplus/nisplus-parser.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c index 8dc021e..d2b0633 100644 --- a/nis/nss_nisplus/nisplus-parser.c +++ b/nis/nss_nisplus/nisplus-parser.c @@ -82,7 +82,7 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, char *numstr = NISOBJVAL (2, obj); len = NISOBJLEN (2, obj); - if (len == 0 && numstr[len - 1] != '\0') + if (len == 0 || numstr[len - 1] != '\0') { if (len >= room_left) goto no_more_room; @@ -98,7 +98,7 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, numstr = NISOBJVAL (3, obj); len = NISOBJLEN (3, obj); - if (len == 0 && numstr[len - 1] != '\0') + if (len == 0 || numstr[len - 1] != '\0') { if (len >= room_left) goto no_more_room;