[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] libfsimage: zfs build fix



Mark Johnson writes ("Re: [Xen-devel] [PATCH] libfsimage: zfs build fix"):
> On Thu, Apr 15, 2010 at 10:10 AM, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> 
> wrote:
> > The ctype problems are more than warnings - they would give undefined
> > behaviour if high-bit-set characters are passed.
> 
> I didn't write that code and agree that it's pretty ugly :-).
> I assume you talking about where the char is sign extended
> or not? Just curious, what's the case that isspace() gives
> a wrong answer here?

Yes.

If you have high bit set characters then chars are negative.  isspace
et al take an int which was converted from an unsigned char, and it is
not permitted to pass negative numbers to them (except EOF).

So
   char *some_string;
   ...
   if (isspace(some_string[14])) {...
is wrong because if some_string[14] is a character >127 (say, 169
which is ISO-LATIN-15 for COPYRIGHT SIGH), then isspace is passed
a negative integer (-87).

If you pass a negative number (other than EOF) to isspace, your
program may crash or access random data.

Therefore EVERY call to isspace needs to be written like this
   if (isspace((unsigned char)some_string[14])) {...

This is of course a design error in the C library.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.