summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTapani Pälli <[email protected]>2017-03-16 08:10:57 +0200
committerTapani Pälli <[email protected]>2017-03-17 07:34:26 +0200
commit70d25cae8b9769d155eb8cabf4095f2b36d9265f (patch)
treecdbbec0b0b6287ae4075a5e3114fb8e22c6e267c
parent4d4558411db166d2d66f8cec9cb581149dbe1597 (diff)
util/build-id: check dlpi_name before strstr call
According to dl_iterate_phdr man page first object visited is the main program where dlpi_name is an empty string. This fixes segfault on Android when using build-id as identifier. Fixes: d4fa083e11f ("util: Add utility build-id code.") Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Plamena Manolova <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Reviewed-by: Matt Turner <[email protected]>
-rw-r--r--src/util/build_id.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/util/build_id.c b/src/util/build_id.c
index c53e71ddfd1..898a15f2b31 100644
--- a/src/util/build_id.c
+++ b/src/util/build_id.c
@@ -55,6 +55,12 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_)
{
struct callback_data *data = data_;
+ /* The first object visited by callback is the main program.
+ * Android's libc returns a NULL pointer for the first executable.
+ */
+ if (info->dlpi_name == NULL)
+ return 0;
+
char *ptr = strstr(info->dlpi_name, data->filename);
if (ptr == NULL || ptr[strlen(data->filename)] != '\0')
return 0;