From 9063868eb8d49e3806a920607d9e87de7700fd14 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Thu, 13 Feb 2025 09:28:08 +0200 Subject: [PATCH] libs/libc/modlib/modlib_bind.c: Fix system crash if modlib_bind fails Addrenv is changed to the newly created process' one in the beginning of modlib_bind, and needs to be changed always when returning from the function; also in error cases. Signed-off-by: Jukka Laitinen --- libs/libc/modlib/modlib_bind.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/libc/modlib/modlib_bind.c b/libs/libc/modlib/modlib_bind.c index 938bd5d611f56..ac294e3bcdd09 100644 --- a/libs/libc/modlib/modlib_bind.c +++ b/libs/libc/modlib/modlib_bind.c @@ -938,7 +938,7 @@ int modlib_bind(FAR struct module_s *modp, ret = modlib_findsymtab(loadinfo); if (ret < 0) { - return ret; + goto errout_with_addrenv; } /* Process relocations in every allocated section */ @@ -989,7 +989,7 @@ int modlib_bind(FAR struct module_s *modp, if (ret < 0) { - return ret; + goto errout_with_addrenv; } } else @@ -1042,7 +1042,7 @@ int modlib_bind(FAR struct module_s *modp, if (ret < 0) { - return ret; + goto errout_with_addrenv; } } @@ -1076,6 +1076,8 @@ int modlib_bind(FAR struct module_s *modp, } #endif + errout_with_addrenv: + #ifdef CONFIG_ARCH_ADDRENV if (loadinfo->addrenv != NULL) {