From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D20C13858C2D for ; Wed, 5 Oct 2022 13:52:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D20C13858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664977961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P3Uil5Vr+1FfyLhdh9yKP5uUO6eiLDLhT1RfarQv5pM=; b=MjBfABInwz3NQMNNc5e2Pkj3BcDmkwsA+pilG4w+ELSjp8rhWqnLD3fw9l+pcutdIzvJYQ 8XBbMUDQPLh9vUK6vnI8rpOFr9r9Zoqnf2rnWtxxDFI4hmr4OHwk9l1HWeQjqK0Nzy3za3 OKDhfvItlVsJaffcL8WSK1030641kIA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-224-9QRoSBn4MAO1Wv-hVN_8Rg-1; Wed, 05 Oct 2022 09:52:40 -0400 X-MC-Unique: 9QRoSBn4MAO1Wv-hVN_8Rg-1 Received: by mail-qk1-f197.google.com with SMTP id x22-20020a05620a259600b006b552a69231so14225551qko.18 for ; Wed, 05 Oct 2022 06:52:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=P3Uil5Vr+1FfyLhdh9yKP5uUO6eiLDLhT1RfarQv5pM=; b=LfpTNqJdDoUvrESKDyGJhSgK1z/WbJqsC56mA2ezlo5sfSb+pmoVyWYElw6MCGCTwi KVdmhUvrpZXo5agkrz8C0vtcQCPMZATbLqOgpn7dH/mouMBjy4wkKMCjc3tG5BW2H7SX ovz42IePk3omaT3Fd6WRDKhgIQKsIqi7ZPi2F38JgmFLjp7fvCaH2gLhEG0FVjMpSFHB 0OdcLFZoglaTBWHHqdhCmvjCzJPBkPFb6aHSRTJe4SyF5uFsUgariaX4zbxTFfh5kTmH 6IBoeH7+TNqM9LZ7nWLn7D3nm5gLtQzv9VuS9Yhls0ukRm/z8VR28LmQsyEhbHrHGPyn 83uA== X-Gm-Message-State: ACrzQf1fADltBmHN2hkBKKissxnxfDnpkashsUq6oQzcRjYRqaOcjycU X3r+7UHp6kkJJ+lBlNJr0qb84FsQ2+Bzu+6yQ25qEqwwmfYRIyku3MXIlna76MQ6RUVBE8OtmeC z9vsiS3UM02W/H0rvdvPJ X-Received: by 2002:ad4:5d66:0:b0:4b1:8caf:886e with SMTP id fn6-20020ad45d66000000b004b18caf886emr11098319qvb.103.1664977959659; Wed, 05 Oct 2022 06:52:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6g4WrqM0nIxS//XvFs7V+JcdPHzHdCAEh+HYtuzm46zn2/qG4M3HFo03joEyrWXhMb8cfnrg== X-Received: by 2002:ad4:5d66:0:b0:4b1:8caf:886e with SMTP id fn6-20020ad45d66000000b004b18caf886emr11098306qvb.103.1664977959463; Wed, 05 Oct 2022 06:52:39 -0700 (PDT) Received: from fedora ([66.187.232.65]) by smtp.gmail.com with ESMTPSA id q34-20020a05620a2a6200b006b8d1914504sm17246868qkp.22.2022.10.05.06.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 06:52:38 -0700 (PDT) Date: Wed, 5 Oct 2022 09:52:37 -0400 From: Carlos O'Donell To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 5/6] sunrpc: Suppress GCC -Os warning on user2netname Message-ID: References: <20220921135108.3324737-1-adhemerval.zanella@linaro.org> <20220921135108.3324737-6-adhemerval.zanella@linaro.org> MIME-Version: 1.0 In-Reply-To: <20220921135108.3324737-6-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 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,SPF_HELO_NONE,SPF_NONE,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: On Wed, Sep 21, 2022 at 10:51:07AM -0300, Adhemerval Zanella via Libc-alpha wrote: > 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. LGTM. No regressions on x86_64. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell > 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 OK. > > #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; OK. Agreed. The code above does that check. > i = strlen (netname); > if (netname[i - 1] == '.') > netname[i - 1] = '\0'; > -- > 2.34.1 >