Commit 68ddbaf6 authored by Wayne Davison's avatar Wayne Davison

Fixed a bug with truncated xattr data requests when the receiver

needs to discard some of the items from the sender's list.
parent 555a081f
...@@ -70,6 +70,7 @@ extern int checksum_seed; ...@@ -70,6 +70,7 @@ extern int checksum_seed;
typedef struct { typedef struct {
char *datum, *name; char *datum, *name;
size_t datum_len, name_len; size_t datum_len, name_len;
int num;
} rsync_xa; } rsync_xa;
static size_t namebuf_len = 0; static size_t namebuf_len = 0;
...@@ -210,14 +211,14 @@ static int rsync_xal_get(const char *fname, item_list *xalp) ...@@ -210,14 +211,14 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
#ifdef HAVE_LINUX_XATTRS #ifdef HAVE_LINUX_XATTRS
int user_only = am_sender ? 0 : !am_root; int user_only = am_sender ? 0 : !am_root;
#endif #endif
rsync_xa *rxa;
int count;
/* This puts the name list into the "namebuf" buffer. */ /* This puts the name list into the "namebuf" buffer. */
if ((list_len = get_xattr_names(fname)) < 0) if ((list_len = get_xattr_names(fname)) < 0)
return -1; return -1;
for (name = namebuf; list_len > 0; name += name_len) { for (name = namebuf; list_len > 0; name += name_len) {
rsync_xa *rxa;
name_len = strlen(name) + 1; name_len = strlen(name) + 1;
list_len -= name_len; list_len -= name_len;
...@@ -270,8 +271,12 @@ static int rsync_xal_get(const char *fname, item_list *xalp) ...@@ -270,8 +271,12 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
rxa->name_len = name_len; rxa->name_len = name_len;
rxa->datum_len = datum_len; rxa->datum_len = datum_len;
} }
if (xalp->count > 1) count = xalp->count;
qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names); rxa = xalp->items;
if (count > 1)
qsort(rxa, count, sizeof (rsync_xa), rsync_xal_compare_names);
for (rxa += count-1; count; count--, rxa--)
rxa->num = count;
return 0; return 0;
} }
...@@ -459,12 +464,11 @@ int xattr_diff(struct file_struct *file, stat_x *sxp, int find_all) ...@@ -459,12 +464,11 @@ int xattr_diff(struct file_struct *file, stat_x *sxp, int find_all)
void send_xattr_request(const char *fname, struct file_struct *file, int f_out) void send_xattr_request(const char *fname, struct file_struct *file, int f_out)
{ {
item_list *lst = rsync_xal_l.items; item_list *lst = rsync_xal_l.items;
int j, cnt, prior_req = -1; int cnt, prior_req = 0;
rsync_xa *rxa; rsync_xa *rxa;
lst += F_XATTR(file); lst += F_XATTR(file);
cnt = lst->count; for (rxa = lst->items, cnt = lst->count; cnt--; rxa++) {
for (rxa = lst->items, j = 0; j < cnt; rxa++, j++) {
if (rxa->datum_len <= MAX_FULL_DATUM) if (rxa->datum_len <= MAX_FULL_DATUM)
continue; continue;
switch (rxa->datum[0]) { switch (rxa->datum[0]) {
...@@ -481,8 +485,8 @@ void send_xattr_request(const char *fname, struct file_struct *file, int f_out) ...@@ -481,8 +485,8 @@ void send_xattr_request(const char *fname, struct file_struct *file, int f_out)
/* Flag that we handled this abbreviated item. */ /* Flag that we handled this abbreviated item. */
rxa->datum[0] = XSTATE_DONE; rxa->datum[0] = XSTATE_DONE;
write_varint(f_out, j - prior_req); write_varint(f_out, rxa->num - prior_req);
prior_req = j; prior_req = rxa->num;
if (fname) { if (fname) {
size_t len = 0; size_t len = 0;
...@@ -534,7 +538,7 @@ int recv_xattr_request(struct file_struct *file, int f_in) ...@@ -534,7 +538,7 @@ int recv_xattr_request(struct file_struct *file, int f_in)
item_list *lst = rsync_xal_l.items; item_list *lst = rsync_xal_l.items;
char *old_datum, *name; char *old_datum, *name;
rsync_xa *rxa; rsync_xa *rxa;
int rel_pos, cnt, got_xattr_data = 0; int rel_pos, cnt, num, got_xattr_data = 0;
if (F_XATTR(file) < 0) { if (F_XATTR(file) < 0) {
rprintf(FERROR, "recv_xattr_request: internal data error!\n"); rprintf(FERROR, "recv_xattr_request: internal data error!\n");
...@@ -544,13 +548,20 @@ int recv_xattr_request(struct file_struct *file, int f_in) ...@@ -544,13 +548,20 @@ int recv_xattr_request(struct file_struct *file, int f_in)
cnt = lst->count; cnt = lst->count;
rxa = lst->items; rxa = lst->items;
rxa -= 1; num = 0;
while ((rel_pos = read_varint(f_in)) != 0) { while ((rel_pos = read_varint(f_in)) != 0) {
rxa += rel_pos; num += rel_pos;
cnt -= rel_pos; while (cnt && rxa->num < num) {
if (cnt < 0 || rxa->datum_len <= MAX_FULL_DATUM rxa++;
|| rxa->datum[0] != XSTATE_ABBREV) { cnt--;
rprintf(FERROR, "recv_xattr_request: internal abbrev error!\n"); }
if (!cnt || rxa->num != num) {
rprintf(FERROR, "[%s] could not find xattr #%d for %s\n",
who_am_i(), num, f_name(file, NULL));
exit_cleanup(RERR_STREAMIO);
}
if (rxa->datum_len <= MAX_FULL_DATUM || rxa->datum[0] != XSTATE_ABBREV) {
rprintf(FERROR, "[%s] internal abbrev error!\n", who_am_i());
exit_cleanup(RERR_STREAMIO); exit_cleanup(RERR_STREAMIO);
} }
...@@ -584,7 +595,7 @@ int recv_xattr_request(struct file_struct *file, int f_in) ...@@ -584,7 +595,7 @@ int recv_xattr_request(struct file_struct *file, int f_in)
void receive_xattr(struct file_struct *file, int f) void receive_xattr(struct file_struct *file, int f)
{ {
static item_list temp_xattr = EMPTY_ITEM_LIST; static item_list temp_xattr = EMPTY_ITEM_LIST;
int count; int count, num;
int ndx = read_varint(f); int ndx = read_varint(f);
if (ndx < 0 || (size_t)ndx > rsync_xal_l.count) { if (ndx < 0 || (size_t)ndx > rsync_xal_l.count) {
...@@ -603,7 +614,7 @@ void receive_xattr(struct file_struct *file, int f) ...@@ -603,7 +614,7 @@ void receive_xattr(struct file_struct *file, int f)
temp_xattr.count = 0; temp_xattr.count = 0;
} }
while (count--) { for (num = 1; num <= count; num++) {
char *ptr, *name; char *ptr, *name;
rsync_xa *rxa; rsync_xa *rxa;
size_t name_len = read_varint(f); size_t name_len = read_varint(f);
...@@ -627,14 +638,14 @@ void receive_xattr(struct file_struct *file, int f) ...@@ -627,14 +638,14 @@ void receive_xattr(struct file_struct *file, int f)
} }
#ifdef HAVE_LINUX_XATTRS #ifdef HAVE_LINUX_XATTRS
/* Non-root can only save the user namespace. */ /* Non-root can only save the user namespace. */
if (am_root <= 0 && !HAS_PREFIX(name, USER_PREFIX)) { if (am_root <= 0 && !HAS_PREFIX(name, USER_PREFIX)) {
if (!am_root) { if (!am_root) {
free(ptr); free(ptr);
continue; continue;
} }
name -= RPRE_LEN; name -= RPRE_LEN;
name_len += RPRE_LEN; name_len += RPRE_LEN;
memcpy(name, RSYNC_PREFIX, RPRE_LEN); memcpy(name, RSYNC_PREFIX, RPRE_LEN);
} }
#else #else
/* This OS only has a user namespace, so we either /* This OS only has a user namespace, so we either
...@@ -663,6 +674,7 @@ void receive_xattr(struct file_struct *file, int f) ...@@ -663,6 +674,7 @@ void receive_xattr(struct file_struct *file, int f)
rxa->datum = ptr; rxa->datum = ptr;
rxa->name_len = name_len; rxa->name_len = name_len;
rxa->datum_len = datum_len; rxa->datum_len = datum_len;
rxa->num = num;
} }
ndx = rsync_xal_l.count; /* pre-incremented count */ ndx = rsync_xal_l.count; /* pre-incremented count */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment