You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
src: audit and fix shift-into-sign-bit bugs #34827
The LHS here is usually of type unsigned char but 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 24 with 24u and 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.
inlinestaticint8_tunbase64(uint8_t x);
// Send all this as a const unsigned char pointer// Or convert all this elements into a const unsigned char pointerunbase64(src[i + 0]);
unbase64(src[i + 1]);
unbase64(src[i + 2]);
unbase64(src[i + 3]);
// and send it to our beautiful methodcares_get_32bit(&mentioned_above_const_char);
Activity
Replace 24 with 24U, git grep -n '<< 24' src/, nodejs#34827
juanarbol commentedon Aug 24, 2020
Quick question, why can't
cares_get_32bit()be used or considered as that helper (like here)? That function could work withbnoordhuis commentedon Aug 24, 2020
@juanarbol It's okay to rename and move that function to e.g.
src/util.h.juanarbol commentedon Aug 24, 2020
Ok, I'll be working on this.
juanarbol commentedon Aug 25, 2020
I don't find a way to
src: create helper for reading Uint32BE
src: create helper for reading Uint32BE
src: create helper for reading Uint32BE
src: create helper for reading Uint32BE
src: create helper for reading Uint32BE
src: create helper for reading Uint32BE