From patchwork Mon Aug 8 03:26:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1664396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=SvaiSvnq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M1M7c009mz9sCD for ; Mon, 8 Aug 2022 13:26:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D916D385803F for ; Mon, 8 Aug 2022 03:26:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D916D385803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1659929207; bh=rztTGEC/ZR//vt+e9McjikR7opm/2EfCItcaWM4Iml8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SvaiSvnqC5F/XRJRsgm3gB6GWgytsR3ZBQRm4bxuO2EPe4Tpc0w41vXQxzvVSfu3Q 6CoOsYRifdY+BOuJ9ZSbts1esspxawlR0Aepx0MAMBj/VvadCLQGYVMrSkospvrtpT mktWnCiHuFMZdUcaCh8NBvTDNg2KhGA60TCwO0mc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 582D93857360 for ; Mon, 8 Aug 2022 03:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 582D93857360 Received: by mail-pg1-x533.google.com with SMTP id q16so7488318pgq.6 for ; Sun, 07 Aug 2022 20:26:33 -0700 (PDT) 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:cc:to:from:x-gm-message-state:from:to:cc; bh=rztTGEC/ZR//vt+e9McjikR7opm/2EfCItcaWM4Iml8=; b=kWcdxL8MoCl2Lsc15cwbn9wmD/ByNG1CVkGacYpZVTqHn4VBnLujLduxlFS4LTE13W slNIqXxU88mk/QY4/IVK9PgKiTJHO1dA0PJ9JmhL/cXiaMWO5knwzEWdxlo3U8hb26fj FIyx63AMVBAE2vGq3O1a4LYesxvOrUSOPHJZDX2kmufX4BWGAWgPnpOfNgJ2ZpXghuHv m79uSTWyP9k/GfSzM+uH0T9EP1ts0LH45/zc/FdV0qvHQL81K8RdNeb69WHNs0g3D7hu Zm9SehYcPmI7n7lvd0bguv1mP0uDbHt1YAuuIKe4SoHuCfXZ765LUQTbQt9kcxvKr+HT Tt4g== X-Gm-Message-State: ACgBeo09ibNCbR5MDnlisXpfFjL2/HfaPvFhw0U6sp8Nhwj+PH94okOI 35IEXD5TsVin1/LRl8oiUxi4+LNw9Zt7urch X-Google-Smtp-Source: AA6agR6f0hTHNiyQCMktgDk0cH0rNsSxL5W60Y2dMD/LjdY3igE1gNpatQE4VY1j9ytp7LqnxrZvSQ== X-Received: by 2002:a63:2d46:0:b0:41d:858b:52ff with SMTP id t67-20020a632d46000000b0041d858b52ffmr2346003pgt.516.1659929191671; Sun, 07 Aug 2022 20:26:31 -0700 (PDT) Received: from noah-tgl.. ([192.198.168.42]) by smtp.gmail.com with ESMTPSA id w8-20020a170902904800b0016d23e941f2sm7294579plz.258.2022.08.07.20.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 20:26:31 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1] elf: Replace `strcpy` call with `memcpy` [BZ #29454] Date: Mon, 8 Aug 2022 11:26:22 +0800 Message-Id: <20220808032622.3804534-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808032622.3804534-1-goldstein.w.n@gmail.com> References: <20220808032622.3804534-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 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-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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); }