[PATCH 4/7] Move libc_freeres_ptrs and libc_subfreeres to weak functions
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Dec 12 13:14:20 GMT 2022
On 12/12/22 07:55, Florian Weimer wrote:
> * 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.)
Indeed you are right and for modern systems is highly unlikely that glibc
libcrypto will be used anyways (at least for system I usually check libxcrypt
is used instead). I will just remove it.
More information about the Libc-alpha
mailing list