aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-01-06 03:26:53 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-01-06 03:26:53 +0000
commit56ea65ca5f30778f05c8882b04e3a94c869bbca4 (patch)
tree85a5d24ca1a86b504779b034fd9e7dbe4dfffa38 /procps/ps.c
parent5fee2e1a79dc6fc05658821a86b0e7b5678a90dd (diff)
downloadbusybox-w32-56ea65ca5f30778f05c8882b04e3a94c869bbca4.tar.gz
busybox-w32-56ea65ca5f30778f05c8882b04e3a94c869bbca4.tar.bz2
busybox-w32-56ea65ca5f30778f05c8882b04e3a94c869bbca4.zip
ps: fix overflow in USER and VSZ columns
function old new delta smart_ulltoa4 - 280 +280 smart_ulltoa5 283 408 +125 ulltoa6_and_space - 25 +25 scale 28 38 +10 bbunpack 358 366 +8 ps_main 259 261 +2 glob3 35 37 +2 fill_bounds 172 174 +2 process_stdin 456 446 -10 smart_ulltoa6 406 - -406 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 6/1 up/down: 454/-416) Total: 38 bytes
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/procps/ps.c b/procps/ps.c
index a6c35f101..6a6a9e6d6 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -25,9 +25,9 @@ enum { MAX_WIDTH = 2*1024 };
25 25
26#if ENABLE_SELINUX 26#if ENABLE_SELINUX
27#define SELINIX_O_PREFIX "label," 27#define SELINIX_O_PREFIX "label,"
28#define DEFAULT_O_STR (SELINIX_O_PREFIX "pid,user" USE_FEATURE_PS_TIME(",time")) 28#define DEFAULT_O_STR (SELINIX_O_PREFIX "pid,user" USE_FEATURE_PS_TIME(",time") ",args")
29#else 29#else
30#define DEFAULT_O_STR ("pid,user" USE_FEATURE_PS_TIME(",time")) 30#define DEFAULT_O_STR ("pid,user" USE_FEATURE_PS_TIME(",time") ",args")
31#endif 31#endif
32 32
33typedef struct { 33typedef struct {
@@ -188,7 +188,10 @@ static void func_pgid(char *buf, int size, const procps_status_t *ps)
188static void put_lu(char *buf, int size, unsigned long u) 188static void put_lu(char *buf, int size, unsigned long u)
189{ 189{
190 char buf5[5]; 190 char buf5[5];
191 smart_ulltoa5( ((unsigned long long)u) << 10, buf5); 191
192 /* see http://en.wikipedia.org/wiki/Tera */
193 smart_ulltoa4( (u, buf5, " mgtpezy");
194 buf5[5] = '\0';
192 sprintf(buf, "%.*s", size, buf5); 195 sprintf(buf, "%.*s", size, buf5);
193} 196}
194 197
@@ -505,9 +508,9 @@ int ps_main(int argc, char **argv)
505#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ 508#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
506 509
507 if (use_selinux) 510 if (use_selinux)
508 puts(" PID Context Stat Command"); 511 puts(" PID CONTEXT STAT COMMAND");
509 else 512 else
510 puts(" PID Uid VSZ Stat Command"); 513 puts(" PID USER VSZ STAT COMMAND");
511 514
512 while ((p = procps_scan(p, 0 515 while ((p = procps_scan(p, 0
513 | PSSCAN_PID 516 | PSSCAN_PID
@@ -519,7 +522,7 @@ int ps_main(int argc, char **argv)
519 ))) { 522 ))) {
520#if ENABLE_SELINUX 523#if ENABLE_SELINUX
521 if (use_selinux) { 524 if (use_selinux) {
522 len = printf("%5u %-32s %s ", 525 len = printf("%5u %-32.32s %s ",
523 p->pid, 526 p->pid,
524 p->context ? p->context : "unknown", 527 p->context ? p->context : "unknown",
525 p->state); 528 p->state);
@@ -527,12 +530,17 @@ int ps_main(int argc, char **argv)
527#endif 530#endif
528 { 531 {
529 const char *user = get_cached_username(p->uid); 532 const char *user = get_cached_username(p->uid);
530 if (p->vsz == 0) 533 //if (p->vsz == 0)
531 len = printf("%5u %-8s %s ", 534 // len = printf("%5u %-8.8s %s ",
532 p->pid, user, p->state); 535 // p->pid, user, p->state);
533 else 536 //else
534 len = printf("%5u %-8s %6lu %s ", 537 {
535 p->pid, user, p->vsz, p->state); 538 char buf6[6];
539 smart_ulltoa5(p->vsz, buf6, " mgtpezy");
540 buf6[5] = '\0';
541 len = printf("%5u %-8.8s %s %s ",
542 p->pid, user, buf6, p->state);
543 }
536 } 544 }
537 545
538 { 546 {