aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2018-03-16 22:25:33 +0000
committerConrad Meyer <cem@FreeBSD.org>2018-03-16 22:25:33 +0000
commit48fc14c0aa32d114e0c58ca084ff2013de482ff7 (patch)
treeb803e4201b5a88fcce302269a2626cc14acaaf0c /contrib
parent28e7752907f02a8ef4db3ba4037414d3373a6780 (diff)
downloadsrc-48fc14c0aa32d114e0c58ca084ff2013de482ff7.tar.gz
src-48fc14c0aa32d114e0c58ca084ff2013de482ff7.zip
elftoolchain nm(1): Initialize allocated memory before use
In out of memory scenarios (where one of these allocations failed but other(s) did not), nm(1) could reference the uninitialized value of these allocations (undefined behavior). Always initialize any successful allocations as the most expedient resolution of the issue. However, I would encourage upstream elftoolchain contributors to clean up the error path to just abort immediately, rather than proceeding sloppily when one allocation fails. Reported by: Coverity Sponsored by: Dell EMC Isilon
Notes
Notes: svn path=/head/; revision=331078
Diffstat (limited to 'contrib')
-rw-r--r--contrib/elftoolchain/nm/nm.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/contrib/elftoolchain/nm/nm.c b/contrib/elftoolchain/nm/nm.c
index 493f3a80b408..33ab44295c77 100644
--- a/contrib/elftoolchain/nm/nm.c
+++ b/contrib/elftoolchain/nm/nm.c
@@ -1310,14 +1310,17 @@ read_elf(Elf *elf, const char *filename, Elf_Kind kind)
line_info = malloc(sizeof(struct line_info_head));
func_info = malloc(sizeof(struct func_info_head));
var_info = malloc(sizeof(struct var_info_head));
+ if (line_info != NULL)
+ SLIST_INIT(line_info);
+ if (func_info != NULL)
+ SLIST_INIT(func_info);
+ if (var_info != NULL)
+ SLIST_INIT(var_info);
if (line_info == NULL || func_info == NULL || var_info == NULL) {
warn("malloc");
(void) dwarf_finish(dbg, &de);
goto process_sym;
}
- SLIST_INIT(line_info);
- SLIST_INIT(func_info);
- SLIST_INIT(var_info);
while ((ret = dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL,
&de)) == DW_DLV_OK) {