Bug#1337: Improper use of sscanf in procps
Package: procps
Version: 0.97-4
Occasionally "ps -a" would display command lines incorrectly:
$ ps -a
PID TTY STAT TIME COMMAND
197 v11 SW 0:00 (getty)
198 v12 SW 0:00 (getty)
14360 v10 SW 0:00 (getty)
21795 v09 SW 3:50 (bash)
31647 s02 SW 0:01 (uugetty)map)
<..deleted..>
Of course, the last line should've been "(uugetty)". The "map)" part
comes from "(rpc.portmap)". This is caused by the use of "%40c" in
snap.c when calling sscanf(). Since "%40c" doesn't put a NUL at the
end of the string, any parts of a previously assigned value would
remain, as is the case here. Here is a patch to fix it:
--- procps-0.97/snap.c.orig Sat Sep 9 19:28:02 1995
+++ procps-0.97/snap.c Sat Sep 9 19:45:33 1995
@@ -35,7 +35,7 @@
;
*tmp='\0';
/* Now we can parse these two strings separately */
- sscanf(S, "%d %40c", &P->pid, P->cmd);
+ sscanf(S, "%d %39s", &P->pid, P->cmd);
sscanf(tmp+1, "%c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u "
"%d %u %u %u %u %u %u %u %u %d %d %d %d %u",
&P->state, &P->ppid, &P->pgrp, &P->session, &P->tty, &P->tpgid,
--
A. B <=> True B. A <=> False
Email: Herbert Xu ~{PmV>HI~} <herbert@greathan.apana.org.au>
PGP Key: pgp-public-keys@pgp.mit.edu or any other key sites
Reply to: