Re: [PATCH v3] dlfcn: Deprecate dlinfo request type RTLD_DI_ORIGIN (bug #24298)

"Andreas K. Huettel" <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Organization Gentoo Linux
Message-ID <[email protected]>
Am Dienstag, 14. Juli 2026, 21:40:59 Japanische Normalzeit schrieb Arjun Shankar:
> Commit b52619f2e8bbae57d79c95538346198c4a9f24a6 added a new dlinfo
> request type, RTLD_DI_ORIGIN_PATH, to be used instead of RTLD_DI_ORIGIN
> which is prone to buffer overflows.  With a replacement available,
> RTLD_DI_ORIGIN can now be deprecated.

Is this in any way urgent? 
I would suggest after the release.

> 
> This commit deprecates RTLD_DI_ORIGIN by adding a compile-time warning
> upon its use, and documents the deprecation in the manual.
> 
> The warning depends on "Enumerator Attributes" supported by gcc
> since 6.1 and by clang.  A new macro __attribute_deprecated_enum__,
> analogous to __attribute_deprecated_msg__, is defined in cdefs.h.
> Because gnulib can override system-installed cdefs.h, thus hiding our
> definition, the deprecation is conditional on the macro being defined.
> ---
> v2:
> https://inbox.sourceware.org/libc-alpha/[email protected]/
> 
> Changes in v3:
> Made the warning conditional to __attribute_deprecated_enum__ being defined,
> because gnulib could override system-installed cdefs.h where we have defined
> it.
> ---
>  dlfcn/dlfcn.h       | 9 +++++++--
>  dlfcn/dlinfo.c      | 5 +++++
>  dlfcn/tst-dlinfo.c  | 5 +++++
>  manual/dynlink.texi | 6 +++---
>  misc/sys/cdefs.h    | 9 +++++++++
>  5 files changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
> index a73303a17e..b9d4257e98 100644
> --- a/dlfcn/dlfcn.h
> +++ b/dlfcn/dlfcn.h
> @@ -145,8 +145,13 @@ enum
>      RTLD_DI_SERINFOSIZE = 5,
>  
>      /* Treat ARG as `char *', and store there the directory name used to
> -       expand $ORIGIN in this shared object's dependency file names.  */
> -    RTLD_DI_ORIGIN = 6,
> +       expand $ORIGIN in this shared object's dependency file names.
> +       Deprecated due to potential for buffer overflows.  */
> +    RTLD_DI_ORIGIN
> +# ifdef __attribute_deprecated_enum__
> +      __attribute_deprecated_enum__ ("Use RTLD_DI_ORIGIN_PATH instead")
> +# endif
> +      = 6,
>  
>      RTLD_DI_PROFILENAME = 7,	/* Unsupported, defined by Solaris.  */
>      RTLD_DI_PROFILEOUT = 8,	/* Unsupported, defined by Solaris.  */
> diff --git a/dlfcn/dlinfo.c b/dlfcn/dlinfo.c
> index a4c6ffb5b8..99257e7464 100644
> --- a/dlfcn/dlinfo.c
> +++ b/dlfcn/dlinfo.c
> @@ -22,6 +22,7 @@
>  #include <libintl.h>
>  #include <dl-tls.h>
>  #include <shlib-compat.h>
> +#include <libc-diag.h>
>  
>  struct dlinfo_args
>  {
> @@ -63,9 +64,13 @@ dlinfo_doit (void *argsblock)
>        _dl_rtld_di_serinfo (l, args->arg, true);
>        break;
>  
> +    DIAG_PUSH_NEEDS_COMMENT;
> +    DIAG_IGNORE_NEEDS_COMMENT (6.1, "-Wdeprecated-declarations");
> +    /* Deprecated via compile-time warning due to buffer overflow risk.  */
>      case RTLD_DI_ORIGIN:
>        strcpy (args->arg, l->l_origin);
>        break;
> +    DIAG_POP_NEEDS_COMMENT;
>  
>      case RTLD_DI_ORIGIN_PATH:
>        if (l->l_origin != (char *) -1)
> diff --git a/dlfcn/tst-dlinfo.c b/dlfcn/tst-dlinfo.c
> index d0c8d8fb6d..cdaf031575 100644
> --- a/dlfcn/tst-dlinfo.c
> +++ b/dlfcn/tst-dlinfo.c
> @@ -21,6 +21,7 @@
>  #include <stdlib.h>
>  #include <error.h>
>  #include <support/check.h>
> +#include <libc-diag.h>
>  
>  #define TEST_FUNCTION do_test ()
>  
> @@ -51,11 +52,15 @@ do_test (void)
>  	}
>      }
>  
> +  DIAG_PUSH_NEEDS_COMMENT;
> +  /* Ignore deprecation to be able to test deprecated request type.  */
> +  DIAG_IGNORE_NEEDS_COMMENT (6.1, "-Wdeprecated-declarations");
>    char origin[8192];		/* >= PATH_MAX, in theory */
>    TRY (RTLD_DI_ORIGIN, origin)
>      {
>        printf ("origin: %s\n", origin);
>      }
> +  DIAG_POP_NEEDS_COMMENT;
>  
>    const char *origin_path;
>    TRY (RTLD_DI_ORIGIN_PATH, &origin_path)
> diff --git a/manual/dynlink.texi b/manual/dynlink.texi
> index 548def534e..ad4da753a5 100644
> --- a/manual/dynlink.texi
> +++ b/manual/dynlink.texi
> @@ -569,9 +569,9 @@ The value of the @code{$ORIGIN} dynamic string token for @var{handle} is
>  written to the character array starting at @var{arg} as a
>  null-terminated string.
>  
> -This request type should not be used because it is prone to buffer
> -overflows.  Instead, @code{RTLD_DI_ORIGIN_PATH} described above should be
> -used.
> +This request type has been deprecated because it is prone to buffer
> +overflows and should therefore not be used.  Instead,
> +@code{RTLD_DI_ORIGIN_PATH} described above should be used.
>  
>  @item RTLD_DI_SERINFO
>  @itemx RTLD_DI_SERINFOSIZE
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index 8d27f26da8..84c4aae262 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -523,6 +523,15 @@
>  # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
>  #endif
>  
> +/* Since version 6.1, gcc allows marking deprecated enumerators.  */
> +#if __GNUC_PREREQ (6, 1) \
> +    || __glibc_has_extension (__enumerator_attributes__)
> +# define __attribute_deprecated_enum__(msg) \
> +         __attribute__ ((__deprecated__ (msg)))
> +#else
> +# define __attribute_deprecated_enum__(msg) /* Ignore */
> +#endif
> +
>  /* At some point during the gcc 2.8 development the `format_arg' attribute
>     for functions was introduced.  We don't want to use it unconditionally
>     (although this would be possible) since it generates warnings.
> 


-- 
PD Dr. Andreas K. Hüttel
[email protected]
Gentoo Linux developer 
(council, comrel, toolchain, base-system, perl, libreoffice)
https://wiki.gentoo.org/wiki/User:Dilfridge
signature.asc (application/pgp-signature, 870 B)
-----BEGIN PGP SIGNATURE-----

iQJPBAABCAA5FiEE/Rnm0xsZLuTcY+rT3CsWIV7VQSoFAmpXb9gbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwyAAoJENwrFiFe1UEqlmsP/jLDul6Z6b6rMB1/90ZB
BUX9Bcfb4Xr/XBHQX07S8CWmVi2tqYxZ4IoHGxE+9sLx5vSAtXKv29gJm6PR7av2
2oBlxwijETIVfP3sRFh+se98DNn911bnpyCnQj9t1wlZfRG8BtJ9vi3tuQvcSAHz
QTQSgxHTqQnK6HRMoltJ0gjYggAl4uG0dbONCgJVI73ycW1qcIcdWbfheSQOKdkt
IsrQupWRRM5lrwbyfpp1UZfVGmbO5BGWWvObaCchpc1uAj0wWM/ttloi5IcQP6lt
LxO9uGDb63wHdYP2xzCOU4Xx9KMnPmvcInftn0WpSaio4iY0mE82UDzUOcGyFpIu
had8fTU8YrNv5LTM5Jkvcr2OxmHkiFxOGa1qf30G4pAfa3zbkk9CHWObPzYQi1f+
3yPBvGcvm4tl19oBiRXixymgMBHMbMgpEqwt9zrQpAjZPYjKQfx/u6uZcLMsvZ1n
6MCY3TEg4jtgSRuiLwVzTJ5whxn5yutVTtz67w3h+lPL+lu7EBrEh1k8mJs3Wm/6
1I2ndyey7Ip+sb1NcljfPRQHRSSQ2J8WHQmVu+JWlkRQ7dyb8TOkgYze2mgdXE+h
cLOsAE9uQIgj+34CPSR4ewvcAA0y6FglvqyHpKn+yNcU5yLk5xTUr1UQ3HQGyuRc
b8p0fgXML+sD5CDL8WTb23HN
=+imM
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.