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: 85765 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 8D1D8386183F for ; Thu, 15 Feb 2024 08:12:41 +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-Google-Smtp-Source: AGHT+IEzvsAH78rpE3dT49IdgHcmMJtllO+oyE0UUY0do1aUHQ3pM/a9W3LHFtN7r9uGYbXNK5m4Ow== 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+patchwork=sourceware.org@sourceware.org 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;