From c0c54cd9feeff6093c78027fade26379838e9899 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Tue, 1 Sep 2009 00:32:40 +0000 Subject: libglusterfsclient: handle paths terminating with '/' properly in libgf_trim_to_prev_dir. Signed-off-by: Anand V. Avati BUG: 236 (Stack overflow due to infinite recursion in glusterfs_glh_realpath) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=236 --- libglusterfsclient/src/libglusterfsclient.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libglusterfsclient') diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index f3a7e3a0dec..58a8017d347 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -709,6 +709,7 @@ char * libgf_trim_to_prev_dir (char * path) { char *idx = NULL; + int len = 0; if (!path) return NULL; @@ -716,9 +717,14 @@ libgf_trim_to_prev_dir (char * path) /* Check if we're already at root, if yes * then there is no prev dir. */ - if (strlen (path) == 1) + len = strlen (path); + if (len == 1) return path; + if (path[len - 1] == '/') { + path[len - 1] = '\0'; + } + idx = libgf_rrindex (path, '/', 1); /* Move to the char after the / */ ++idx; -- cgit