[BusyBox] Bug in pidof !

Steven Scholz steven.scholz at imc-berlin.de
Sun Nov 24 07:11:05 UTC 2002


Hi there,

I think there is a bug in the pidof applet in busybox-unstable-20021123
resulting in "Segmentation fault" when using pidof without "-s".

~ # pidof -s inetd
37

~ # pidof inetd   
37
Segmentation fault

Have a look at this (procps/pidof.c):

-------------------------------------------------------------------------------
    /* Looks like everything is set to go. */
    while(optind < argc) {
        long* pidList;

        pidList = find_pid_by_name(argv[optind]);
        for(; *pidList > 0; pidList++) {
            printf("%s%ld", (n++ ? " " : ""), (long)*pidList);
            fail = 0;
            if (single_flag)
                break;
        }
        free(pidList);
        optind++;
    }
-------------------------------------------------------------------------------
Obviously pidList gets incremented when single_flag is FALSE. So free(pidList)
frees the wrong pointer!

0.60.5 is working ok since there's no free(). Source says:

        /* Note that we don't bother to free the memory
         * allocated in find_pid_by_name().  It will be freed
         * upon exit, so we can save a byte or two */

So what's the solution!? Who introduced the free()?

Thanks,

Steven



More information about the busybox mailing list