From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id DA1483858028 for ; Wed, 21 Sep 2022 13:51:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA1483858028 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1278624b7c4so9125323fac.5 for ; Wed, 21 Sep 2022 06:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=20qWx9xGjOYDijsTmK59UPcgX2htVy0Z9x8Cm4cuKl0=; b=SiYp3KsezddSoFvgdonFxABTjeX6EQoUll8yKFEqQvZYto8zSBA/CAoo9YNZ52FKML xnAaYJtCtUqerjtYfkCquvuMkexSDYIG9ppOGbRLKAYUhckcrlw0SBn1AG3rwGV8v2WF mHCAW1lKDT1SwCnAjgMqOrBAi2SKDCAZ4bUd5VNzMwcCFmiRtwJPdpoEF06eajJVqlkr 9aCYkyj9ylC8oLMjrGTTtE0NIygXtSiZMfW8QYxl4b1eIQ9nEC0AAElAagTCOOBUPdkG L36DKUYlLioTnvj7If/8u9WKXnJ4mQd7AnosmAC7mdOe4vaHfBimpIjRtCzZAC1jm1TD CC1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=20qWx9xGjOYDijsTmK59UPcgX2htVy0Z9x8Cm4cuKl0=; b=t66l7Xey7HOtMuef0dF1kh2chIsYg5nkFE4vvXep9fnLkelQC0k3lkWKgZ/oS6wwLv BHqEgXftXcTjyUcu4l8z0DZG4rLEikUde7UxK0Z1AdAoMjIOLA1WXIAyUlP3YvRJOAmW GlgA1FW4yNS3LXYGYZAwVYN/lhiJlLqTB6qYEFRJXXnqVgeAygM4RyQpt6HH30166PtV iZcShxQve0rKQ/Y56igLhBoX65DSLRobFVHWq9GWEXxiIYbKj8JBz+STLdqIWWoljVTg qBI9c+D2DXUFUi94DOihOpDO3+zZzYT3FO/d37r321ZgCJFtwF+jzyJ0V5/ZLZXFaAB0 Nhwg== X-Gm-Message-State: ACrzQf0q0ihmRuQ9GInLMzJS5MoOqVG+iCz3KdSv+vGp2n1OZtXMaW9/ 2vSG+dEEd3fNg7ja8v2+VKyOWF360rn+WqLV X-Google-Smtp-Source: AMsMyM4FtXNyOeGpQDMy+eF4y4Jay1YyaGE4bjuq2KlcM2sbDhgoATYPN44Cu2qAIh1t/A5IbsE/XQ== X-Received: by 2002:a05:6870:b3a5:b0:127:9b3a:10e9 with SMTP id w37-20020a056870b3a500b001279b3a10e9mr5056305oap.203.1663768285003; Wed, 21 Sep 2022 06:51:25 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:c266:dbbf:9e84:6582:5289]) by smtp.gmail.com with ESMTPSA id a38-20020a05687046a600b0010bf07976c9sm1669476oap.41.2022.09.21.06.51.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 06:51:24 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 5/6] sunrpc: Suppress GCC -Os warning on user2netname Date: Wed, 21 Sep 2022 10:51:07 -0300 Message-Id: <20220921135108.3324737-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220921135108.3324737-1-adhemerval.zanella@linaro.org> References: <20220921135108.3324737-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. --- 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'; -- 2.34.1