[PATCH 4/7] Move libc_freeres_ptrs and libc_subfreeres to weak functions
Florian Weimer
fweimer@redhat.com
Mon Dec 12 10:55:40 GMT 2022
* Adhemerval Zanella via Libc-alpha:
> diff --git a/crypt/md5-crypt.c b/crypt/md5-crypt.c
> index 7c4fb9fb97..9660cdd698 100644
> --- a/crypt/md5-crypt.c
> +++ b/crypt/md5-crypt.c
> @@ -299,10 +299,7 @@ __md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
> return buffer;
> }
>
> -#ifndef _LIBC
> -# define libc_freeres_ptr(decl) decl
> -#endif
> -libc_freeres_ptr (static char *buffer);
> +static char *buffer;
>
> char *
> __md5_crypt (const char *key, const char *salt)
> @@ -330,7 +327,10 @@ __md5_crypt (const char *key, const char *salt)
> static void
> __attribute__ ((__destructor__))
> free_mem (void)
> +#else
> +void
> +__md5_crypt_freemem (void)
> +#endif
> {
> free (buffer);
> }
> -#endif
> diff --git a/crypt/sha256-crypt.c b/crypt/sha256-crypt.c
> index a98a968a8b..75fd582429 100644
> --- a/crypt/sha256-crypt.c
> +++ b/crypt/sha256-crypt.c
> @@ -386,10 +386,7 @@ __sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
> return buffer;
> }
>
> -#ifndef _LIBC
> -# define libc_freeres_ptr(decl) decl
> -#endif
> -libc_freeres_ptr (static char *buffer);
> +static char *buffer;
>
> /* This entry point is equivalent to the `crypt' function in Unix
> libcs. */
> @@ -422,7 +419,10 @@ __sha256_crypt (const char *key, const char *salt)
> static void
> __attribute__ ((__destructor__))
> free_mem (void)
> +#else
> +void
> +__sha256_crypt_freemem (void)
> +#endif
> {
> free (buffer);
> }
> -#endif
> diff --git a/crypt/sha512-crypt.c b/crypt/sha512-crypt.c
> index ea13527c09..ae6ecaef16 100644
> --- a/crypt/sha512-crypt.c
> +++ b/crypt/sha512-crypt.c
> @@ -408,10 +408,7 @@ __sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
> return buffer;
> }
>
> -#ifndef _LIBC
> -# define libc_freeres_ptr(decl) decl
> -#endif
> -libc_freeres_ptr (static char *buffer);
> +static char *buffer;
>
> /* This entry point is equivalent to the `crypt' function in Unix
> libcs. */
> @@ -444,7 +441,10 @@ __sha512_crypt (const char *key, const char *salt)
> static void
> __attribute__ ((__destructor__))
> free_mem (void)
> +#else
> +void
> +__sha512_crypt_freemem (void)
> +#endif
> {
> free (buffer);
> }
> -#endif
I think you should delete the entire deallocation logic, or make use of
the ELF destructor unconditional. This wasn't linked into libc, so it
wasn't run from __libc_freeres, and the hook registration was a no-op.
(I believe, I haven't checked.)
Thanks,
Florian
More information about the Libc-alpha
mailing list