r2361: Fix the appalling toktocliplist() fn. Bug found by Luis Benvenutto.
authorJeremy Allison <jra@samba.org>
Wed, 15 Sep 2004 22:49:23 +0000 (22:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:40 +0000 (10:52 -0500)
Jeremy.

source/client/clitar.c
source/lib/util_str.c

index 64c194b54dae7d91997e3fcd7b985083c2bcdbee..4cadef558d61ccc6c75a93279b1fc03718737155 100644 (file)
@@ -1345,8 +1345,9 @@ Principal command for creating / extracting
 int cmd_tar(void)
 {
        fstring buf;
-       char **argl;
-       int argcl;
+       char **argl = NULL;
+       int argcl = 0;
+       int ret;
 
        if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
                DEBUG(0,("tar <c|x>[IXbgan] <filename>\n"));
@@ -1357,8 +1358,9 @@ int cmd_tar(void)
        if (!tar_parseargs(argcl, argl, buf, 0))
                return 1;
 
+       ret = process_tar();
        SAFE_FREE(argl);
-       return process_tar();
+       return ret;
 }
 
 /****************************************************************************
index 6eee62c14aa70af86e212f031f589f7a83c55d73..65a616ad4198851b8168b6b5f8840747e3e4130a 100644 (file)
@@ -134,17 +134,20 @@ char **toktocliplist(int *ctok, const char *sep)
        *ctok=ictok;
        s=(char *)last_ptr;
        
-       if (!(ret=iret=malloc(ictok*sizeof(char *))))
+       if (!(ret=iret=malloc((ictok+1)*sizeof(char *))))
                return NULL;
        
        while(ictok--) {    
                *iret++=s;
-               while(*s++)
-                       ;
-               while(!*s)
-                       s++;
+               if (ictok > 0) {
+                       while(*s++)
+                               ;
+                       while(!*s)
+                               s++;
+               }
        }
 
+       ret[*ctok] = NULL;
        return ret;
 }