svn commit: r340306 - stable/11/contrib/elftoolchain/nm

Ed Maste emaste at FreeBSD.org
Fri Nov 9 21:38:55 UTC 2018


Author: emaste
Date: Fri Nov  9 21:38:53 2018
New Revision: 340306
URL: https://svnweb.freebsd.org/changeset/base/340306

Log:
  MFC r331078 (cem): nm: 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.

Modified:
  stable/11/contrib/elftoolchain/nm/nm.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/elftoolchain/nm/nm.c
==============================================================================
--- stable/11/contrib/elftoolchain/nm/nm.c	Fri Nov  9 21:26:26 2018	(r340305)
+++ stable/11/contrib/elftoolchain/nm/nm.c	Fri Nov  9 21:38:53 2018	(r340306)
@@ -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) {


More information about the svn-src-all mailing list