diff options
-rw-r--r-- | ldso/ldso/dl-elf.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 61fff7b0e..857465337 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -136,20 +136,33 @@ static struct elf_resolve * search_for_named_library(const char *name, int secure, const char *path_list, struct dyn_elf **rpnt) { - char *path, *path_n; - char mylibname[2050]; + char *path, *path_n, *mylibname; struct elf_resolve *tpnt; - int done = 0; + int done; if (path_list==NULL) return NULL; - /* We need a writable copy of this string */ - path = _dl_strdup(path_list); - if (!path) { + /* We need a writable copy of this string, but we don't + * need this allocated permanently since we don't want + * to leak memory, so use alloca to put path on the stack */ + done = _dl_strlen(path_list); + path = alloca(done + 1); + + /* another bit of local storage */ + mylibname = alloca(2050); + + /* gcc inlines alloca using a single instruction adjusting + * the stack pointer and no stack overflow check and thus + * no NULL error return. No point leaving in dead code... */ +#if 0 + if (!path || !mylibname) { _dl_dprintf(2, "Out of memory!\n"); _dl_exit(0); } +#endif + + _dl_strcpy(path, path_list); /* Unlike ldd.c, don't bother to eliminate double //s */ @@ -157,6 +170,7 @@ search_for_named_library(const char *name, int secure, const char *path_list, /* : at the beginning or end of path maps to CWD */ /* :: anywhere maps CWD */ /* "" maps to CWD */ + done = 0; path_n = path; do { if (*path == 0) { |