diff mbox series

[uclibc-ng-devel] Re: [PATCH] dl-elf.c: Add null-pointer check

Message ID 12729258.O9o76ZdvQC@noys4
State Accepted
Headers show
Series [uclibc-ng-devel] Re: [PATCH] dl-elf.c: Add null-pointer check | expand

Commit Message

Frank Mehnert Feb. 20, 2024, 8:32 a.m. UTC
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
> >            */
> >
> > [...]

Comments

Waldemar Brodkorb Feb. 22, 2024, 6:46 p.m. UTC | #1
Hi Frank,

finally applied and pushed,
 thanks
  Waldemar

Frank Mehnert wrote,

> 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 <frank.mehnert@kernkonzept.com>
> 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 <frank.mehnert@kernkonzept.com>
> ---
>  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
> 

> _______________________________________________
> devel mailing list -- devel@uclibc-ng.org
> To unsubscribe send an email to devel-leave@uclibc-ng.org
diff mbox series

Patch

From 85bad53b21837b6816d6f4f53c31b6a08b6d68e4 Mon Sep 17 00:00:00 2001
From: Frank Mehnert <frank.mehnert@kernkonzept.com>
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 <frank.mehnert@kernkonzept.com>
---
 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