diff mbox series

[11/11] elf: Fix UB on _dl_map_object_from_fd

Message ID 20250507142110.3452012-12-adhemerval.zanella@linaro.org
State New
Headers show
Series Add initial support for --enable-ubsan | expand

Commit Message

Adhemerval Zanella May 7, 2025, 2:17 p.m. UTC
On 32-bit architecture ubsan triggers:

UBSAN: Undefined behaviour in dl-load.c:1345:54 pointer index expression with base 0x00612508 overflowed  to 0xf7c3a508

Use explicit uintptr_t operation instead.
---
 elf/dl-load.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/elf/dl-load.c b/elf/dl-load.c
index bf29ec725d..6e26ef0583 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1340,7 +1340,7 @@  cannot enable executable stack as shared object requires");
 
   /* Adjust the address of the TLS initialization image.  */
   if (l->l_tls_initimage != NULL)
-    l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr;
+    l->l_tls_initimage = (void*)((uintptr_t)l->l_tls_initimage + l->l_addr);
 
   /* Process program headers again after load segments are mapped in
      case processing requires accessing those segments.  Scan program