Module Name: src
Committed By: martin
Date: Sat Jun 9 15:40:05 UTC 2018
Modified Files:
src/external/bsd/top/dist/machine [netbsd-8]: m_netbsd.c
Log Message:
Pull up following revision(s) (requested by kamil in ticket #872):
external/bsd/top/dist/machine/m_netbsd.c: revision 1.20
Fix read of unitialized array elements in top(1)
The cp_old array is allocated with malloc(3) and its pointer is passed to=
percentages64().
In this function there happens a calculation of total_change, which value=
depends on the value inside the unitialized cp_old[] array.
WARNING: MemorySanitizer: use-of-uninitialized-value
/usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:1341:6
/usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:478:65
SUMMARY: MemorySanitizer: use-of-uninitialized-value
/usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:1341:6 in percentages64
Exiting
Fix this issue by changling malloc(3) with calloc(3).
Detected with Memory Sanitizer during the integration of sanitizers with
the NetBSD basesystem.
Reported by <Yang Zheng>
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.6.1 src/external/bsd/top/dist/machine/m_netbsd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/top/dist/machine/m_netbsd.c
diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.19 src/external/bsd/top/dist/machine/m_netbsd.c:1.19.6.1
--- src/external/bsd/top/dist/machine/m_netbsd.c:1.19 Mon Dec 26 12:46:31 2016
+++ src/external/bsd/top/dist/machine/m_netbsd.c Sat Jun 9 15:40:05 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $ */
+/* $NetBSD: m_netbsd.c,v 1.19.6.1 2018/06/09 15:40:05 martin Exp $ */
/*
* top - a top users display for Unix
@@ -37,12 +37,12 @@
* Andrew Doran <[email protected]>
*
*
- * $Id: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $
+ * $Id: m_netbsd.c,v 1.19.6.1 2018/06/09 15:40:05 martin Exp $
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $");
+__RCSID("$NetBSD: m_netbsd.c,v 1.19.6.1 2018/06/09 15:40:05 martin Exp $");
#endif
#include <sys/param.h>
@@ -335,7 +335,7 @@ machine_init(statics)
ncpu = 1;
cpu_states = malloc(sizeof(cpu_states[0]) * CPUSTATES * ncpu);
- cp_old = malloc(sizeof(cp_old[0]) * CPUSTATES * ncpu);
+ cp_old = calloc(CPUSTATES * ncpu, sizeof(cp_old[0]));
cp_diff = malloc(sizeof(cp_diff[0]) * CPUSTATES * ncpu);
if (cpu_states == NULL || cp_time == NULL || cp_old == NULL ||
cp_diff == NULL) {