receive and build the rsync_xattr_lists */
| 769 | |
| 770 | /* receive and build the rsync_xattr_lists */ |
| 771 | void receive_xattr(int f, struct file_struct *file) |
| 772 | { |
| 773 | static item_list temp_xattr = EMPTY_ITEM_LIST; |
| 774 | int count, num; |
| 775 | #ifdef HAVE_LINUX_XATTRS |
| 776 | int need_sort = 0; |
| 777 | #else |
| 778 | int need_sort = 1; |
| 779 | #endif |
| 780 | int ndx = read_varint(f); |
| 781 | |
| 782 | if (ndx < 0 || (size_t)ndx > rsync_xal_l.count) { |
| 783 | rprintf(FERROR, "receive_xattr: xa index %d out of" |
| 784 | " range for %s\n", ndx, f_name(file, NULL)); |
| 785 | exit_cleanup(RERR_STREAMIO); |
| 786 | } |
| 787 | |
| 788 | if (ndx != 0) { |
| 789 | F_XATTR(file) = ndx - 1; |
| 790 | return; |
| 791 | } |
| 792 | |
| 793 | count = read_varint_bounded(f, 0, MAX_WIRE_XATTR_COUNT, "xattr count"); |
| 794 | if (count != 0) { |
| 795 | (void)EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count); |
| 796 | temp_xattr.count = 0; |
| 797 | } |
| 798 | |
| 799 | for (num = 1; num <= count; num++) { |
| 800 | char *ptr, *name; |
| 801 | rsync_xa *rxa; |
| 802 | size_t name_len = read_varint_size(f, MAX_WIRE_XATTR_NAMELEN, "xattr name_len"); |
| 803 | size_t datum_len = read_varint_size(f, MAX_WIRE_XATTR_DATALEN, "xattr datum_len"); |
| 804 | size_t dget_len = datum_len > MAX_FULL_DATUM ? 1 + (size_t)xattr_sum_len : datum_len; |
| 805 | size_t extra_len = MIGHT_NEED_RPRE ? RPRE_LEN : 0; |
| 806 | if (SIZE_MAX - dget_len < extra_len || SIZE_MAX - dget_len - extra_len < name_len) |
| 807 | overflow_exit("receive_xattr"); |
| 808 | ptr = new_array(char, dget_len + extra_len + name_len); |
| 809 | name = ptr + dget_len + extra_len; |
| 810 | read_buf(f, name, name_len); |
| 811 | if (name_len < 1 || name[name_len-1] != '\0') { |
| 812 | rprintf(FERROR, "Invalid xattr name received (missing trailing \\0).\n"); |
| 813 | exit_cleanup(RERR_FILEIO); |
| 814 | } |
| 815 | if (dget_len == datum_len) |
| 816 | read_buf(f, ptr, dget_len); |
| 817 | else { |
| 818 | *ptr = XSTATE_ABBREV; |
| 819 | read_buf(f, ptr + 1, xattr_sum_len); |
| 820 | } |
| 821 | |
| 822 | if (saw_xattr_filter) { |
| 823 | if (name_is_excluded(name, NAME_IS_XATTR, ALL_FILTERS)) { |
| 824 | free(ptr); |
| 825 | continue; |
| 826 | } |
| 827 | } |
| 828 | #ifdef HAVE_LINUX_XATTRS |
no test coverage detected