1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-09 13:57:42 +03:00

build-path: fix SIGSEGV on RISC-V and MIPS

On RISC-V and MIPS DT_STRTAB is an offset, not a full address.

Follow-up for 91d149cfb45fc2fad7ce18fb651297ee50ecc1f8
This commit is contained in:
Luca Boccassi 2024-04-27 15:25:09 +01:00 committed by Luca Boccassi
parent 2ff22bf132
commit ba2caa8a38

View File

@ -12,7 +12,7 @@
#include "process-util.h"
#include "unistd.h"
static int get_runpath_from_dynamic(const ElfW(Dyn) *d, const char **ret) {
static int get_runpath_from_dynamic(const ElfW(Dyn) *d, ElfW(Addr) bias, const char **ret) {
size_t runpath_index = SIZE_MAX, rpath_index = SIZE_MAX;
const char *strtab = NULL;
@ -33,7 +33,14 @@ static int get_runpath_from_dynamic(const ElfW(Dyn) *d, const char **ret) {
break;
case DT_STRTAB:
strtab = (const char *) d->d_un.d_val;
/* On MIPS and RISC-V DT_STRTAB records an offset, not a valid address, so it has to be adjusted
* using the bias calculated earlier. */
if (d->d_un.d_val != 0)
strtab = (const char *) ((uintptr_t) d->d_un.d_val
#if defined(__mips__) || defined(__riscv)
+ bias
#endif
);
break;
}
@ -45,7 +52,7 @@ static int get_runpath_from_dynamic(const ElfW(Dyn) *d, const char **ret) {
if (!strtab)
return -ENOTRECOVERABLE;
/* According to dl.so runpath wins of both runpath and rpath are defined. */
/* According to ld.so runpath wins if both runpath and rpath are defined. */
if (runpath_index != SIZE_MAX) {
if (ret)
*ret = strtab + runpath_index;
@ -111,7 +118,7 @@ static int get_runpath(const char **ret) {
if (!found_dyn)
return -ENOTRECOVERABLE;
return get_runpath_from_dynamic((const ElfW(Dyn)*) (bias + dyn), ret);
return get_runpath_from_dynamic((const ElfW(Dyn)*) (bias + dyn), bias, ret);
}
int get_build_exec_dir(char **ret) {