Avoid leaving a file open on error return.
[rsync.git] / receiver.c
index 3d9bc65f0238312df778e93ee08982b9aaf1cd9b..d6a48f14a66772eda9a3c15c349ccec7f641d6d2 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2003-2015 Wayne Davison
+ * Copyright (C) 2003-2018 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -236,7 +236,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
        static char file_sum1[MAX_DIGEST_LEN];
        struct map_struct *mapbuf;
        struct sum_struct sum;
-       int checksum_len;
+       int sum_len;
        int32 len;
        OFF_T offset = 0;
        OFF_T offset2;
@@ -388,15 +388,15 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
        if (INFO_GTE(PROGRESS, 1))
                end_progress(total_size);
 
-       checksum_len = sum_end(file_sum1);
+       sum_len = sum_end(file_sum1);
 
        if (mapbuf)
                unmap_file(mapbuf);
 
-       read_buf(f_in, sender_file_sum, checksum_len);
+       read_buf(f_in, sender_file_sum, sum_len);
        if (DEBUG_GTE(DELTASUM, 2))
                rprintf(FINFO,"got file_sum\n");
-       if (fd != -1 && memcmp(file_sum1, sender_file_sum, checksum_len) != 0)
+       if (fd != -1 && memcmp(file_sum1, sender_file_sum, sum_len) != 0)
                return 0;
        return 1;
 }
@@ -577,6 +577,12 @@ int recv_files(int f_in, int f_out, char *local_name)
                if (DEBUG_GTE(RECV, 1))
                        rprintf(FINFO, "recv_files(%s)\n", fname);
 
+               if (daemon_filter_list.head && (*fname != '.' || fname[1] != '\0')
+                && check_filter(&daemon_filter_list, FLOG, fname, 0) < 0) {
+                       rprintf(FERROR, "attempt to hack rsync failed.\n");
+                       exit_cleanup(RERR_PROTOCOL);
+               }
+
 #ifdef SUPPORT_XATTRS
                if (preserve_xattrs && iflags & ITEM_REPORT_XATTR && do_xfers
                 && !(want_xattr_optim && BITS_SET(iflags, ITEM_XNAME_FOLLOWS|ITEM_LOCAL_CHANGE)))
@@ -645,12 +651,6 @@ int recv_files(int f_in, int f_out, char *local_name)
 
                cleanup_got_literal = 0;
 
-               if (daemon_filter_list.head
-                   && check_filter(&daemon_filter_list, FLOG, fname, 0) < 0) {
-                       rprintf(FERROR, "attempt to hack rsync failed.\n");
-                       exit_cleanup(RERR_PROTOCOL);
-               }
-
                if (read_batch) {
                        int wanted = redoing
                                   ? we_want_redo(ndx)
@@ -722,7 +722,7 @@ int recv_files(int f_in, int f_out, char *local_name)
                                break;
                        }
                        if (!fnamecmp || (daemon_filter_list.head
-                         && check_filter(&daemon_filter_list, FLOG, fname, 0) < 0)) {
+                         && check_filter(&daemon_filter_list, FLOG, fnamecmp, 0) < 0)) {
                                fnamecmp = fname;
                                fnamecmp_type = FNAMECMP_FNAME;
                        }