From patchwork Mon Apr 1 16:42:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maks Mishin X-Patchwork-Id: 87889 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 46F113858C24 for ; Mon, 1 Apr 2024 16:42:49 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 237E93858D20 for ; Mon, 1 Apr 2024 16:42:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 237E93858D20 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 237E93858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711989760; cv=none; b=Ekn61tCMC4JttUtOdQPX2NezhHOd5rADcZgk3GSmLQLrf2Tv0fPQaQQSqR8k/YFoOgp9yKtYkz40rENMSH1N44zsadIUv6YIMv9UWinu+POB1SiSitGkAtCKIuSsDXTx483NEpbhXSgxGtNk9eZmkJs5ZzIimiiwMzEqsnrlSr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711989760; c=relaxed/simple; bh=dSKQY6u2sfOLjolUr6zao/LlcByonWxfpiUUovdbkzQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Wut5wxk47wrhV8rGWI+mSn3sawe/ka86pveQbNkicY5/fXUETslYHvLxcVnSmL13qaM+qfT6BTLD1Ndp+EIBwVk9OySdJpY4e5MlVhDHZa6xWFlwpLzLJOFqZ1A1cnOi1cMdKspwaESet87b+AZNHS446nl71WPlv+MLie+hFS4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-513e10a4083so4801078e87.1 for ; Mon, 01 Apr 2024 09:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711989756; x=1712594556; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1ze3W47M5avhORxZN3j+QOh1iVRz1tYkcYzG96FfTqQ=; b=XP58X7hj5sGIp/BHWhooV5rLYRhbAyV26itN+yXY0hH3lzT+lsJCYqyVLQ7J42pU68 mqMZRqUxBMGtgWqdr6Ff5MXutzbVRBuho9NWeoK+QK3+VqeZGhJQWerOPBXacBwhrZHo qFFsjSLOzujlzHLsvHx9aW7jdAY9rQC4FJ7eTmvjZqOzx+UHhWb21uwR90Avq6Lk9owG rQqzKPuSZRT/wqPo+bZq24XrGm69hKrE+V3pw+ZUQe72zzEg8B7JL0/AP6NY/FZ2dTO4 nYIlSBxOiPrxa0u2h8aLLopA81y8ED4inGnsAYS/h9fEefEQbEGdTeu+oZMIoxWR+vqC 6FtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711989756; x=1712594556; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1ze3W47M5avhORxZN3j+QOh1iVRz1tYkcYzG96FfTqQ=; b=ancy4YBXhmaQAhJDUJvoJOViPLoEdMSUxPeKNh8GRcerGVnI5QPgIk2KUgMQrk0zfT Am3z+9UZTdfrOmt5WPNofgQL4+VS32T0qRfbA3N4ipWi2xd+OT7pL2f7jWeYrS1waWfn d7PEX1NJ2UYfzGlm/liv7NDIzPSsLir9DGm6L+g2ocjrzL1ucwJtlpLAvsDXqLbtEXxI cIeeGCgZO8zDoE9sAE73HwyJFnF8RRQOE/uoBAhuHqQTuX/d2I0c8h3ssZqEHM8gX//y RfBpH2CPL8d2ebJKlU17ZIQTKLzLJFvp4ePsABt8sJ/jg+ZFpPojwQJm6Evry5piDu6z rVPQ== X-Gm-Message-State: AOJu0YxFW70nZdP+Q58i/oO9sGFgEXefKV6yJWmPB9ML0ziULJ5l8tY0 n9IVy8qmaM951cez8TIl5MW3pRl7SY46+E32lCUuZocjMIzPgKiKIDBZYAT+ X-Google-Smtp-Source: AGHT+IHNsHZfaXap/RzIZoFnAA9skkAXJnI1pOylq9PBnNB20wCweXUXnG8NAocQtsSgYoCHdqNdHw== X-Received: by 2002:a05:6512:32b3:b0:516:9f1a:929d with SMTP id q19-20020a05651232b300b005169f1a929dmr3976882lfe.1.1711989755896; Mon, 01 Apr 2024 09:42:35 -0700 (PDT) Received: from mishin.sarov.local (95-37-71-41.dynamic.mts-nn.ru. [95.37.71.41]) by smtp.gmail.com with ESMTPSA id eq14-20020a056512488e00b005159eaf5c35sm1477509lfb.276.2024.04.01.09.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 09:42:35 -0700 (PDT) From: Maks Mishin X-Google-Original-From: Maks Mishin To: elfutils-devel@sourceware.org Cc: Maks Mishin Subject: [PATCH] readelf: Fix deref-of-null in dump_archive_index() Date: Mon, 1 Apr 2024 19:42:31 +0300 Message-Id: <20240401164231.23940-1-maks.mishinFZ@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Pointer, returned from function 'elf_getarhdr' ar readelf.c:13551, may be NULL and is dereferenced at readelf.c:13553. Found by RASU JCS. Signed-off-by: Maks Mishin --- src/readelf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/readelf.c b/src/readelf.c index 0e931184..a650c0b9 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -13549,6 +13549,12 @@ dump_archive_index (Elf *elf, const char *fname) as_off, fname, elf_errmsg (-1)); const Elf_Arhdr *h = elf_getarhdr (subelf); + if (h == NULL) + { + printf ("cannot get archive header in '%s': %s\n", + fname, elf_errmsg (-1)); + return; + } printf (_("Archive member '%s' contains:\n"), h->ar_name);