From 295c0280d117cfca85f354d8098ea72c30ef2ced Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 20 Jun 2012 13:45:46 +0200 Subject: valid_ipv4_address: don't access addr[-1] for 0-length input string valid_ipv6_address: Likewise. Change-Id: I6225873a5e323f81de5f25335aceeee571629e28 BUG: 789278 Signed-off-by: Jim Meyering Reviewed-on: http://review.gluster.com/3602 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/common-utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libglusterfs/src/common-utils.c') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 82a493669..671a3e549 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1703,7 +1703,8 @@ valid_ipv4_address (char *address, int length, gf_boolean_t wildcard_acc) tmp = gf_strdup (address); /* To prevent cases where last character is '.' */ - if (!isdigit (tmp[length - 1]) && (tmp[length - 1] != '*')) { + if (length <= 0 || + (!isdigit (tmp[length - 1]) && (tmp[length - 1] != '*'))) { ret = 0; goto out; } @@ -1749,7 +1750,7 @@ valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc) tmp = gf_strdup (address); /* Check for compressed form */ - if (tmp[length - 1] == ':') { + if (length <= 0 || tmp[length - 1] == ':') { ret = 0; goto out; } -- cgit