summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2022-01-06 17:58:59 +0100
committerMark Wielaard <mark@klomp.org>2022-01-06 17:58:59 +0100
commit04a5fd7400429398e096ccd1b32f71a1f1c8db76 (patch)
tree134bc51ed37811aa32e55d57acd60644e3a0c504 /libdwfl
parentlibdwfl: Handle unaligned Dyns in dwfl_segment_report_module (diff)
downloadelfutils-04a5fd7400429398e096ccd1b32f71a1f1c8db76.tar.gz
elfutils-04a5fd7400429398e096ccd1b32f71a1f1c8db76.tar.bz2
elfutils-04a5fd7400429398e096ccd1b32f71a1f1c8db76.tar.xz
libdwfl: Declare possible zero sized arrays only when non-zero
The gcc undefined sanitizer complains when seeing a zero sized array declaration. Move the declaration to the point in the code where we know they aren't zero sized. https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/link_map.c4
2 files changed, 7 insertions, 2 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index aace969f..b2588b12 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
12022-01-03 Mark Wielaard <mark@klomp.org> 12022-01-03 Mark Wielaard <mark@klomp.org>
2 2
3 * link_map.c (dwfl_link_map_report): Only declare d32 and d64 before
4 actual use.
5
62022-01-03 Mark Wielaard <mark@klomp.org>
7
3 * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy 8 * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy
4 dyn_data and set xlatefrom.d_buf to dyns when dyns is not aligned. 9 dyn_data and set xlatefrom.d_buf to dyns when dyns is not aligned.
5 10
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 99222bb9..c0207cd3 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -1037,8 +1037,6 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
1037 return false; 1037 return false;
1038 } 1038 }
1039 void *buf = malloc (dyn_filesz); 1039 void *buf = malloc (dyn_filesz);
1040 Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
1041 Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;
1042 if (unlikely (buf == NULL)) 1040 if (unlikely (buf == NULL))
1043 { 1041 {
1044 __libdwfl_seterrno (DWFL_E_NOMEM); 1042 __libdwfl_seterrno (DWFL_E_NOMEM);
@@ -1068,6 +1066,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
1068 /* We are looking for DT_DEBUG. */ 1066 /* We are looking for DT_DEBUG. */
1069 if (elfclass == ELFCLASS32) 1067 if (elfclass == ELFCLASS32)
1070 { 1068 {
1069 Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
1071 size_t n = dyn_filesz / sizeof (Elf32_Dyn); 1070 size_t n = dyn_filesz / sizeof (Elf32_Dyn);
1072 for (size_t i = 0; i < n; ++i) 1071 for (size_t i = 0; i < n; ++i)
1073 if ((*d32)[i].d_tag == DT_DEBUG) 1072 if ((*d32)[i].d_tag == DT_DEBUG)
@@ -1078,6 +1077,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
1078 } 1077 }
1079 else 1078 else
1080 { 1079 {
1080 Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;
1081 size_t n = dyn_filesz / sizeof (Elf64_Dyn); 1081 size_t n = dyn_filesz / sizeof (Elf64_Dyn);
1082 for (size_t i = 0; i < n; ++i) 1082 for (size_t i = 0; i < n; ++i)
1083 if ((*d64)[i].d_tag == DT_DEBUG) 1083 if ((*d64)[i].d_tag == DT_DEBUG)