diff options
| author | Raghavendra G <raghavendra@gluster.com> | 2009-09-01 00:34:02 +0000 | 
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2009-09-08 03:22:57 -0700 | 
| commit | 6f1a9007f4876d46bd2d67e67312c24771d82bf5 (patch) | |
| tree | a684ba46e04ba30d4e2303e2a36a96a4a9f40e34 | |
| parent | 8d696f317ef06e045de380d4408b814a3214ced7 (diff) | |
libglusterfsclient: handle paths terminating with '/' properly in libgf_trim_to_prev_dir.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
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
| -rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 8 | 
1 files changed, 7 insertions, 1 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 02328388d..e2c2f10b8 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;  | 
