From patchwork Sat Oct 9 23:43:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 46036 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F0F03858411 for ; Sat, 9 Oct 2021 23:43:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F0F03858411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633823027; bh=fLB1p5nZFu8d5dDE5gMQULFsR7SONzit4BFDu6CtRiI=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=cUF6ZEMRhEGHNqWqFvJ9/dAcSQxgvTQBuON5taF2wwzUHLpYGBC3KUBmYdxgMpMvp hjshu+2NgaI73gS5JDw8VwuG9cnaOByHm22Bnko5LUXW5GhaaU4PfwDXx04ij+lKS7 yKeET9zfrVqgzRAC++WhfPBrPYVaE/3Nwhk3xvcc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id 74BF63858D28 for ; Sat, 9 Oct 2021 23:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74BF63858D28 Received: by mail-qt1-x836.google.com with SMTP id c20so13125082qtb.2 for ; Sat, 09 Oct 2021 16:43:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=fLB1p5nZFu8d5dDE5gMQULFsR7SONzit4BFDu6CtRiI=; b=I/QFSqyzvQJW87Hg9rCJFKRJZmMoPtmdouMA5syqlpKEiQCIJgUBq5VGt/qPR0PxYP 7GqEwREa7l/SHVZf/98OCyz+OzGsQeUt4yf7+1gN5Z0sYc80PU0uEPiAaxO0ZgQJpqW7 MefzZlQOjsjtadxVVysXx+S+TnVGXi4ThKr3SgGfHX2T5hY3Y1lPczHNPEn11lwbcCN1 yre+41NwamJ5f+7HZX+mX4292UpNYw5jZCumZhxBlYVsuQzKCtowlm5haektDP+6pYaf uMsqnIEBBb8TNpIxhXHjmKiFLUWazoS+C07fuQPDk37GfwvceLjUqTuIPOh7NHhEpacJ Y7nw== X-Gm-Message-State: AOAM531gCRxbeTFKOOJfTsCvkux3vW/5jWf8/sZSvZvsMna/cRKv4Vb/ a27rz8Bc5A+vHeyvvRiz9XY= X-Google-Smtp-Source: ABdhPJyFW1yIZOcQTFQHWZKKYbUSsnl7QjZbLBEp4ho3FTPbP+8yniYApcuHJUmnE4J9Bll87tkJTQ== X-Received: by 2002:a05:622a:180f:: with SMTP id t15mr6509209qtc.33.1633823005116; Sat, 09 Oct 2021 16:43:25 -0700 (PDT) Received: from [192.168.0.41] (184-96-250-116.hlrn.qwest.net. [184.96.250.116]) by smtp.gmail.com with ESMTPSA id y23sm2163454qtm.68.2021.10.09.16.43.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Oct 2021 16:43:24 -0700 (PDT) Subject: [PATCH v3] replace sprintf with stpcpy to avoid GCC warning [BZ#28439] To: Paul Eggert , Martin Sebor via Libc-alpha References: <8bc40ccb-9d82-77c9-1277-cbff062b4ce6@gmail.com> <87ily67y46.fsf@mid.deneb.enyo.de> <33640df2-6ba0-5c0c-2829-747f813118b5@gmail.com> <8e2c6d66-45c7-721f-eb9e-2518eab083c3@cs.ucla.edu> Message-ID: Date: Sat, 9 Oct 2021 17:43:23 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <8e2c6d66-45c7-721f-eb9e-2518eab083c3@cs.ucla.edu> Content-Language: en-US X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Sebor via Libc-alpha From: Martin Sebor Reply-To: Martin Sebor Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" On 10/9/21 3:57 PM, Paul Eggert wrote: > On 10/9/21 1:56 PM, Martin Sebor via Libc-alpha wrote: >> I would >> have thought the strcpy approach preferable > > Me too. sprintf/snprintf/__snprintf is overkill here. Instead, I suggest > something like the following (untested) patch, as it is easier for > static analysis that would otherwise have to worry about the INT_MAX > gorp that plagues the sprintf family. > > diff --git a/resolv/res_query.c b/resolv/res_query.c > index 75b0e5f2f7..5d0a68dc81 100644 > --- a/resolv/res_query.c > +++ b/resolv/res_query.c > @@ -610,7 +610,9 @@ __res_context_querydomain (struct resolv_context *ctx, >              RES_SET_H_ERRNO(statp, NO_RECOVERY); >              return (-1); >          } > -        sprintf(nbuf, "%s.%s", name, domain); > +        char *p = __stpcpy (nbuf, name); > +        *p++ = '.'; > +        strcpy (p, domain); >      } >      return __res_context_query (ctx, longname, class, type, answer, >                      anslen, answerp, answerp2, nanswerp2, That works for me too. Attached is v3 with the above patch for Patchwork to test. It builds and passes with no extra failures for me on x86_64-linux. I'll plan to commit this version sometime next week if it passes and there's no further feedback. Florian, please pipe up if you have any concerns with it. Martin diff --git a/resolv/res_query.c b/resolv/res_query.c index 75b0e5f2f7..5d0a68dc81 100644 --- a/resolv/res_query.c +++ b/resolv/res_query.c @@ -610,7 +610,9 @@ __res_context_querydomain (struct resolv_context *ctx, RES_SET_H_ERRNO(statp, NO_RECOVERY); return (-1); } - sprintf(nbuf, "%s.%s", name, domain); + char *p = __stpcpy (nbuf, name); + *p++ = '.'; + strcpy (p, domain); } return __res_context_query (ctx, longname, class, type, answer, anslen, answerp, answerp2, nanswerp2,