Date: Fri, 16 Mar 2018 22:25:33 +0000 (UTC) From: Conrad Meyer <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331078 - head/contrib/elftoolchain/nm Message-ID: <201803162225.w2GMPXWV083814@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cem Date: Fri Mar 16 22:25:33 2018 New Revision: 331078 URL: https://svnweb.freebsd.org/changeset/base/331078 Log: 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 Modified: head/contrib/elftoolchain/nm/nm.c Modified: head/contrib/elftoolchain/nm/nm.c ============================================================================== --- head/contrib/elftoolchain/nm/nm.c Fri Mar 16 22:23:04 2018 (r331077) +++ head/contrib/elftoolchain/nm/nm.c Fri Mar 16 22:25:33 2018 (r331078) @@ -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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803162225.w2GMPXWV083814>