summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-08-15 15:48:15 +0200
committerantirez <antirez@gmail.com>2014-08-27 10:29:53 +0200
commit5e707c66dd71f301081e6ee34a0050b78c228466 (patch)
treec52f5f1167b90cf889ea37d38c98a18351f2dded
parent65d47452f82721486bd79aafe6ca420ca6dedf8b (diff)
downloadredis-5e707c66dd71f301081e6ee34a0050b78c228466.tar.gz
Fix undefined behavior in ll2string().
The bug was found by @CAFxX, thanks! See issue #1940.
-rw-r--r--src/util.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util.c b/src/util.c
index a0bb2b84c..1b1798658 100644
--- a/src/util.c
+++ b/src/util.c
@@ -261,7 +261,11 @@ int ll2string(char* dst, size_t dstlen, long long svalue) {
/* The main loop works with 64bit unsigned integers for simplicity, so
* we convert the number here and remember if it is negative. */
if (svalue < 0) {
- value = -svalue;
+ if (svalue != LLONG_MIN) {
+ value = -svalue;
+ } else {
+ value = ((unsigned long long) LLONG_MAX)+1;
+ }
negative = 1;
} else {
value = svalue;