Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120613173248.GK17860@port70.net>
Date: Wed, 13 Jun 2012 19:32:48 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: FreeSec crypt()

* Solar Designer <solar@...nwall.com> [2012-06-13 20:45:46 +0400]:
> On Wed, Jun 13, 2012 at 10:56:03AM -0400, Rich Felker wrote:
> > Well if char is signed, (char)0x80 << 1 is -256. If char is unsigned,
> > (char)0x80 << 1 is 256.
> 
> Sure, but we had:
> 
> 	const char *key;
> 	u_char *q;
> 	*q++ = *key << 1;
> 
> so while *key << 1 is either -256 or 256 (promoted to int or unsigned
> int), those high bits get dropped on the assignment to *q anyway,
> resulting in the same value there either way.  No?

yes the code happens to work whenever -128<<1 is -256

and i assume -256 is what most compilers will give
usually in case of two's complement int representation

but -128<<1 is UB and should be fixed anyway

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.