diff options
author | Jay Satiro <raysatiro@yahoo.com> | 2017-05-29 18:04:53 -0400 |
---|---|---|
committer | Jay Satiro <raysatiro@yahoo.com> | 2017-05-29 18:04:53 -0400 |
commit | 35682764a9dc7eb0fed3fbb1c0074f1c34dd60b2 (patch) | |
tree | 4f0152ff992851b056d4fdac88f1338a8f85590f | |
parent | 35e9281ef8ac394b7d718cf6bd65bdc2ff8047b0 (diff) |
test557: fix ubsan runtime error due to int left shift
- Test curl_msnprintf negative int width arg using INT_MIN instead of
1 << 31 which is undefined behavior.
Closes https://github.com/curl/curl/issues/1516
-rw-r--r-- | tests/libtest/lib557.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index ca3118aec..4a598f22d 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -27,6 +27,10 @@ #include "test.h" +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif + #ifdef HAVE_LOCALE_H # include <locale.h> /* for setlocale() */ #endif @@ -1621,8 +1625,8 @@ static int test_float_formatting(void) 123456789123456789123456789.2987654); errors += strlen_check(buf, 325); - /* 1<<31 turns negative (-2147483648) when used signed */ - curl_msnprintf(buf, sizeof(buf), "%*f", (1<<31), 9.1); + /* check negative when used signed */ + curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1); errors += string_check(buf, "9.100000"); /* curl_msnprintf() limits a single float output to 325 bytes maximum |