Message buffer and printf reentrancy patch

Ian Dowse iedowse at maths.tcd.ie
Tue Jun 17 17:22:45 PDT 2003


In message <200306170410.h5H4AXM7050537 at gw.catspoiler.org>, Don Lewis writes:
>Since MSGBUF_SEQSUB() calls MSGBUF_SEQNORM() on the difference between
>the sequence numbers, a negative value will never be returned.  If you
>want a signed result, you'll probably want to do something more like:
>	tmp = MSGBUF_SEQNORM(mbp, (seq1) - (seq2) + (mbp)->seqmod);
>	return (tmp < ((mbp)->seqmod / 2)) ? tmp : (tmp - (mbp)->seqmod));
>
>and you'll have to use a slightly different function if you are
>comparing indexes.

Oops, you're quite right - MSGBUF_SEQSUB was intended to return
negative values, but got broken somewhere along the way. This appears
not to affect the code that uses it, so I guess that means that the
sequence numbers might as well be unsigned after all.

>> The only minor problem I see with the above is that it is fragile
>> with respect to arbitrary input sequence numbers, in that it could
>> return a negative value. However, the property of guaranteeing to
>> return a normalised sequence number can be achieved by forcing an
>> unsigned division like in MSGBUF_SEQ_TO_POS, i.e.:
>
>Wouldn't it be better to have assertions to detect obviously bogus
>sequence numbers rather than using them to generate a valid pointer to a
>random location in the message buffer?

It would if the assertion didn't trigger a panic that gets written
to the message buffer via the same macros :-)

Ian




More information about the freebsd-arch mailing list