Fixed crash bug that can affect --delete in certain circumstances.
[rsync/rsync.git] / flist.c
diff --git a/flist.c b/flist.c
index bd7ad16..7c39e53 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -542,6 +542,9 @@ void receive_file_entry(struct file_struct **fptr, unsigned short flags,
                return;
        }
 
+       if (!flist || !flist->count)    /* Ignore lastdir when invalid. */
+               lastdir_len = -1;
+
        if (flags & XMIT_SAME_NAME)
                l1 = read_byte(f);
 
@@ -745,7 +748,7 @@ struct file_struct *make_file(char *fname,
        char *basename, *dirname, *bp;
        unsigned short flags = 0;
 
-       if (!flist)     /* lastdir isn't valid if flist is NULL */
+       if (!flist || !flist->count)    /* Ignore lastdir when invalid. */
                lastdir_len = -1;
 
        if (strlcpy(thisname, fname, sizeof thisname)
@@ -989,7 +992,7 @@ static void send_directory(int f, struct file_list *flist, char *dir)
                if (strlcpy(p, ".cvsignore", MAXPATHLEN - offset)
                    < MAXPATHLEN - offset) {
                        add_exclude_file(&local_exclude_list, fname,
-                                        XFLG_WORD_SPLIT | XFLG_NO_PREFIXES);
+                                        XFLG_WORD_SPLIT | XFLG_WORDS_ONLY);
                } else {
                        io_error |= IOERR_GENERAL;
                        rprintf(FINFO,
@@ -1517,11 +1520,17 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
        if (!(c1 = (uchar*)f1->dirname)) {
                state1 = fnc_BASE;
                c1 = (uchar*)f1->basename;
+       } else if (!*c1) {
+               state1 = fnc_SLASH;
+               c1 = (uchar*)"/";
        } else
                state1 = fnc_DIR;
        if (!(c2 = (uchar*)f2->dirname)) {
                state2 = fnc_BASE;
                c2 = (uchar*)f2->basename;
+       } else if (!*c2) {
+               state2 = fnc_SLASH;
+               c2 = (uchar*)"/";
        } else
                state2 = fnc_DIR;