summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-18 22:42:23 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-18 22:42:23 +0000
commit557e404d6595bed6be66076577b829a00f39eda4 (patch)
tree361c700610de267c069899ca3ccec93920752503
parent20d8808116d749b626c080b2891c968f163966e6 (diff)
Be extra careful to memset the correct size, not the size of some random
pointer. Fix printing of '0x0x' in ldd output. Simplify discrimination of libname, so doing things like dlopen("./libfoo.so",RTLD_NOW) with a leading "./" in the path will work as expected. -Erik
-rw-r--r--ldso/ldso/dl-elf.c22
-rw-r--r--ldso/ldso/dl-hash.c4
-rw-r--r--ldso/ldso/hash.c4
-rw-r--r--ldso/ldso/ldso.c28
-rw-r--r--ldso/ldso/readelflib1.c22
5 files changed, 37 insertions, 43 deletions
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 261505b1a..0290d6ccf 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -178,7 +178,7 @@ extern char *_dl_ldsopath;
struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
struct elf_resolve *tpnt, char *full_libname)
{
- char *pnt;
+ char *pnt, *pnt1;
struct elf_resolve *tpnt1;
char *libname;
@@ -190,10 +190,10 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
if (_dl_strlen(full_libname) > 1024)
goto goof;
- while (*pnt) {
- if (*pnt == '/')
- libname = pnt + 1;
- pnt++;
+ /* Skip over any initial initial './' path to get the libname */
+ pnt1 = _dl_strrchr(pnt, '/');
+ if (pnt1) {
+ libname = pnt1 + 1;
}
#if defined (__SUPPORT_LD_DEBUG__)
@@ -207,7 +207,7 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
tpnt1 = _dl_load_elf_shared_library(secure, rpnt, full_libname);
if (tpnt1)
return tpnt1;
- goto goof;
+ //goto goof;
}
/*
@@ -334,9 +334,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
tpnt = _dl_check_hashed_files(libname);
if (tpnt) {
if (*rpnt) {
- (*rpnt)->next = (struct dyn_elf *)
- _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next)));
+ (*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+ _dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
(*rpnt)->next->prev = (*rpnt);
*rpnt = (*rpnt)->next;
(*rpnt)->dyn = tpnt;
@@ -602,9 +601,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
* Add this object into the symbol chain
*/
if (*rpnt) {
- (*rpnt)->next = (struct dyn_elf *)
- _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next)));
+ (*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+ _dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
(*rpnt)->next->prev = (*rpnt);
*rpnt = (*rpnt)->next;
(*rpnt)->dyn = tpnt;
diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c
index 6922ba9de..bd7ac7708 100644
--- a/ldso/ldso/dl-hash.c
+++ b/ldso/ldso/dl-hash.c
@@ -109,13 +109,13 @@ struct elf_resolve *_dl_add_elf_hash_table(const char *libname,
if (!_dl_loaded_modules) {
tpnt = _dl_loaded_modules =
(struct elf_resolve *) _dl_malloc(sizeof(struct elf_resolve));
- _dl_memset(tpnt, 0, sizeof(*tpnt));
+ _dl_memset(tpnt, 0, sizeof(struct elf_resolve));
} else {
tpnt = _dl_loaded_modules;
while (tpnt->next)
tpnt = tpnt->next;
tpnt->next = (struct elf_resolve *) _dl_malloc(sizeof(struct elf_resolve));
- _dl_memset(tpnt->next, 0, sizeof(*(tpnt->next)));
+ _dl_memset(tpnt->next, 0, sizeof(struct elf_resolve));
tpnt->next->prev = tpnt;
tpnt = tpnt->next;
};
diff --git a/ldso/ldso/hash.c b/ldso/ldso/hash.c
index 6922ba9de..bd7ac7708 100644
--- a/ldso/ldso/hash.c
+++ b/ldso/ldso/hash.c
@@ -109,13 +109,13 @@ struct elf_resolve *_dl_add_elf_hash_table(const char *libname,
if (!_dl_loaded_modules) {
tpnt = _dl_loaded_modules =
(struct elf_resolve *) _dl_malloc(sizeof(struct elf_resolve));
- _dl_memset(tpnt, 0, sizeof(*tpnt));
+ _dl_memset(tpnt, 0, sizeof(struct elf_resolve));
} else {
tpnt = _dl_loaded_modules;
while (tpnt->next)
tpnt = tpnt->next;
tpnt->next = (struct elf_resolve *) _dl_malloc(sizeof(struct elf_resolve));
- _dl_memset(tpnt->next, 0, sizeof(*(tpnt->next)));
+ _dl_memset(tpnt->next, 0, sizeof(struct elf_resolve));
tpnt->next->prev = tpnt;
tpnt = tpnt->next;
};
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 7af118533..2c1d3e33c 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -372,9 +372,9 @@ LD_BOOT(unsigned long args)
}
tpnt = LD_MALLOC(sizeof(struct elf_resolve));
- _dl_memset(tpnt, 0, sizeof(*tpnt));
+ _dl_memset(tpnt, 0, sizeof(struct elf_resolve));
app_tpnt = LD_MALLOC(sizeof(struct elf_resolve));
- _dl_memset(app_tpnt, 0, sizeof(*app_tpnt));
+ _dl_memset(app_tpnt, 0, sizeof(struct elf_resolve));
/*
* This is used by gdb to locate the chain of shared libraries that are currently loaded.
@@ -754,7 +754,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
_dl_loaded_modules->ppnt = (elf_phdr *) auxvt[AT_PHDR].a_un.a_ptr;
_dl_loaded_modules->n_phent = auxvt[AT_PHNUM].a_un.a_val;
_dl_symbol_tables = rpnt = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset(rpnt, 0, sizeof(*rpnt));
+ _dl_memset(rpnt, 0, sizeof(struct dyn_elf));
rpnt->dyn = _dl_loaded_modules;
app_tpnt->usage_count++;
app_tpnt->symbol_scope = _dl_symbol_tables;
@@ -946,7 +946,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
/* this is a real hack to make ldd not print
* the library itself when run on a library. */
if (_dl_strcmp(_dl_progname, str) != 0)
- _dl_dprintf(1, "\t%s => %s (0x%x)\n", str, tpnt1->libname,
+ _dl_dprintf(1, "\t%s => %s (%x)\n", str, tpnt1->libname,
(unsigned) tpnt1->loadaddr);
}
#endif
@@ -1019,7 +1019,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
#endif
#ifdef __LDSO_LDD_SUPPORT__
if (_dl_trace_loaded_objects && tpnt1->usage_count==1) {
- _dl_dprintf(1, "\t%s => %s (0x%x)\n", cp2,
+ _dl_dprintf(1, "\t%s => %s (%x)\n", cp2,
tpnt1->libname, (unsigned) tpnt1->loadaddr);
}
#endif
@@ -1073,7 +1073,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
name = tpnt->libname;
while(*name == '/')
name++;
- _dl_dprintf(1, "\t%s => %s (0x%x)\n",
+ _dl_dprintf(1, "\t%s => %s (%x)\n",
lpntstr, --name, (unsigned) tpnt->loadaddr);
}
#endif
@@ -1083,9 +1083,8 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
ttmp->next = tpnt;
tpnt->prev = ttmp;
tpnt->next = NULL;
- rpnt->next = (struct dyn_elf *)
- _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
+ rpnt->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+ _dl_memset(rpnt->next, 0, sizeof(struct dyn_elf));
rpnt->next->prev = rpnt;
rpnt = rpnt->next;
rpnt->dyn = tpnt;
@@ -1115,7 +1114,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
name = tpnt1->libname;
while(*name == '/')
name++;
- _dl_dprintf(1, "\t%s => %s (0x%x)\n", lpntstr, --name,
+ _dl_dprintf(1, "\t%s => %s (%x)\n", lpntstr, --name,
(unsigned) tpnt1->loadaddr);
}
#endif
@@ -1150,14 +1149,13 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
tpnt->prev = NULL;
}
if (rpnt) {
- rpnt->next =
- (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset(rpnt->next, 0, sizeof(*(rpnt->next)));
+ rpnt->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+ _dl_memset(rpnt->next, 0, sizeof(struct dyn_elf));
rpnt->next->prev = rpnt;
rpnt = rpnt->next;
} else {
rpnt = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset(rpnt, 0, sizeof(*(rpnt->next)));
+ _dl_memset(rpnt, 0, sizeof(struct dyn_elf));
}
rpnt->dyn = tpnt;
tpnt = NULL;
@@ -1166,7 +1164,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
#ifdef __LDSO_LDD_SUPPORT__
/* End of the line for ldd.... */
if (_dl_trace_loaded_objects) {
- _dl_dprintf(1, "\t%s => %s (0x%x)\n", rpnt->dyn->libname + (_dl_strlen(_dl_ldsopath)) + 1,
+ _dl_dprintf(1, "\t%s => %s (%x)\n", rpnt->dyn->libname + (_dl_strlen(_dl_ldsopath)) + 1,
rpnt->dyn->libname, rpnt->dyn->loadaddr);
_dl_exit(0);
}
diff --git a/ldso/ldso/readelflib1.c b/ldso/ldso/readelflib1.c
index 261505b1a..0290d6ccf 100644
--- a/ldso/ldso/readelflib1.c
+++ b/ldso/ldso/readelflib1.c
@@ -178,7 +178,7 @@ extern char *_dl_ldsopath;
struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
struct elf_resolve *tpnt, char *full_libname)
{
- char *pnt;
+ char *pnt, *pnt1;
struct elf_resolve *tpnt1;
char *libname;
@@ -190,10 +190,10 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
if (_dl_strlen(full_libname) > 1024)
goto goof;
- while (*pnt) {
- if (*pnt == '/')
- libname = pnt + 1;
- pnt++;
+ /* Skip over any initial initial './' path to get the libname */
+ pnt1 = _dl_strrchr(pnt, '/');
+ if (pnt1) {
+ libname = pnt1 + 1;
}
#if defined (__SUPPORT_LD_DEBUG__)
@@ -207,7 +207,7 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
tpnt1 = _dl_load_elf_shared_library(secure, rpnt, full_libname);
if (tpnt1)
return tpnt1;
- goto goof;
+ //goto goof;
}
/*
@@ -334,9 +334,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
tpnt = _dl_check_hashed_files(libname);
if (tpnt) {
if (*rpnt) {
- (*rpnt)->next = (struct dyn_elf *)
- _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next)));
+ (*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+ _dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
(*rpnt)->next->prev = (*rpnt);
*rpnt = (*rpnt)->next;
(*rpnt)->dyn = tpnt;
@@ -602,9 +601,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
* Add this object into the symbol chain
*/
if (*rpnt) {
- (*rpnt)->next = (struct dyn_elf *)
- _dl_malloc(sizeof(struct dyn_elf));
- _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next)));
+ (*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+ _dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
(*rpnt)->next->prev = (*rpnt);
*rpnt = (*rpnt)->next;
(*rpnt)->dyn = tpnt;