From c9a8da5bb8c78aba4b2477c011e2a4f335351fd8 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Mon, 16 Apr 2012 12:07:15 +0530 Subject: glusterd: Properly validate compressed form of IPv6 addresses Properly validate IPv6 compressed notation, when used in volume set. Change-Id: Ia489125a45472fc0971c6b11de073aaeb9b1a123 BUG: 810442 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.com/3152 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- libglusterfs/src/common-utils.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index c190049122c..cc73a8b7abb 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1699,11 +1699,30 @@ valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc) { int hex_numbers = 0; int value = 0; + int i = 0; char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL; char ret = 1; int is_wildcard = 0; + int is_compressed = 0; tmp = gf_strdup (address); + + /* Check for compressed form */ + if (tmp[length - 1] == ':') { + ret = 0; + goto out; + } + for (i = 0; i < (length - 1) ; i++) { + if (tmp[i] == ':' && tmp[i + 1] == ':') { + if (is_compressed == 0) + is_compressed = 1; + else { + ret = 0; + goto out; + } + } + } + prev = strtok_r (tmp, ":", &ptr); while (prev != NULL) { @@ -1721,7 +1740,8 @@ valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc) prev = strtok_r (NULL, ":", &ptr); } - if ((hex_numbers > 8) || (hex_numbers < 8 && !is_wildcard)) { + if ((hex_numbers > 8) || (hex_numbers < 8 && !is_wildcard + && !is_compressed)) { ret = 0; } -- cgit