From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 025033857BB2; Wed, 5 Oct 2022 21:43:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 025033857BB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665006230; bh=Ot5PdNAp+t04uaSCIG/YGfUbhALtF74CB4fSp3d+Omk=; h=From:To:Subject:Date:From; b=OH3QMMes37M38R4NC9k++2cWhrC3zIWcQtp8hTinm3lzHhc/vlPe7Dq8wilDFyxym +IJrO2J73r5KouNtxMnVZvZI64FH5GpYpwWu1Ugca7tFkv3pAIZ90YOb40zc5GMXeq tNpA90gMW5Kdr7Y+dYHcXD1esNsBU7jgDr52d/jQ= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] sunrpc: Suppress GCC -Os warning on user2netname X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella Netto X-Git-Refname: refs/heads/master X-Git-Oldrev: cbf24edbb3123e3154ad2366912e0c1270ad3546 X-Git-Newrev: 6128e82ebe973163d2dd614d31753c88c0c4d645 Message-Id: <20221005214350.025033857BB2@sourceware.org> Date: Wed, 5 Oct 2022 21:43:49 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6128e82ebe973163d2dd614d31753c88c0c4d645 commit 6128e82ebe973163d2dd614d31753c88c0c4d645 Author: Adhemerval Zanella Netto Date: Wed Sep 21 10:51:07 2022 -0300 sunrpc: Suppress GCC -Os warning on user2netname GCC with -Os warns that sprint might overflow: netname.c: In function ‘user2netname’: netname.c:51:28: error: ‘%s’ directive writing up to 255 bytes into a region of size between 239 and 249 [-Werror=format-overflow=] 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); | ^~ ~~~~~~~ netname.c:51:3: note: ‘sprintf’ output between 8 and 273 bytes into a destination of size 256 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors However the code does test prior the sprintf call that dfltdom plus the required extra space for OPSYS, uid, and extra character will not overflow and return 0 instead. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell Diff: --- sunrpc/netname.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sunrpc/netname.c b/sunrpc/netname.c index bf7f0b81c4..c1d1c43e50 100644 --- a/sunrpc/netname.c +++ b/sunrpc/netname.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "nsswitch.h" @@ -48,7 +49,12 @@ user2netname (char netname[MAXNETNAMELEN + 1], const uid_t uid, if ((strlen (dfltdom) + OPSYS_LEN + 3 + MAXIPRINT) > (size_t) MAXNETNAMELEN) return 0; + /* GCC with -Os warns that sprint might overflow while handling dfltdom, + however the above test does check if an overflow would happen. */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wformat-overflow"); sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); + DIAG_POP_NEEDS_COMMENT; i = strlen (netname); if (netname[i - 1] == '.') netname[i - 1] = '\0';