Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsrc: audit and fix shift-into-sign-bit bugs #34827
Open
Labels
Comments
|
Quick question, why can't
|
|
@juanarbol It's okay to rename and move that function to e.g. |
|
Ok, I'll be working on this. |
|
I don't find a way to inline static int8_t unbase64(uint8_t x);
// Send all this as a const unsigned char pointer
// Or convert all this elements into a const unsigned char pointer
unbase64(src[i + 0]);
unbase64(src[i + 1]);
unbase64(src[i + 2]);
unbase64(src[i + 3]);
// and send it to our beautiful method
cares_get_32bit(&mentioned_above_const_char); |
juanarbol
added a commit
to juanarbol/node
that referenced
this issue
Sep 9, 2020
Fixes: nodejs#34827
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The LHS here is usually of type
unsigned charbut gets promoted to int (because 24 is an int) and is then left-shifted.If the LHS >= 128, that ends up shifting into the sign bit and that's implementation-defined behavior (i.e., bad - although it probably works okay with most compilers.)
Replace
24with24uand all is good. But! It's probably best to abstract it away into a helper function.cares_wrap.cc already has one -
cares_get_32bit()- that handles it correctly.