added DNS spoofing test to host access control
[rsync/rsync.git] / flist.c
diff --git a/flist.c b/flist.c
index 4c2e984..d3c07ed 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -262,6 +262,12 @@ static void receive_file_entry(struct file_struct **fptr,
 
   clean_fname(thisname);
 
+  if (relative_paths && thisname[0] == '/') {
+         /* strip / off absolute paths in destination */
+         memmove(thisname, thisname+1, strlen(thisname));
+         if (!thisname[0]) strcpy(thisname,".");
+  }
+
   if ((p = strrchr(thisname,'/'))) {
          static char *lastdir;
          *p = 0;
@@ -521,7 +527,7 @@ static void send_directory(int f,struct file_list *flist,char *dir)
                        closedir(d);
                        return;
                }
-               strcat(fname,"/");
+               strlcat(fname,"/", MAXPATHLEN-1);
                l++;
        }
        p = fname + strlen(fname);
@@ -573,6 +579,10 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
                                                     flist->malloced);
        if (!flist->files) out_of_memory("send_file_list");
 
+       if (f != -1) {
+               io_start_buffering(f);
+       }
+
        for (i=0;i<argc;i++) {
                char fname2[MAXPATHLEN];
                char *fname = fname2;
@@ -581,7 +591,7 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
 
                l = strlen(fname);
                if (l != 1 && fname[l-1] == '/') {
-                       strcat(fname,".");
+                       strlcat(fname,".",MAXPATHLEN-1);
                }
 
                if (link_stat(fname,&st) != 0) {
@@ -612,7 +622,7 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
                           thus getting their permissions right */
                        *p = 0;
                        if (strcmp(lastpath,fname)) {
-                               strcpy(lastpath, fname);
+                               strlcpy(lastpath, fname, sizeof(lastpath)-1);
                                *p = '/';
                                for (p=fname+1; (p=strchr(p,'/')); p++) {
                                        *p = 0;
@@ -658,7 +668,6 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
 
        if (f != -1) {
                send_file_entry(NULL,f,0);
-               write_flush(f);
        }
 
        if (verbose && recurse && !am_server && f != -1)
@@ -677,6 +686,11 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
                write_int(f, io_error);
        }
 
+       if (f != -1) {
+               io_end_buffering(f);
+               write_flush(f);
+       }
+
        if (verbose > 2)
                rprintf(FINFO,"send_file_list done\n");
 
@@ -870,7 +884,7 @@ char *f_name(struct file_struct *f)
        n = (n+1)%10;
 
        if (f->dirname) {
-               sprintf(p, "%s/%s", f->dirname, f->basename);
+               slprintf(p, MAXPATHLEN-1, "%s/%s", f->dirname, f->basename);
        } else {
                strlcpy(p, f->basename, MAXPATHLEN-1);
        }