diff options
-rw-r--r-- | libglusterfs/src/dict.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 2ad1ae1abff..833f117fc67 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -1104,6 +1104,8 @@ data_to_int16 (data_t *data) int8_t data_to_int8 (data_t *data) { + int32_t value = 0; + if (!data) { gf_log_callingfn ("dict", GF_LOG_WARNING, "data is NULL"); return -1; @@ -1116,7 +1118,17 @@ data_to_int8 (data_t *data) memcpy (str, data->data, data->len); str[data->len] = '\0'; - return (int8_t)strtol (str, NULL, 0); + errno = 0; + value = strtol (str, NULL, 0); + + if ((SCHAR_MAX > value) || (SCHAR_MIN < value)) { + errno = ERANGE; + gf_log_callingfn ("dict", GF_LOG_WARNING, + "Error in data conversion: detected overflow"); + return -1; + } + + return (int8_t)value; } @@ -1189,7 +1201,9 @@ data_to_uint8 (data_t *data) if ((UCHAR_MAX - value) < 0) { errno = ERANGE; - gf_log_callingfn ("dict", GF_LOG_WARNING, "data conversion overflow detected (%s)", strerror(errno)); + gf_log_callingfn ("dict", GF_LOG_WARNING, + "data conversion overflow detected (%s)", + strerror(errno)); return -1; } |