You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.3 KiB

  1. From: Wayne Davison <wayned@samba.org>
  2. Date: Wed, 31 Dec 2014 20:41:03 +0000 (-0800)
  3. Subject: Complain if an inc-recursive path is not right for its dir.
  4. X-Git-Url: https://git.samba.org/?p=rsync.git;a=commitdiff_plain;h=962f8b90045ab331fc04c9e65f80f1a53e68243b
  5. Complain if an inc-recursive path is not right for its dir.
  6. This ensures that a malicious sender can't use a just-sent
  7. symlink as a trasnfer path.
  8. ---
  9. diff --git a/flist.c b/flist.c
  10. index c24672e..92e4b65 100644
  11. --- a/flist.c
  12. +++ b/flist.c
  13. @@ -2435,8 +2435,9 @@ struct file_list *send_file_list(int f, int argc, char *argv[])
  14. return flist;
  15. }
  16. -struct file_list *recv_file_list(int f)
  17. +struct file_list *recv_file_list(int f, int dir_ndx)
  18. {
  19. + const char *good_dirname = NULL;
  20. struct file_list *flist;
  21. int dstart, flags;
  22. int64 start_read;
  23. @@ -2492,6 +2493,23 @@ struct file_list *recv_file_list(int f)
  24. flist_expand(flist, 1);
  25. file = recv_file_entry(f, flist, flags);
  26. + if (inc_recurse) {
  27. + static const char empty_dir[] = "\0";
  28. + const char *cur_dir = file->dirname ? file->dirname : empty_dir;
  29. + if (relative_paths && *cur_dir == '/')
  30. + cur_dir++;
  31. + if (cur_dir != good_dirname) {
  32. + const char *d = dir_ndx >= 0 ? f_name(dir_flist->files[dir_ndx], NULL) : empty_dir;
  33. + if (strcmp(cur_dir, d) != 0) {
  34. + rprintf(FERROR,
  35. + "ABORTING due to invalid dir prefix from sender: %s (should be: %s)\n",
  36. + cur_dir, d);
  37. + exit_cleanup(RERR_PROTOCOL);
  38. + }
  39. + good_dirname = cur_dir;
  40. + }
  41. + }
  42. +
  43. if (S_ISREG(file->mode)) {
  44. /* Already counted */
  45. } else if (S_ISDIR(file->mode)) {
  46. @@ -2615,7 +2633,7 @@ void recv_additional_file_list(int f)
  47. rprintf(FINFO, "[%s] receiving flist for dir %d\n",
  48. who_am_i(), ndx);
  49. }
  50. - flist = recv_file_list(f);
  51. + flist = recv_file_list(f, ndx);
  52. flist->parent_ndx = ndx;
  53. }
  54. }
  55. diff --git a/io.c b/io.c
  56. index b9a9bd0..a868fa9 100644
  57. --- a/io.c
  58. +++ b/io.c
  59. @@ -1685,7 +1685,7 @@ void wait_for_receiver(void)
  60. rprintf(FINFO, "[%s] receiving flist for dir %d\n",
  61. who_am_i(), ndx);
  62. }
  63. - flist = recv_file_list(iobuf.in_fd);
  64. + flist = recv_file_list(iobuf.in_fd, ndx);
  65. flist->parent_ndx = ndx;
  66. #ifdef SUPPORT_HARD_LINKS
  67. if (preserve_hard_links)
  68. diff --git a/main.c b/main.c
  69. index e7a13f7..713b818 100644
  70. --- a/main.c
  71. +++ b/main.c
  72. @@ -1009,7 +1009,7 @@ static void do_server_recv(int f_in, int f_out, int argc, char *argv[])
  73. filesfrom_fd = -1;
  74. }
  75. - flist = recv_file_list(f_in);
  76. + flist = recv_file_list(f_in, -1);
  77. if (!flist) {
  78. rprintf(FERROR,"server_recv: recv_file_list error\n");
  79. exit_cleanup(RERR_FILESELECT);
  80. @@ -1183,7 +1183,7 @@ int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
  81. if (write_batch && !am_server)
  82. start_write_batch(f_in);
  83. - flist = recv_file_list(f_in);
  84. + flist = recv_file_list(f_in, -1);
  85. if (inc_recurse && file_total == 1)
  86. recv_additional_file_list(f_in);
  87. diff --git a/rsync.c b/rsync.c
  88. index 68ff6b1..c3ecc51 100644
  89. --- a/rsync.c
  90. +++ b/rsync.c
  91. @@ -364,7 +364,7 @@ int read_ndx_and_attrs(int f_in, int f_out, int *iflag_ptr, uchar *type_ptr,
  92. }
  93. /* Send all the data we read for this flist to the generator. */
  94. start_flist_forward(ndx);
  95. - flist = recv_file_list(f_in);
  96. + flist = recv_file_list(f_in, ndx);
  97. flist->parent_ndx = ndx;
  98. stop_flist_forward();
  99. }