Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/top/dist/machine Fix read of unitialized array ...
details: https://anonhg.NetBSD.org/src/rev/0dac152adaf7
branches: trunk
changeset: 323106:0dac152adaf7
user: kamil <kamil%NetBSD.org@localhost>
date: Thu May 31 10:14:21 2018 +0000
description:
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.
==26662==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x268a2c in percentages64 /usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:1341:6
#1 0x26748b in get_system_info /usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:478:6
#2 0x25518e in do_display /usr/src/external/bsd/top/bin/../dist/top.c:507:5
#3 0x253038 in main /usr/src/external/bsd/top/bin/../dist/top.c:975:2
#4 0x21cad1 in ___start (/usr/bin/top+0x1cad1)
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>
diffstat:
external/bsd/top/dist/machine/m_netbsd.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diffs (33 lines):
diff -r d6248e52f847 -r 0dac152adaf7 external/bsd/top/dist/machine/m_netbsd.c
--- a/external/bsd/top/dist/machine/m_netbsd.c Thu May 31 09:37:16 2018 +0000
+++ b/external/bsd/top/dist/machine/m_netbsd.c Thu May 31 10:14:21 2018 +0000
@@ -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.20 2018/05/31 10:14:21 kamil Exp $ */
/*
* top - a top users display for Unix
@@ -37,12 +37,12 @@
* Andrew Doran <ad%NetBSD.org@localhost>
*
*
- * $Id: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $
+ * $Id: m_netbsd.c,v 1.20 2018/05/31 10:14:21 kamil 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.20 2018/05/31 10:14:21 kamil Exp $");
#endif
#include <sys/param.h>
@@ -335,7 +335,7 @@
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) {
Home |
Main Index |
Thread Index |
Old Index