elf: Port ldconfig away from stack-allocated paths
authorSergey Bugaev <bugaevc@gmail.com>
Sat, 17 Jun 2023 16:40:25 +0000 (19:40 +0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 26 Jun 2023 13:04:31 +0000 (10:04 -0300)
commitdaf7b53a3c93e99ce66837e908984148fb9f11ee
treeebeaffc635c3e463725fcdc213d8a3f9670305a7
parent21fbc0a19366f89638a30eef2b53c6d4baafdb88
elf: Port ldconfig away from stack-allocated paths

ldconfig was allocating PATH_MAX bytes on the stack for the library file
name. The issues with PATH_MAX usage are well documented [0][1]; even if
a program does not rely on paths being limited to PATH_MAX bytes,
allocating 4096 bytes on the stack for paths that are typically rather
short (strlen ("/lib64/libc.so.6") is 16) is wasteful and dangerous.

[0]: https://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html
[1]: https://eklitzke.org/path-max-is-tricky

Instead, make use of asprintf to dynamically allocate memory of just the
right size on the heap.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
elf/ldconfig.c