Re: is size correct in ecryptfs_parse_packet_length()

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

 



On Tue, Oct 21, 2014 at 05:29:53PM -0400, Tyler Hicks wrote:
> >    101          if (data[0] < 192) {
> >    102                  /* One-byte length */
> >    103                  (*size) = (unsigned char)data[0];
> >    104                  (*length_size) = 1;
> >    105          } else if (data[0] < 224) {
> >    106                  /* Two-byte length */
> >    107                  (*size) = (((unsigned char)(data[0]) - 192) * 256);
> >                                     ^^^^^^^^^^^^^^^
> >    108                  (*size) += ((unsigned char)(data[1]) + 192);
> >                                     ^^^^^^^^^^^^^^^
> > These casts are no-ops because they are "data" is an unsigned char
> > pointer already.  Then the value is type promoted to int, we subtract
> > 192 giving a negative number and we multiply by 256 giving a slightly
> > larger negative then we save it as a very large positive.
> 
> Subtracting 192 from data[0] should never result in a negative number.
> We know that data[0] is greater than or equal to 192 (and less than 224)
> because the previous conditional was false.
> 

Oh right.  Duh...  Thanks.

We could remove the casting though because it's a no-op?

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe ecryptfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Crypto]     [Device Mapper Crypto]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux