From f21830d2a8097333fd7a85ad0ddbd925eb5f1877 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 29 May 2019 17:27:16 -0600 Subject: [PATCH] dtoolutil: Fix UB when musl's dlinfo(RTLD_DI_LINKMAP) fails --- dtool/src/dtoolutil/executionEnvironment.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dtool/src/dtoolutil/executionEnvironment.cxx b/dtool/src/dtoolutil/executionEnvironment.cxx index 4152a8c356..9fce349268 100644 --- a/dtool/src/dtoolutil/executionEnvironment.cxx +++ b/dtool/src/dtoolutil/executionEnvironment.cxx @@ -610,16 +610,16 @@ read_args() { #else void *self = dlopen(NULL, RTLD_NOW | RTLD_NOLOAD); #endif - dlinfo(self, RTLD_DI_LINKMAP, &map); - - while (map != nullptr) { - const char *tail = strrchr(map->l_name, '/'); - const char *head = strchr(map->l_name, '/'); - if (tail && head && (strcmp(tail, "/libp3dtool.so." PANDA_ABI_VERSION_STR) == 0 - || strcmp(tail, "/libp3dtool.so") == 0)) { - _dtool_name = head; + if (dlinfo(self, RTLD_DI_LINKMAP, &map)) { + while (map != nullptr) { + const char *tail = strrchr(map->l_name, '/'); + const char *head = strchr(map->l_name, '/'); + if (tail && head && (strcmp(tail, "/libp3dtool.so." PANDA_ABI_VERSION_STR) == 0 + || strcmp(tail, "/libp3dtool.so") == 0)) { + _dtool_name = head; + } + map = map->l_next; } - map = map->l_next; } } #endif