From patchwork Tue Feb 20 08:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Mehnert X-Patchwork-Id: 1901261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernkonzept.com header.i=@kernkonzept.com header.a=rsa-sha256 header.s=mx1 header.b=KzSgw49+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=patchwork.ozlabs.org) Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TfCMs14wnz23cw for ; Tue, 20 Feb 2024 19:32:55 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 906F5353697B; Tue, 20 Feb 2024 09:32:44 +0100 (CET) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernkonzept.com header.i=@kernkonzept.com header.a=rsa-sha256 header.s=mx1 header.b=KzSgw49+; dkim-atps=neutral Received: from mx.kernkonzept.com (serv1.kernkonzept.com [159.69.200.6]) by helium.openadk.org (Postfix) with ESMTPS id F11033536977 for ; Tue, 20 Feb 2024 09:32:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc: Reply-To:Content-ID:Content-Description; bh=havHfFaLpug73hdJ+0Y2lqSR2re3+L2g11rYcikCfF8=; b=KzSgw49+eNblk1inzGIBJif2sE VUQThUgR8ag5QfxTAgCDshvrQf2OwGxgaf8pbZ/xU25lzdznG0knjSiQJVaZyWwEQ/s2heleltYme BRe1UgSb8cDcBMpornkKRi1Z23X5fOqTPP7nZkwUYQdYDik5ArGCWvPs4UPS5C+no81MEZ7lxfYu5 LKKw85Aua7/jj3AXJVMKFsL+jnnY+Pei3q4p7isvO2y89Z5PHapBpXGa9sNfor+JDJf4rt88p/AAn LulPsCmLXxetFx2KLs54gK9DlRP+6ncwGCEh0NBjSYHg0EXDuQKjQ2IG6T+c7b1cuBEibtIjwwSOW UpAAp3mg==; Received: from p5089b207.dip0.t-ipconnect.de ([80.137.178.7] helo=noys4.localnet) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) id 1rcLYN-0000P9-04 for devel@uclibc-ng.org; Tue, 20 Feb 2024 09:32:39 +0100 From: Frank Mehnert To: devel@uclibc-ng.org Date: Tue, 20 Feb 2024 09:32:38 +0100 Message-ID: <12729258.O9o76ZdvQC@noys4> Organization: Kernkonzept In-Reply-To: References: <6013950.lOV4Wx5bFT@noys4> MIME-Version: 1.0 Message-ID-Hash: 7HJGF7LADH3IE67V5MZU4CGMJ6IZRSZE X-Message-ID-Hash: 7HJGF7LADH3IE67V5MZU4CGMJ6IZRSZE X-MailFrom: frank.mehnert@kernkonzept.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] Re: [PATCH] dl-elf.c: Add null-pointer check List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi Waldemar, sure, patch attached. Frank On Sonntag, 11. Februar 2024 07:11:36 CET Waldemar Brodkorb wrote: > Hi Frank, > > could you sent a patch including your good description with your > Signed-Off-By? For example with git format-patch -s origin > > Thanks in advance > Waldemar > > Frank Mehnert wrote, > > > Hi, > > > > static analysis tools complain that the following code lacks a null-pointer > > check: > > > > > > ldso/ldso/dl-elf.c: > > > > /* > > * Add this object into the symbol chain > > */ > > > > [...] From 85bad53b21837b6816d6f4f53c31b6a08b6d68e4 Mon Sep 17 00:00:00 2001 From: Frank Mehnert Date: Tue, 20 Feb 2024 08:32:20 +0100 Subject: [PATCH] ldso: add null-pointer check There is a check for (*rpnt == NULL) a few lines above but the "else" case performing an allocation does only exist if SHARED is not defined. If SHARED is defined, the allocation is not performed and it may happen (at least in theory) that *rpnt == NULL when executing (*rpnt)->dyn = tpnt; Add the null-pointer check. Signed-off-by: Frank Mehnert --- ldso/ldso/dl-elf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index ac6db59e0..4f50d62b7 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -900,7 +900,8 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned int rflags, _dl_memset(*rpnt, 0, sizeof(struct dyn_elf)); } #endif - (*rpnt)->dyn = tpnt; + if (*rpnt) + (*rpnt)->dyn = tpnt; tpnt->usage_count++; if (tpnt->rtld_flags & RTLD_NODELETE) tpnt->usage_count++; -- 2.43.0