From ee3ed7c0bfcd340cd747a20812062925d5550d2a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 20 Jun 2012 11:58:07 +0200 Subject: libgf_rrindex: don't return &str[-1] for an empty string input libgf_trim_to_prev_dir: handle empty path (i.e., don't access path[-1]) libgf_alloc_fd_ctx: assert that vpath is not empty Change-Id: I8f9d233680f78107187132889916cdcf4262af72 BUG: 789278 Signed-off-by: Jim Meyering Reviewed-on: http://review.gluster.com/3598 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfsclient/src/libglusterfsclient.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libglusterfsclient') diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 39b5bea50..b0ae61dad 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -214,6 +214,7 @@ libgf_alloc_fd_ctx (libglusterfs_client_ctx_t *ctx, fd_t *fd, char *vpath) if (vpath != NULL) { strcpy (fdctx->vpath, vpath); + assert (strlen(vpath) > 0); if (vpath[strlen(vpath) - 1] != '/') { strcat (fdctx->vpath, "/"); } @@ -743,7 +744,7 @@ xlator_graph_fini (xlator_t *xl) char * libgf_rrindex (char *str, int c, int n) { - int len = 0; + size_t len; int occurrence = 0; if (str == NULL) @@ -751,7 +752,8 @@ libgf_rrindex (char *str, int c, int n) len = strlen (str); /* Point to last character of string. */ - str += (len - 1); + if (len) + str += (len - 1); while (len > 0) { if ((int)*str == c) { ++occurrence; @@ -778,7 +780,7 @@ libgf_trim_to_prev_dir (char * path) * then there is no prev dir. */ len = strlen (path); - if (len == 1) + if (len <= 1) return path; if (path[len - 1] == '/') { -- cgit