[PATCH 01/13] elf: strdup() l_name if no realname [BZ #30100]

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Mar 29 14:19:37 GMT 2023



On 29/03/23 11:12, stsp wrote:
> 
> 29.03.2023 18:54, Adhemerval Zanella Netto пишет:
>>
>> On 18/03/23 13:50, Stas Sergeev via Libc-alpha wrote:
>>> _dl_close_worker() has this code:
>>>        /* This name always is allocated.  */
>>>        free (imap->l_name);
>>>
>>> But in that particular case, while indeed being allocated, l_name
>>> doesn't point to the start of an allocation:
>>>    new = (struct link_map *) calloc (sizeof (*new) + audit_space
>>>                                      + sizeof (struct link_map *)
>>>                                      + sizeof (*newname) + libname_len, 1);
>>>    ...
>>>    new->l_symbolic_searchlist.r_list = (struct link_map **) ((char *) (new + 1)
>>>                                                              + audit_space);
>>>
>>>    new->l_libname = newname
>>>      = (struct libname_list *) (new->l_symbolic_searchlist.r_list + 1);
>>>    newname->name = (char *) memcpy (newname + 1, libname, libname_len);
>>>    ...
>>>    new->l_name = (char *) newname->name + libname_len - 1;
>>>
>>> It therefore cannot be freed separately.
>>> Use strdup("") as a simple fix.
>> This is not required, the l_name alias to newname->name is only used for
>> __RTLD_OPENEXEC (used by loader on DT_NEEDED) and these handlers are not
>> meant to be dlclose.
> But dlmem() can also use "" as the name
> if the name is not specified explicitly.
> Without that patch it crashes.
> I think you mean its not needed w/o dlmem()?

Yes, I did not take in consideration dlmem inclusion for this.  If dlmem breaks
this assumption, it is another issue with the interface.

> Then its a dlmem-specific patch.


More information about the Libc-alpha mailing list