From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 87904 invoked by alias); 12 Apr 2018 15:31:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 87510 invoked by uid 89); 12 Apr 2018 15:31:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KHOP_DYNAMIC,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=nis X-HELO: mx0a-001b2d01.pphosted.com Subject: Re: [PATCH] Replace strncpy with memccpy to fix -Wstringop-truncation. To: libc-alpha@sourceware.org References: <20180323010729.41457-1-raj.khem@gmail.com> <796d9b52-7270-69d4-cfc2-1ce05b6ebbf1@linux.vnet.ibm.com> From: Stefan Liebler Cc: schwab@suse.de Date: Thu, 12 Apr 2018 15:31:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------B8F8D5BEF4705008248F9369" X-TM-AS-GCONF: 00 x-cbid: 18041215-0040-0000-0000-0000044CD1D8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041215-0041-0000-0000-000020F10682 Message-Id: <980fefe5-31ac-e5be-afb5-102b873dc567@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-12_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804120153 X-SW-Source: 2018-04/txt/msg00209.txt.bz2 This is a multi-part message in MIME format. --------------B8F8D5BEF4705008248F9369 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 683 On 04/05/2018 06:14 PM, Andreas Schwab wrote: > On Apr 05 2018, Stefan Liebler wrote: > >> Why do we need the strncpy at all? >> if (len == 0 && ...) > > That's obviously a typo. > > Andreas. > Yes. You are right. Please have a look at the applied patch. If the zero-termination is needed, numstr is copied to the buffer with strncpy and the zero-termination is applied. If numstr is either 0 bytes long or the length of the numstr string is 0, then _nss_nisplus_parse_pwent returns with 0. This solves the mentioned warning with if build with gcc-head and --enable-obsolete-nsl. But I can not test it as I don't have a nisplus setup. Bye. Stefan --------------B8F8D5BEF4705008248F9369 Content-Type: text/x-patch; name="20180412_nisplus-parser.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="20180412_nisplus-parser.patch" Content-length: 1388 diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c index 8dc021e73d..4714a3085a 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; @@ -91,14 +91,14 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, first_unused[len] = '\0'; numstr = first_unused; } - if (numstr[0] == '\0') + if (len == 0 || numstr[0] == '\0') /* If we don't have a uid, it's an invalid shadow entry. */ return 0; pw->pw_uid = strtoul (numstr, NULL, 10); 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; @@ -107,7 +107,7 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, first_unused[len] = '\0'; numstr = first_unused; } - if (numstr[0] == '\0') + if (len == 0 || numstr[0] == '\0') /* If we don't have a gid, it's an invalid shadow entry. */ return 0; pw->pw_gid = strtoul (numstr, NULL, 10); --------------B8F8D5BEF4705008248F9369--