From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 979DD385B835 for ; Sun, 29 Mar 2020 23:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 979DD385B835 Received: by mail-pf1-x435.google.com with SMTP id 22so7668061pfa.9 for ; Sun, 29 Mar 2020 16:04:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=xroyPNR8KKFdZQmdir4gUpchMalMgJvUSaXgwiKuxoY=; b=DoU49YQ35kPNaTslpsUo4JTjhYA4LINtzMq1p3IipC/jyBYCP62e06Hb/qkSQjLx8p 2Cp+m3DWRfb9eIyS4HGI+ysc3jgW8CvPB/730lu7O0+5+Dalgk+SZcgXQHLlJwVcZ+bG cEc6H1p0NrxddxME+OKpf9GzFiP9T2RCZcZFjTWaVk6ujmiJD/G3ez6KhB/2ThnLJTCy Q+2lQuoh0oj3NlI3i/5VZ4GWUbXmzqZbIozB0KmFxxAkmHRMbjElB6QQCLpYPbaR/p29 ySTH/p4qGpsRyCr0v0O3mNwQaPX73cVStQAxAelOkMGRGclgjnHlTrQj/1MgNTIHgbsy Wh9Q== X-Gm-Message-State: ANhLgQ122Utk0hj1uRUOOH6fkalykdVQZO39ktxaWuUCDbstvunHXvpr 9kMA2t48CcO9j5NhZo/3strnO8nllFc= X-Google-Smtp-Source: ADFU+vvLrKZ7gfkXLivSOBgsuJpvbYTOwLSpj9SFtTbicCqyUm9eAeyF+Qd0womnhzx6SQhK2eZrxg== X-Received: by 2002:a63:6f0c:: with SMTP id k12mr10359720pgc.142.1585523074207; Sun, 29 Mar 2020 16:04:34 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:bc06:df58:39d1:fa9f]) by smtp.gmail.com with ESMTPSA id k5sm8236037pgl.3.2020.03.29.16.04.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Mar 2020 16:04:33 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id CF72E805D2; Mon, 30 Mar 2020 09:34:29 +1030 (ACDT) Date: Mon, 30 Mar 2020 09:34:29 +1030 From: Alan Modra To: binutils@sourceware.org Subject: PR25745, powerpc64-ld overflows string buffer in --stats mode Message-ID: <20200329230429.GV4583@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-24.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Mar 2020 23:04:37 -0000 Translated strings can take a lot more space. PR 25745 * elf64-ppc.c (ppc64_elf_build_stubs): Use asprintf to form statistics message. diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 7f7e190ce2..945f83c7e6 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -14557,42 +14557,46 @@ ppc64_elf_build_stubs (struct bfd_link_info *info, if (stats != NULL) { - size_t len; - *stats = bfd_malloc (500); - if (*stats == NULL) - return FALSE; - - len = sprintf (*stats, - ngettext ("linker stubs in %u group\n", - "linker stubs in %u groups\n", - stub_sec_count), - stub_sec_count); - sprintf (*stats + len, _(" branch %lu\n" - " branch toc adj %lu\n" - " branch notoc %lu\n" - " branch both %lu\n" - " long branch %lu\n" - " long toc adj %lu\n" - " long notoc %lu\n" - " long both %lu\n" - " plt call %lu\n" - " plt call save %lu\n" - " plt call notoc %lu\n" - " plt call both %lu\n" - " global entry %lu"), - htab->stub_count[ppc_stub_long_branch - 1], - htab->stub_count[ppc_stub_long_branch_r2off - 1], - htab->stub_count[ppc_stub_long_branch_notoc - 1], - htab->stub_count[ppc_stub_long_branch_both - 1], - htab->stub_count[ppc_stub_plt_branch - 1], - htab->stub_count[ppc_stub_plt_branch_r2off - 1], - htab->stub_count[ppc_stub_plt_branch_notoc - 1], - htab->stub_count[ppc_stub_plt_branch_both - 1], - htab->stub_count[ppc_stub_plt_call - 1], - htab->stub_count[ppc_stub_plt_call_r2save - 1], - htab->stub_count[ppc_stub_plt_call_notoc - 1], - htab->stub_count[ppc_stub_plt_call_both - 1], - htab->stub_count[ppc_stub_global_entry - 1]); + char *groupmsg; + if (asprintf (&groupmsg, + ngettext ("linker stubs in %u group\n", + "linker stubs in %u groups\n", + stub_sec_count), + stub_sec_count) < 0) + *stats = NULL; + else + { + if (asprintf (stats, _("%s" + " branch %lu\n" + " branch toc adj %lu\n" + " branch notoc %lu\n" + " branch both %lu\n" + " long branch %lu\n" + " long toc adj %lu\n" + " long notoc %lu\n" + " long both %lu\n" + " plt call %lu\n" + " plt call save %lu\n" + " plt call notoc %lu\n" + " plt call both %lu\n" + " global entry %lu"), + groupmsg, + htab->stub_count[ppc_stub_long_branch - 1], + htab->stub_count[ppc_stub_long_branch_r2off - 1], + htab->stub_count[ppc_stub_long_branch_notoc - 1], + htab->stub_count[ppc_stub_long_branch_both - 1], + htab->stub_count[ppc_stub_plt_branch - 1], + htab->stub_count[ppc_stub_plt_branch_r2off - 1], + htab->stub_count[ppc_stub_plt_branch_notoc - 1], + htab->stub_count[ppc_stub_plt_branch_both - 1], + htab->stub_count[ppc_stub_plt_call - 1], + htab->stub_count[ppc_stub_plt_call_r2save - 1], + htab->stub_count[ppc_stub_plt_call_notoc - 1], + htab->stub_count[ppc_stub_plt_call_both - 1], + htab->stub_count[ppc_stub_global_entry - 1]) < 0) + *stats = NULL; + free (groupmsg); + } } return TRUE; } -- Alan Modra Australia Development Lab, IBM