From d7aca117e2aaa7dca6db40f182f64fd66644a198 Mon Sep 17 00:00:00 2001 From: Mohammed Khoory Date: Mon, 4 Nov 2013 10:49:44 +0900 Subject: Fixed comparison of ELF object names --- rtl-obj.c | 38 +++++++++++++++++++++++--------------- rtl-obj.h | 16 ++++++++++++++++ rtl.c | 7 +++++++ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/rtl-obj.c b/rtl-obj.c index 7e20f46..532756a 100644 --- a/rtl-obj.c +++ b/rtl-obj.c @@ -115,11 +115,14 @@ rtems_rtl_obj_unresolved (rtems_rtl_obj_t* obj) return (obj->flags & RTEMS_RTL_OBJ_UNRESOLVED) != 0 ? true : false; } -static bool -rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) +bool +rtems_rtl_parse_name (const char* name, + const char** aname, + const char** oname, + int* ooffset) { - const char* aname = NULL; - const char* oname = NULL; + const char* laname = NULL; + const char* loname = NULL; const char* colon; const char* end; @@ -133,14 +136,14 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) if (colon == NULL || colon < strrchr(name, '/')) colon = end; - oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, colon - name + 1, true); + loname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, colon - name + 1, true); if (!oname) { rtems_rtl_set_error (ENOMEM, "no memory for object file name"); return false; } - memcpy ((void*) oname, name, colon - name); + memcpy ((void*) loname, name, colon - name); /* * If the pointers match there is no ':' delimiter. @@ -153,7 +156,7 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) * The file name is an archive and the object file name is next after the * delimiter. Move the pointer to the archive name. */ - aname = oname; + laname = loname; ++colon; /* @@ -166,15 +169,15 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) at = end; - oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, at - colon + 1, true); - if (!oname) + loname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, at - colon + 1, true); + if (!loname) { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) aname); + rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) laname); rtems_rtl_set_error (ENOMEM, "no memory for object file name"); return false; } - memcpy ((void*) oname, colon, at - colon); + memcpy ((void*) loname, colon, at - colon); if (at != end) { @@ -183,16 +186,21 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) * does not parse 0 will be returned and the archive will be * searched. */ - obj->ooffset = strtoul (at + 1, 0, 0); + *ooffset = strtoul (at + 1, 0, 0); } } - obj->oname = oname; - obj->aname = aname; - + *oname = loname; + *aname = laname; return true; } +static bool +rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) +{ + return rtems_rtl_parse_name (name, &(obj->aname), &(obj->oname), &(obj->ooffset)); +} + static bool rtems_rtl_seek_read (int fd, off_t off, size_t len, uint8_t* buffer) { diff --git a/rtl-obj.h b/rtl-obj.h index 2f7c403..7e200d6 100644 --- a/rtl-obj.h +++ b/rtl-obj.h @@ -280,6 +280,22 @@ bool rtems_rtl_obj_free (rtems_rtl_obj_t* obj); */ bool rtems_rtl_obj_unresolved (rtems_rtl_obj_t* obj); +/** + * Parses a filename and returns newly allocated strings with the archive name, + * object name, and the object's offset + * + * @param name The filename of the object + * @param aname Address of a string pointer that holds the archive name + * @param oname Address of a string pointer that holds the object name + * @param ooffset Address of an int that holds the object offset + * @retval true The parsing was successful + * @retval false The parsing was unsuccessful + */ +bool rtems_rtl_parse_name (const char* name, + const char** aname, + const char** oname, + int* ooffset); + /** * Load the object file. * diff --git a/rtl.c b/rtl.c index 9429046..3e96742 100644 --- a/rtl.c +++ b/rtl.c @@ -375,6 +375,13 @@ rtems_rtl_obj_t* rtems_rtl_find_obj (const char* name) { rtems_chain_node* node; + rtems_rtl_obj_t* found = NULL; + const char* aname = NULL; + const char* oname = NULL; + int ooffset; + + if (!rtems_rtl_parse_name (name, &aname, &oname, &ooffset)) + return NULL; node = rtems_chain_first (&rtl->objects); -- cgit v1.2.3