From owner-svn-src-stable@freebsd.org Fri Nov 9 21:38:55 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05DD51108E73; Fri, 9 Nov 2018 21:38:55 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 86A6B8F236; Fri, 9 Nov 2018 21:38:54 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6650319846; Fri, 9 Nov 2018 21:38:54 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wA9Lcsab030189; Fri, 9 Nov 2018 21:38:54 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wA9Lcsw1030188; Fri, 9 Nov 2018 21:38:54 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201811092138.wA9Lcsw1030188@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Fri, 9 Nov 2018 21:38:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r340306 - stable/11/contrib/elftoolchain/nm X-SVN-Group: stable-11 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/11/contrib/elftoolchain/nm X-SVN-Commit-Revision: 340306 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 86A6B8F236 X-Spamd-Result: default: False [-106.87 / 200.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; ALLOW_DOMAIN_WHITELIST(-100.00)[FreeBSD.org]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; DMARC_NA(0.00)[FreeBSD.org]; RCVD_COUNT_THREE(0.00)[4]; MX_GOOD(-0.01)[cached: mx1.FreeBSD.org]; NEURAL_HAM_SHORT(-1.00)[-1.000,0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; IP_SCORE(-3.76)[ip: (-9.91), ipnet: 2610:1c1:1::/48(-4.93), asn: 11403(-3.87), country: US(-0.09)] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Nov 2018 21:38:55 -0000 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) {