On 7/16/06, Gustavo Rios <[EMAIL PROTECTED]> wrote:
...
static int
do_sid(const xlong f)
{
        int     r;

        if (r = 0, f & 1)
                if (f & 2) { if (apx_setsid() == -1) r = -1; }
                else r = apx_setpgid(0l, apx_getpid());

        return r;
}

Wow, what an annoying set of coding conventions you use.  The best
part is, the bug is in your use of one of them: use of unnamed bit
flags with particular flags being stored in _different_bits_ in
different parts of the code.  (i.e., the "do setsid()" flag is 4 in
main but 2 in the above.  Using the same values and defining symbolic
names would have kept this problem from occuring.   Not trying to be
too clever would have helped too.

So, please consider the above code and then think _really_ hard about
the code that determines the value of 'f' in that call:

...
                case 's' : f |= 2, f |= 4; break;
                case 'p' : f |= 2, f &= ~4; break;
...
                if (!r) r = do_sid(f & 6 >> 1);

That last line contains the bug, but the _source_ of the bug is either
the lack of symbolic constants or your decision to use bitflags at all
instead of just putting the flags in separate variables.


Philip Guenther

Reply via email to