libbb: move nuke_str() from passwd into libbb
[oweals/busybox.git] / libbb / procps.c
index c06ff1d704eef7e02aa57da64129ed31555e0111..5b68d343138566656441d00f7f508107ee601be4 100644 (file)
@@ -127,11 +127,11 @@ static unsigned long fast_strtoul_16(char **endptr)
        char *str = *endptr;
        unsigned long n = 0;
 
-       /* need to stop on both ' ' and '\n' */
+       /* Need to stop on both ' ' and '\n' */
        while ((c = *str++) > ' ') {
                c = ((c|0x20) - '0');
                if (c > 9)
-                       // c = c + '0' - 'a' + 10:
+                       /* c = c + '0' - 'a' + 10: */
                        c = c - ('a' - '0' - 10);
                n = n*16 + c;
        }
@@ -144,11 +144,12 @@ static unsigned long fast_strtoul_16(char **endptr)
 /* We cut a lot of corners here for speed */
 static unsigned long fast_strtoul_10(char **endptr)
 {
-       char c;
+       unsigned char c;
        char *str = *endptr;
        unsigned long n = *str - '0';
 
-       while ((c = *++str) != ' ')
+       /* Need to stop on both ' ' and '\n' */
+       while ((c = *++str) > ' ')
                n = n*10 + (c - '0');
 
        *endptr = str + 1; /* We skip trailing space! */
@@ -179,7 +180,7 @@ static char *skip_fields(char *str, int count)
 
 #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP
 int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
-                     void (*cb)(struct smaprec *, void *), void *data)
+               void (*cb)(struct smaprec *, void *), void *data)
 {
        FILE *file;
        struct smaprec currec;
@@ -424,7 +425,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
                        if (n < 11)
                                continue; /* bogus data, get next /proc/XXX */
 # if ENABLE_FEATURE_TOP_SMP_PROCESS
-                       if (n < 11+15)
+                       if (n == 11)
                                sp->last_seen_on_cpu = 0;
 # endif
 
@@ -582,6 +583,8 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm)
                buf[sz] = '\0';
                while (--sz >= 0 && buf[sz] == '\0')
                        continue;
+               /* Prevent basename("process foo/bar") = "bar" */
+               strchrnul(buf, ' ')[0] = '\0';
                base = bb_basename(buf); /* before we replace argv0's NUL with space */
                while (sz >= 0) {
                        if ((unsigned char)(buf[sz]) < ' ')