Subject: Re: bin/34578 (iscsi_target rejects Windows iscsi initiator.)
To: None <netbsd-bugs@NetBSD.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 11/27/2006 07:47:03
Alan Barrett wrote:
> On Mon, 27 Nov 2006, nakamoto wrote:
> >  As the original problem was shifting only 31 bits when the mask is
> >  "0.0.0.0/0", the reproduction of the bug depends on MSB ( or LSB ) of
> >  the initiator's address.
> >  I tested the initiator with "192.168.x..x" ( MSB is set) and your IP
> >  address is "10.x.x.x" ( MSB is not set ).
> 
> I don't know exactly where this code is, but the symptoms suggest that
> it's using the << operator with a signed 32-bit value on the left
> hand side, and 32 on the right hand side.  The C standard does not
> guarantee the results of such an operation.  See revision 1.105 of
> sbin/route/route.c for a fix to a similar issue.

I think this would have been the better fix:

static inline uint32_t
u32_shift_left(uint32_t v, unsigned n)
{
	return n < 32 ? v << n : 0;
}

You can obviously use a macro to generate them for each intN.

-- 
Christian