changed an example slightly
[rsync/rsync.git] / receiver.c
index 376c3fc..9701303 100644 (file)
@@ -163,7 +163,7 @@ static int get_tmpname(char *fnametmp, char *fname)
                        rprintf(FERROR,"filename too long\n");
                        return 0;
                }
-               slprintf(fnametmp,MAXPATHLEN-1, "%s/.%s.XXXXXX",tmpdir,f);
+               slprintf(fnametmp,MAXPATHLEN, "%s/.%s.XXXXXX",tmpdir,f);
                return 1;
        } 
 
@@ -176,11 +176,11 @@ static int get_tmpname(char *fnametmp, char *fname)
 
        if (f) {
                *f = 0;
-               slprintf(fnametmp,MAXPATHLEN-1,"%s/.%s.XXXXXX",
+               slprintf(fnametmp,MAXPATHLEN,"%s/.%s.XXXXXX",
                         fname,f+1);
                *f = '/';
        } else {
-               slprintf(fnametmp,MAXPATHLEN-1,".%s.XXXXXX",fname);
+               slprintf(fnametmp,MAXPATHLEN,".%s.XXXXXX",fname);
        }
 
        return 1;
@@ -223,7 +223,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
 
                        if (fd != -1 && write_file(fd,data,i) != i) {
                                rprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
-                               exit_cleanup(1);
+                               exit_cleanup(RERR_FILEIO);
                        }
                        offset += i;
                        continue;
@@ -249,7 +249,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
                if (fd != -1 && write_file(fd,map,len) != len) {
                        rprintf(FERROR,"write failed on %s : %s\n",
                                fname,strerror(errno));
-                       exit_cleanup(1);
+                       exit_cleanup(RERR_FILEIO);
                }
                offset += len;
        }
@@ -259,7 +259,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
        if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
                rprintf(FERROR,"write failed on %s : %s\n",
                        fname,strerror(errno));
-               exit_cleanup(1);
+               exit_cleanup(RERR_FILEIO);
        }
 
        sum_end(file_sum1);
@@ -322,7 +322,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
                if (i < 0 || i >= flist->count) {
                        rprintf(FERROR,"Invalid file index %d in recv_files (count=%d)\n", 
                                i, flist->count);
-                       exit_cleanup(1);
+                       exit_cleanup(RERR_PROTOCOL);
                }
 
                file = flist->files[i];
@@ -353,7 +353,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
 
                if ((fd1 == -1) && (compare_dest != NULL)) {
                        /* try the file at compare_dest instead */
-                       slprintf(fnamecmpbuf,MAXPATHLEN-1,"%s/%s",
+                       slprintf(fnamecmpbuf,MAXPATHLEN,"%s/%s",
                                                compare_dest,fname);
                        fnamecmp = fnamecmpbuf;
                        fd1 = open(fnamecmp,O_RDONLY);
@@ -387,6 +387,10 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
                        continue;
                }
 
+               /* mktemp is deliberately used here instead of mkstemp.
+                  because O_EXCL is used on the open, the race condition
+                  is not a problem or a security hole, and we want to
+                  control the access permissions on the created file. */
                if (NULL == do_mktemp(fnametmp)) {
                        rprintf(FERROR,"mktemp %s failed\n",fnametmp);
                        receive_data(f_in,buf,-1,NULL,file->length);