aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox/top-buffer-overflow.patch
blob: 14b23c64885518403ad8fab99b0db5e8f5d567e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--- busybox-1.27.0.orig/procps/top.c
+++ busybox-1.27.0/procps/top.c
@@ -694,10 +694,14 @@
 		CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift);
 #endif
 
-		if (s->vsz >= 100000)
-			sprintf(vsz_str_buf, "%6ldm", s->vsz/1024);
+		if ((s->vsz / (1024 * 1024)) >= 100000)
+			snprintf(vsz_str_buf, sizeof(vsz_str_buf), "%6ldt", s->vsz/(1024 * 1024 * 1024));
+		else if ((s->vsz / 1024) >= 100000)
+			snprintf(vsz_str_buf, sizeof(vsz_str_buf), "%6ldg", s->vsz/(1024 * 1024));
+		else if (s->vsz >= 100000)
+			snprintf(vsz_str_buf, sizeof(vsz_str_buf), "%6ldm", s->vsz/1024);
 		else
-			sprintf(vsz_str_buf, "%7lu", s->vsz);
+			snprintf(vsz_str_buf, sizeof(vsz_str_buf), "%7lu", s->vsz);
 		/* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
 		col = snprintf(line_buf, scr_width,
 				"\n" "%5u%6u %-8.8s %s%s" FMT