summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/dict.c
diff options
context:
space:
mode:
authorHarshavardhana <fharshav@redhat.com>2012-01-06 16:00:25 -0800
committerAnand Avati <avati@redhat.com>2012-03-18 02:20:28 -0700
commit65c6e3706f5290947179922c9e3b8f05ea6ae91c (patch)
tree26cd567a45b3f069db9b3edc39ca5f2d863c34d5 /libglusterfs/src/dict.c
parent5f59fbd81830a5f2157b3206d8413ba862aa5253 (diff)
libglusterfs/dict: Add boundary conditionsv3.3.0qa29
Functions modified: 1. data_to_int16() 2. data_to_uint16() Change-Id: I6775ca5d39f519c24ca3a07ce41018472e238cdf BUG: 769692 Signed-off-by: Harshavardhana <fharshav@redhat.com> Reviewed-on: http://review.gluster.com/2599 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@redhat.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src/dict.c')
-rw-r--r--libglusterfs/src/dict.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index a9d67ebc7ae..67bac435fa3 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -1085,6 +1085,8 @@ data_to_int32 (data_t *data)
int16_t
data_to_int16 (data_t *data)
{
+ int16_t value = 0;
+
if (!data) {
gf_log_callingfn ("dict", GF_LOG_WARNING, "data is NULL");
return -1;
@@ -1097,7 +1099,18 @@ data_to_int16 (data_t *data)
memcpy (str, data->data, data->len);
str[data->len] = '\0';
- return strtol (str, NULL, 0);
+ errno = 0;
+ value = strtol (str, NULL, 0);
+
+ if ((SHRT_MAX > value) || (SHRT_MIN < value)) {
+ errno = ERANGE;
+ gf_log_callingfn ("dict", GF_LOG_WARNING,
+ "Error in data conversion: "
+ "detected overflow");
+ return -1;
+ }
+
+ return (int16_t)value;
}
@@ -1124,7 +1137,8 @@ data_to_int8 (data_t *data)
if ((SCHAR_MAX > value) || (SCHAR_MIN < value)) {
errno = ERANGE;
gf_log_callingfn ("dict", GF_LOG_WARNING,
- "Error in data conversion: detected overflow");
+ "Error in data conversion: "
+ "detected overflow");
return -1;
}
@@ -1166,6 +1180,8 @@ data_to_uint32 (data_t *data)
uint16_t
data_to_uint16 (data_t *data)
{
+ uint16_t value = 0;
+
if (!data)
return -1;
@@ -1176,7 +1192,18 @@ data_to_uint16 (data_t *data)
memcpy (str, data->data, data->len);
str[data->len] = '\0';
- return strtol (str, NULL, 0);
+ errno = 0;
+ value = strtol (str, NULL, 0);
+
+ if ((USHRT_MAX - value) < 0) {
+ errno = ERANGE;
+ gf_log_callingfn ("dict", GF_LOG_WARNING,
+ "Error in data conversion: "
+ "overflow detected");
+ return -1;
+ }
+
+ return (uint16_t)value;
}
uint8_t