From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id AD27B3858023 for ; Mon, 8 Aug 2022 14:24:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD27B3858023 Received: by mail-qt1-x834.google.com with SMTP id u12so6613005qtk.0 for ; Mon, 08 Aug 2022 07:24:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=snbZKBeyhFdd73hbE60FGApiuL4ZHhh+Xng1Sur+moY=; b=kS5TO9coK+sDj+ymFY2ThuMEhltSokTCBa8OKhhE81aYmqV4SpZUAx9MCYrugDbsfp Vki04F6ZzMZSSHAbX8Wnmn+eond/08CeT1adwMK/XRDn4eHM1jrFO90tAok6AxObwUhO 19d81uAk50cqkAH75mqEe+Es12vJjt5PBYMOEqnxhb4oEpEU+VrRjJUv/wSsgWIoCJud tM8Sq0G23fzoJ/x6OmYGID7j3/zsi+wVL8+LKMKBp6iY+l0iZcO1eA/bq/JuJZZHigE4 WpOh63YOtkbNZJlYiSzQcA0FLHAImC319Sae/IewZxEdJ8im6Q/BFgPXrgrJYy7ufhOo tHMA== X-Gm-Message-State: ACgBeo0LjycU6B6PO52znnmat7EHerd5cmSQwF/K003v0TrCcfq2ADjE CJskLtKsHB/R2UxtZTrv2oKEyUOanSlr1dgTEiE= X-Google-Smtp-Source: AA6agR4CJv3VPhA73B/fVLhTaMlmaJ5elGXnGxce7wSrF5US4uIRn1HnDoWykn8yKDghXenWs+T4AL6LCda82T8SEcA= X-Received: by 2002:ac8:7d13:0:b0:343:33d:f03a with SMTP id g19-20020ac87d13000000b00343033df03amr1239092qtb.500.1659968672017; Mon, 08 Aug 2022 07:24:32 -0700 (PDT) MIME-Version: 1.0 References: <20220808032622.3804534-1-goldstein.w.n@gmail.com> <20220808032622.3804534-2-goldstein.w.n@gmail.com> In-Reply-To: <20220808032622.3804534-2-goldstein.w.n@gmail.com> From: "H.J. Lu" Date: Mon, 8 Aug 2022 07:23:56 -0700 Message-ID: Subject: Re: [PATCH v1] elf: Replace `strcpy` call with `memcpy` [BZ #29454] To: Noah Goldstein Cc: GNU C Library , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3024.6 required=5.0 tests=BAYES_00, 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-List-Received-Date: Mon, 08 Aug 2022 14:24:34 -0000 On Sun, Aug 7, 2022 at 8:26 PM Noah Goldstein wrote: > > GCC normally does this optimization for us in > strlen_pass::handle_builtin_strcpy but only for optimized > build. To avoid needing to include strcpy.S in the rtld build to > support the debug build, just do the optimization by hand. > --- > elf/dl-cache.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/elf/dl-cache.c b/elf/dl-cache.c > index 8bbf110d02..b97c17b3a9 100644 > --- a/elf/dl-cache.c > +++ b/elf/dl-cache.c > @@ -509,8 +509,9 @@ _dl_load_cache_lookup (const char *name) > we are accessing. Therefore we must make the copy of the > mapping data without using malloc. */ > char *temp; > - temp = alloca (strlen (best) + 1); > - strcpy (temp, best); > + size_t best_len = strlen (best) + 1; > + temp = alloca (best_len); > + memcpy (temp, best, best_len); > return __strdup (temp); > } > > -- > 2.34.1 > LGTM. Thanks. -- H.J.