diff mbox

getauxval: fix crash on systems without HAVE_AUX_VECTOR

Message ID 20160402105716.GA10998@var.jdll.illyse.net
State New
Headers show

Commit Message

Samuel Thibault April 2, 2016, 10:57 a.m. UTC
Systems without HAVE_AUX_VECTOR have GLRO(dl_auxv) == NULL, and
getauxval would thus crash.

* misc/getauxval.c (__getauxval): Check for GLRO(dl_auxv) != NULL before
looping through the list.

Comments

Mike Frysinger April 2, 2016, 5:30 p.m. UTC | #1
On 02 Apr 2016 12:57, Samuel Thibault wrote:
> Systems without HAVE_AUX_VECTOR have GLRO(dl_auxv) == NULL, and
> getauxval would thus crash.

assuming this is for GNU/hurd

> --- a/misc/getauxval.c
> +++ b/misc/getauxval.c
> @@ -30,9 +30,10 @@ __getauxval (unsigned long int type)
>    else if (type == AT_HWCAP2)
>      return GLRO(dl_hwcap2);
>  
> -  for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
> -    if (p->a_type == type)
> -      return p->a_un.a_val;
> +  if (GLRO(dl_auxv) != NULL)
> +    for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
> +      if (p->a_type == type)
> +	return p->a_un.a_val;

should this just be under HAVE_AUX_VECTOR ?  seems like we shouldn't
even bother defining/exporting dl_auxv at all if it's disabled.  then
we wouldn't run into more latent problems like this at run time -- it
would be a build failure.

in looking at other uses of dl_auxv, why isn't _dl_sysdep_start an
issue too ?  rtld.c:_dl_start_final always calls that, and that func
always walks GLRO(dl_auxv).
-mike
Roland McGrath April 4, 2016, 7:37 p.m. UTC | #2
> On 02 Apr 2016 12:57, Samuel Thibault wrote:
> > Systems without HAVE_AUX_VECTOR have GLRO(dl_auxv) == NULL, and
> > getauxval would thus crash.
> 
> assuming this is for GNU/hurd

Yes.

> should this just be under HAVE_AUX_VECTOR ?  seems like we shouldn't
> even bother defining/exporting dl_auxv at all if it's disabled.  then
> we wouldn't run into more latent problems like this at run time -- it
> would be a build failure.

Agreed.

> in looking at other uses of dl_auxv, why isn't _dl_sysdep_start an
> issue too ?  rtld.c:_dl_start_final always calls that, and that func
> always walks GLRO(dl_auxv).

You are looking at elf/dl-sysdep.c, not sysdeps/mach/hurd/dl-sysdep.c.
Markus Trippelsdorf April 11, 2016, 7:55 a.m. UTC | #3
On 2016.04.02 at 12:57 +0200, Samuel Thibault wrote:
> Systems without HAVE_AUX_VECTOR have GLRO(dl_auxv) == NULL, and
> getauxval would thus crash.

Your commit 0cdc5e930a breaks the build for me:

In file included from ../sysdeps/x86_64/ldsodefs.h:54:0,
                 from ../sysdeps/gnu/ldsodefs.h:46,
                 from ../sysdeps/unix/sysv/linux/ldsodefs.h:22,
                 from getauxval.c:20:
getauxval.c: In function ‘__getauxval’:
../sysdeps/generic/ldsodefs.h:439:21: error: ‘_dl_auxv’ undeclared (first use in this function)
 # define GLRO(name) _##name
                     ^
getauxval.c:34:12: note: in expansion of macro ‘GLRO’
   for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
            ^~~~
../sysdeps/generic/ldsodefs.h:439:21: note: each undeclared identifier is reported only once for each function it appears in
 # define GLRO(name) _##name
                     ^
getauxval.c:34:12: note: in expansion of macro ‘GLRO’
   for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
            ^~~~
../o-iterator.mk:9: recipe for target '/var/tmp/glibc-build/misc/getauxval.o' failed
Samuel Thibault April 11, 2016, 8:28 a.m. UTC | #4
Hello,

Markus Trippelsdorf, on Mon 11 Apr 2016 09:55:12 +0200, wrote:
> On 2016.04.02 at 12:57 +0200, Samuel Thibault wrote:
> > Systems without HAVE_AUX_VECTOR have GLRO(dl_auxv) == NULL, and
> > getauxval would thus crash.
> 
> Your commit 0cdc5e930a breaks the build for me:

Ah, sorry, part of the commit was missing indeed, now fixed.

Samuel
diff mbox

Patch

diff --git a/misc/getauxval.c b/misc/getauxval.c
index e48f40f..7ba0598 100644
--- a/misc/getauxval.c
+++ b/misc/getauxval.c
@@ -30,9 +30,10 @@  __getauxval (unsigned long int type)
   else if (type == AT_HWCAP2)
     return GLRO(dl_hwcap2);
 
-  for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
-    if (p->a_type == type)
-      return p->a_un.a_val;
+  if (GLRO(dl_auxv) != NULL)
+    for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
+      if (p->a_type == type)
+	return p->a_un.a_val;
 
   __set_errno (ENOENT);
   return 0;