On Fri, May 31, 2013 at 10:54:33PM -0400, Mike Frysinger wrote:
> On Friday 31 May 2013 20:34:16 Dag Wieers wrote:
> > --- busybox-1.21.0/procps/pstree.c.orig 2013-06-01 02:27:14.008530872 +0200
> > +++ busybox-1.21.0/procps/pstree.c      2013-06-01 02:31:36.483537110 +0200
> > @@ -342,7 +342,7 @@
> >   static void handle_thread(const char *comm, pid_t pid, pid_t ppid, uid_t
> > uid) {
> >          char threadname[COMM_LEN + 2];
> > -       sprintf(threadname, "{%.*s}", COMM_LEN - 2, comm);
> > +       sprintf(threadname, "{%.*s}", COMM_LEN - 1, comm);
> >          add_proc(threadname, pid, ppid, uid/*, 1*/);
> >   }
> 
> hmm, your change is correct all by itself (but really it should be using 
> sizeof()), but i don't think the current code is correct.  it *should* be 
> truncating 2 bytes from the comm name.

sizeof cannot be used directly in expressions for the * form of width
or precision, because it has the wrong type. The * requires int, and
sizeof gives size_t. If you use sizeof, you need to cast the result to
int.

> @@ -341,8 +348,8 @@ static void dump_by_user(PROC *current, uid_t uid)
>  #if ENABLE_FEATURE_SHOW_THREADS
>  static void handle_thread(const char *comm, pid_t pid, pid_t ppid, uid_t uid)
>  {
> -     char threadname[COMM_LEN + 2];
> -     sprintf(threadname, "{%.*s}", COMM_LEN - 2, comm);
> +     char threadname[COMM_DISP_LEN + 1];
> +     sprintf(threadname, "{%.*s}", sizeof(threadname) - 1, comm);
>       add_proc(threadname, pid, ppid, uid/*, 1*/);
>  }
>  #endif

In particular, the above is wrong.

Rich
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to