summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src/libglusterfsclient.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-06-20 11:58:07 +0200
committerAnand Avati <avati@redhat.com>2012-07-02 15:39:31 -0700
commitee3ed7c0bfcd340cd747a20812062925d5550d2a (patch)
treebd8b12d585bde8adf9465ab04e82641ba9401a5c /libglusterfsclient/src/libglusterfsclient.c
parentb535e4936d31e88595abc79a28ba87031aeccc4c (diff)
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 <meyering@redhat.com> Reviewed-on: http://review.gluster.com/3598 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfsclient/src/libglusterfsclient.c')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 39b5bea5068..b0ae61dad31 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] == '/') {