added DNS spoofing test to host access control
[rsync/rsync.git] / util.c
diff --git a/util.c b/util.c
index d9c87ec..89bc75b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -558,10 +558,11 @@ static void glob_expand_one(char *s, char **argv, int *argc, int maxargs)
 #endif
 }
 
-void glob_expand(char *base, char **argv, int *argc, int maxargs)
+void glob_expand(char *base1, char **argv, int *argc, int maxargs)
 {
        char *s = argv[*argc];
        char *p, *q;
+       char *base = base1;
 
        if (!s || !*s) return;
 
@@ -572,21 +573,23 @@ void glob_expand(char *base, char **argv, int *argc, int maxargs)
        s = strdup(s);
        if (!s) out_of_memory("glob_expand");
 
+       base = (char *)malloc(strlen(base1)+3);
+       if (!base) out_of_memory("glob_expand");
+
+       sprintf(base," %s/", base1);
+
        q = s;
        while ((p = strstr(q,base)) && ((*argc) < maxargs)) {
-               if (p != q && *(p-1) == ' ' && p[strlen(base)] == '/') {
-                       /* split it at this point */
-                       *(p-1) = 0;
-                       glob_expand_one(q, argv, argc, maxargs);
-                       q = p+strlen(base)+1;
-               } else {
-                       q++;
-               }
+               /* split it at this point */
+               *p = 0;
+               glob_expand_one(q, argv, argc, maxargs);
+               q = p+strlen(base);
        }
 
        if (*q && (*argc < maxargs)) glob_expand_one(q, argv, argc, maxargs);
 
        free(s);
+       free(base);
 }
 
 /*******************************************************************
@@ -633,26 +636,19 @@ int vslprintf(char *str, int n, const char *format, va_list ap)
                buf = malloc(len);
                if (!buf) {
                        /* can't call debug or we would recurse */
-                       exit(1);
+                       exit_cleanup(1);
                }
        }
 
-       ret = vsprintf(buf, format, ap);
-
-       if (ret < 0) {
-               str[0] = 0;
-               return -1;
-       }
-
-       if (ret < n) {
-               n = ret;
-       } else if (ret > n) {
-               ret = -1;
+       vsprintf(buf, format, ap);
+       ret = strlen(buf);
+       if (ret > n) {
+               /* yikes! */
+               exit_cleanup(1);
        }
-
-       buf[n] = 0;
+       buf[ret] = 0;
        
-       memcpy(str, buf, n+1);
+       memcpy(str, buf, ret+1);
 
        return ret;
 #endif
@@ -670,3 +666,4 @@ int slprintf(char *str, int n, char *format, ...)
        va_end(ap);
        return ret;
 }
+