From patchwork Thu Feb 15 08:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 201258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp242220dyb; Thu, 15 Feb 2024 00:12:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUX3hE9p6aIYE7VVswlYwiVw41Y9UGO/z+PxC01F+621aHkrFNSL+5WI/RvTD1XBK2Kkljsge5fAGoeRc6Tgy3tzanDlQ== X-Google-Smtp-Source: AGHT+IF9XbQBwQkHssUoaAbUW8Q8i8aK/y7j/WB/MclMcSFqry6yCyeCwLbexEVsa2+BxSryP0RT X-Received: by 2002:a0c:f592:0:b0:68e:e3a1:e614 with SMTP id k18-20020a0cf592000000b0068ee3a1e614mr1078720qvm.2.1707984745096; Thu, 15 Feb 2024 00:12:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707984745; cv=pass; d=google.com; s=arc-20160816; b=lS+GYPhwei2N0tx0I+ptqjCxIl+zfToRPJ7YPWWff9Y0asQxZ+hXUoqiqXkFa41CaE UzvTlCka2yJMFY9ZKVQBV4dO6qYiNrUy9AYqKQPkQEB/sDU2z3vS6bMxh0GjmiqBGlP2 XiPT8FcmMNKobnn5xFE+51wb3QYF4j3AMVK5qTdX02fBmxf9Uh6bb0hfovvIuV0u1QuQ yYnXYpAku5sSVWKxTXY6rYMAWGEnZbM6uANP72csQLvcngCQF22xvBJ4/Vwbq/4wPt/V r3t9gmjlGzNvhUrdyJbhgITYGBAyCF1brKP3gIcIliUGXHtTzDBUlb9Wkemdq4OdKaTB ZJTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=/4bSaCXhjqHjVNOUsGK+Zu5S9i6NnY6fYkTRusqdZ5A=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=IXRR4yOlOD7wkLC/VKPqEUIZaz2V58rsx0l5obYekLI1DPQHlyjf2BiiyqVG8Q0QMI DAt9/qIToS+1hs4lcyRHUpsRz/4jT8AhKARaF1USu4znGXxNBMzcmg1asyC+ulPeHRnM u0UFWuxMr4dmlPxo0Jm1UUpniQW0pv6+WyN7UQ3CXwVhl38rzs892m5ej4PpTMcbDpSl IZG7yYofpTODDSoFucQXYpqtF62zcafs6yhFnNxWNvNafsMWodAI011ySN/IfIAga5KF Fe0C0h2ECnyYNV2Vlc7BuJaNqjTOlsse0RjiEE1W+Atl98i9Wgd4PF2mWQUlPFEfoDZ/ xxjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nHoC9dXL; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 2-20020a0562140d6200b0068cc181729csi889560qvs.539.2024.02.15.00.12.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 00:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nHoC9dXL; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C42DC3861852 for ; Thu, 15 Feb 2024 08:12:24 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id C0D0A3861814 for ; Thu, 15 Feb 2024 08:12:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0D0A3861814 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C0D0A3861814 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707984734; cv=none; b=iAYIhAesb2Y3bbvZKXh4HCc5App2sNDYTRklio4bfIkrxMslts1Tns/ODd13mvPqRNcOu7rA7X94rQr7C81otV9Tr3Qs2EqCdhxoNO0WIko/DyjRFK9OmpLSmhCbh8ib5/zMvJc9IrKgicNBPuwCWG80+GtD3U38bVJutK4PsVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707984734; c=relaxed/simple; bh=hs42ckbSD7sn4RRiGuqu6rY71UoCIehPVcgTS2FcedI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Cxbab4oxy31zalTOml4tsb0QQnLcQtkjA43T8rKe7aBBeOPCz/Cyvibc6o/TYnCbQolBQfgK1ldcuYe07N1Z8uk120K8OqDlkW+VNpeNWsllGs6JFOBPzKGRPd0vQFp/9PH9FZaBIHL70azSBQRmteCjKcW8Uc8lNTAhB2yzS4E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6e2de202d9aso210699a34.0 for ; Thu, 15 Feb 2024 00:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707984731; x=1708589531; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/4bSaCXhjqHjVNOUsGK+Zu5S9i6NnY6fYkTRusqdZ5A=; b=nHoC9dXLXxStn+/l+gW5C87CnxuG1UKaWW1XHlRMK692QTSNDnKBsjTdngGAPBFjJy IbhoQ/cf7W7XYWa8V1WLkH5F7QabUmUHPouWCnktgoMmGvJ5+a2hU435dzNJAFcLq9Wg Dtg1I5q7x3FzMRVb4DPGxZt8s59vcxP7K1zGaWZUI4OR1MZWqIJ5YUPSdLPyKJpwKvoh /cVYWLrEskEYwo2037fNxwl53kjzWo89KLRWKj0A5uyFbwwADh6LI2k4qbUQoCTJkHs9 6gTNfS2CckaJOZn6xTZ/cM3SjH0OPLlKO6SiP16C+N5MeuqS/eV7JxUYAdjxMfCxbe8S PZhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707984731; x=1708589531; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/4bSaCXhjqHjVNOUsGK+Zu5S9i6NnY6fYkTRusqdZ5A=; b=JKQ5aXWX95vT8qEzkG1YhOH1TWWcZwHxIgijCFjnz/+pTL/2YtcbH7OlsldEFRE9xi 1QeGqA6TuKQL7ONBxMmlTVi3enrbIEYvysyFevEX4zo3+hdDTjgSyUiCFkF17yBq2bg4 wlv7gkC3j+w55TNmbingD6pTa4aYHNXX/+7KCKJvYrbddwLlMHR6Sxc4dqnSzLxw8+ZZ 2TLoRuWbUe4VlNeFJ+ITS0o3lzV84i1H4EOPEayChpMukBvzswN90QOD78N+9HJUXREf movHmY4Vulu9wKK/ItlYWOwKqZi0YYFwQfakfBU2mbvDD/a3cGTpVGdDNyoFmv5RCrYW yzJg== X-Gm-Message-State: AOJu0Ywpgl8kHKiuVm+ykeWufi5vp/sGvglG1aa2E92FBoGIt2kWNa6D 7+niypZePaD5YA5aU/7UV3LVnI/is/Y4XF7lyR+cjJJkfMPbanpEU2jWRlMz X-Received: by 2002:a05:6358:470d:b0:178:75cb:18dc with SMTP id j13-20020a056358470d00b0017875cb18dcmr1240897rwn.10.1707984731000; Thu, 15 Feb 2024 00:12:11 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:dec2:7d97:e7f:4c60]) by smtp.gmail.com with ESMTPSA id n22-20020aa78a56000000b006e043d3e5c2sm704988pfa.162.2024.02.15.00.12.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 00:12:10 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 0741E11423AD; Thu, 15 Feb 2024 18:42:07 +1030 (ACDT) Date: Thu, 15 Feb 2024 18:42:07 +1030 From: Alan Modra To: binutils@sourceware.org Subject: PR28448, Memory leak in function add_symbols(plugin.c) Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.4 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790951812133737671 X-GMAIL-MSGID: 1790951812133737671 PR 28448 * plugin.c (add_symbols): bfd_alloc memory for symptrs. Check bfd_make_empty_symbol return. diff --git a/ld/plugin.c b/ld/plugin.c index e982869072b..f81ab02b3a6 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -506,7 +506,9 @@ add_symbols (void *handle, int nsyms, const struct ld_plugin_symbol *syms) int n; ASSERT (called_plugin); - symptrs = xmalloc (nsyms * sizeof *symptrs); + symptrs = bfd_alloc (abfd, nsyms * sizeof *symptrs); + if (symptrs == NULL) + return LDPS_ERR; for (n = 0; n < nsyms; n++) { enum ld_plugin_status rv; @@ -514,6 +516,8 @@ add_symbols (void *handle, int nsyms, const struct ld_plugin_symbol *syms) bfdsym = bfd_make_empty_symbol (abfd); symptrs[n] = bfdsym; + if (bfdsym == NULL) + return LDPS_ERR; rv = asymbol_from_plugin_symbol (abfd, bfdsym, syms + n); if (rv != LDPS_OK) return rv;