From patchwork Mon Apr 1 16:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maks Mishin X-Patchwork-Id: 87887 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 B286B3858413 for ; Mon, 1 Apr 2024 16:03:02 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id AD6D53858D20 for ; Mon, 1 Apr 2024 16:02:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD6D53858D20 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 AD6D53858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711987372; cv=none; b=jrDCzprDA06Sz2bVTKcGk9m6tajxT7Z0REDix6X+8pmO7G8oXdlyZHch2YU1pYJwx4nK4u4IRs8PQhE9sIVGdzio/jl8qQ+IsvtYgdx8TSbk/ddIyUYQb9xW36CZiX7jP8efuOh2HemDLOGMR+zNdHJAgBcFYku1SV9budiLzug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711987372; c=relaxed/simple; bh=Q2SY7FGYamu+o1OzB5CnDf7EjhvDO649PVgxubIM2XU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=OWTwAVjxS/k2wfFh2wQOhKWcemyjAmevs593vvQqXC+P8Z8Ql7g0sjMcpFxG30+FDf/feTzD3j6Pqa1+YS1UJ0mBdiB7fxDFtuWBtKG53KvYTMQUTJ/C2zUk+qP6RliBxkTi+uNx1VwSG1GTKKJJj4ZWvJL5zwjnGIdmCrCsabI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-513e89d0816so4847478e87.0 for ; Mon, 01 Apr 2024 09:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711987368; x=1712592168; 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=818EaDOP39ICBs7rGFtLR4FNZzt7oViRzsNxgR6Nmp4=; b=mMncvPMr3HElF9nLCHruKOhf6LzBDy0SBkkUodj3BB9v1e7VkfRQlnaBIYQAgXCxK5 /q6ZygZ9I6PnvBZN41ebBZBPOb+U/3knXkV7csCMrBGn0GnNgd5KTq1BKQcsSpda0bvE rLoYPqnoDOg3F2GEq4hiK4bdmy/rkxIch82lllGxjsv2UGsJNAFKfMzyBO0+14KkMv0k Za9KF679dwwXxXHQgZLUBOFIy1uFZEkd/rQ8n75QvgBQIx7tIrQl4EE/Z9v1KClENkSU MK6jn+5ki9Z1QUf1Q+FsA0iVtU2RHPg2gOHRAqBc01r9dM0KpdGc8P3rjYceg4OZDOOI eziw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711987368; x=1712592168; 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=818EaDOP39ICBs7rGFtLR4FNZzt7oViRzsNxgR6Nmp4=; b=NSyJEsXFsE4tyOlV5ecLBp8gfE5+faHYwdj23m7P4tYgb/u2ahvm8VSx6fz2BpxwRk GcDtn/SfBoINguxpiTyUIArD7jCiXGRQv7B6bvrFXyRFgKLnBcXuH8ziTcEtOdFyxysG iWVJqlnNiyeFkIgkztQeVd9Syj8GXm1fFd4OaAPMN/ke6zSOluZSPM4HDZauwB7wqTEE tCTA5Ih+Set8Cy1qeGbcTi2xWm6Ppxm3hjzjWzGz9lWl3an9Z7w2qUr0BqWmfBHrXS3P SqFzfHfZEzH0RTTEkVonF0U0LIZzQCNLZHXA3CiGpFqnS4CdHOnzCG9yZL/kew3J6PXj qI+w== X-Gm-Message-State: AOJu0YzDXikTInfZ6P7X981onzsCCvEobnwcCgWKQK8oqo96np+btGXN R1iRRV7gtclFEaStHRX/N6b7Zw7hPMK7ztLP4q9vvCYAqJ26cKT7aQxh+vKR X-Google-Smtp-Source: AGHT+IGDwE3elkQIBJyaDQxsje1IdwCw7W1oFC8STijulj+OMCNN/cHjYBBX62k8japmFjqKTdQunw== X-Received: by 2002:ac2:5f86:0:b0:513:cb7a:7cf7 with SMTP id r6-20020ac25f86000000b00513cb7a7cf7mr6102634lfe.63.1711987368271; Mon, 01 Apr 2024 09:02:48 -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 f8-20020a193808000000b00515bbc2feedsm1479896lfa.102.2024.04.01.09.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 09:02:47 -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 handle_core_item() Date: Mon, 1 Apr 2024 19:02:45 +0300 Message-Id: <20240401160245.9688-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 Signed-off-by: Maks Mishin --- src/readelf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/readelf.c b/src/readelf.c index 0e931184..495db13e 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -12440,6 +12440,13 @@ handle_core_item (Elf *core, const Ebl_Core_Item *item, const void *desc, field went into the high half of USEC. */ GElf_Ehdr ehdr_mem; GElf_Ehdr *ehdr = gelf_getehdr (core, &ehdr_mem); + if (ehdr == NULL) + { + error (EXIT_FAILURE, 0, + _("cannot read ELF header: %s"), elf_errmsg (-1)); + return; + } + if (likely (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)) usec >>= 32; else