diff options
| author | Harshavardhana <fharshav@redhat.com> | 2012-01-03 11:07:00 -0800 | 
|---|---|---|
| committer | Vijay Bellur <vijay@gluster.com> | 2012-01-03 13:29:37 -0800 | 
| commit | 60862f5916dff99c91dd6d6319c958d02cb535d8 (patch) | |
| tree | 40d54f7f95523eb21606830babb3b1d5d9c74212 | |
| parent | a6777636fbb94a34a37cadd7840429f72fc5b747 (diff) | |
libglusterfs: Add boundary conditions to data_to_int8() function.
Change-Id: Iff50d44568895a75fc8743a10346990f764cf8fa
BUG: 769692
Signed-off-by: Harshavardhana <fharshav@redhat.com>
Reviewed-on: http://review.gluster.com/2556
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
| -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;  	}  | 
