From e2216fbc37831f76039cae77bf724550827daa0f Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Thu, 19 Apr 2012 13:17:49 +0530 Subject: cli: Strip whitespace from "volume set" option values Strips the whitespace from options values before sending to glusterd. This prevents options containing whitespace to be written to the volfiles which would cause the volfile parser to fail. Change-Id: I46faee7b0853141fa102d06bb067c7ab499a2f6e BUG: 813937 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.com/3192 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Vijay Bellur --- cli/src/cli-cmd-parser.c | 4 ++++ libglusterfs/src/common-utils.c | 31 +++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 1 + 3 files changed, 36 insertions(+) diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 2aba56b9b..aef13a77d 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -688,6 +688,10 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) count++; + ret = gf_strip_whitespace (value, strlen (value)); + if (ret == -1) + goto out; + sprintf (str, "key%d", count); ret = dict_set_str (dict, str, key); if (ret) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index cc73a8b7a..0e133c005 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -2024,3 +2024,34 @@ gf_client_pid_check (gf_client_pid_t npid) return ( (npid > GF_CLIENT_PID_MIN) && (npid < GF_CLIENT_PID_MAX) ) ? 0 : -1; } + +/* Strips all whitespace characters in a string and returns length of new string + * on success + */ +int +gf_strip_whitespace (char *str, int len) +{ + int i = 0; + int new_len = 0; + char *new_str = NULL; + + GF_ASSERT (str); + + new_str = GF_CALLOC (1, len + 1, gf_common_mt_char); + if (new_str == NULL) + return -1; + + for (i = 0; i < len; i++) { + if (!isspace (str[i])) + new_str[new_len++] = str[i]; + } + new_str[new_len] = '\0'; + + if (new_len != len) { + memset (str, 0, len); + strncpy (str, new_str, new_len); + } + + GF_FREE (new_str); + return new_len; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 86f1b051f..7e6da9ed2 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -494,4 +494,5 @@ char *get_path_name (char *word, char **path); void gf_path_strip_trailing_slashes (char *path); uint64_t get_mem_size (); int gf_client_pid_check (gf_client_pid_t npid); +int gf_strip_whitespace (char *str, int len); #endif /* _COMMON_UTILS_H */ -- cgit