Unverified Commit e1dc9790 authored by Binbin's avatar Binbin Committed by GitHub
Browse files

sds.c: Fix potential overflow in sdsll2str. (#8910)

Fixes an undefined behavior, same way as our `ll2string` does.
parent 563ba7a3
...@@ -553,7 +553,17 @@ int sdsll2str(char *s, long long value) { ...@@ -553,7 +553,17 @@ int sdsll2str(char *s, long long value) {
/* Generate the string representation, this method produces /* Generate the string representation, this method produces
* a reversed string. */ * a reversed string. */
v = (value < 0) ? -value : value; if (value < 0) {
/* Since v is unsigned, if value==LLONG_MIN, -LLONG_MIN will overflow. */
if (value != LLONG_MIN) {
v = -value;
} else {
v = ((unsigned long long)LLONG_MAX) + 1;
}
} else {
v = value;
}
p = s; p = s;
do { do {
*p++ = '0'+(v%10); *p++ = '0'+(v%10);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment