FreeBSD Security Advisory FreeBSD-SA-05:01.telnet

Jacques A. Vidrine nectar at FreeBSD.org
Fri Apr 1 06:18:39 PST 2005


On Fri, Apr 01, 2005 at 09:29:48AM +0200, Roberto wrote:
> Actually I've not read the code, 

Then why are you posting your opinion about it?  (^_^)

I guess I'm responding to your post only to prevent others from worrying
about a non-existent ``problem''.

> but from these email it seems to me that
> someone could be confused by this code (at least Steve and I); for example
> refer to the address "&slc_reply[128];" when slc_reply[127] is the last
> element.

There is no reference to ``&slc_reply[128]''.  There *is* a pointer
initialized to the equivalent expression
``&slc_reply[sizeof(slc_reply)]'', which is the usual way to designate
the end of a sequence.  For example, 

   char buf[...];
   const char *eom = &buf[sizeof(buf)];

   while (p < eom) /* `*p' is valid */;
   size_t n = eom - p;  /* There are `n' bytes left */

If we used a pointer to the last element (instead of one beyond the last
element), we'd need to adjust many expressions by 1, which is
error-prone and ugly.

> I do not want to be offensive in any way, what I want to say is that this
> code is clear to you (and the person who wrote it) but the next programmer
> that will reuse the code (because this is a open source) could make a
> mistake.
> 
> I think many bugs can derive from code not easy to understand.
> 
> This is only my opinion.

I find the tests fairly idiomatic and I find it easy to see their
correctness.  I doubt I'm alone.  The suggested fix was reviewed by a
number of coders from several open source operating system projects and
caused no confusion.  The form was chosen to clearly show how many bytes
were expected to be written at that point.  IMHO, using alternative
forms invites off-by-one errors.

       if (&slc_replyp[6+2] > slc_reply_eom)
               return;
       /* past this point, we can write 6+2 bytes, slc_replyp[0]
        * through slc_replyp[7].
	*/

Cheers,
-- 
Jacques A Vidrine / NTT/Verio
nectar at celabo.org / jvidrine at verio.net / nectar at FreeBSD.org



More information about the freebsd-security mailing list