On entry, the *len_ptr parameter contains the size of the extra space we * should allocate when we create a buffer for the data. On exit, it contains * the length of the datum. */
| 185 | * should allocate when we create a buffer for the data. On exit, it contains |
| 186 | * the length of the datum. */ |
| 187 | static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr, int no_missing_error) |
| 188 | { |
| 189 | size_t datum_len = sys_lgetxattr(fname, name, NULL, 0); |
| 190 | size_t extra_len = *len_ptr; |
| 191 | char *ptr; |
| 192 | |
| 193 | *len_ptr = datum_len; |
| 194 | |
| 195 | if (datum_len == (size_t)-1) { |
| 196 | if (errno == ENOTSUP || no_missing_error) |
| 197 | return NULL; |
| 198 | rsyserr(FERROR_XFER, errno, |
| 199 | "get_xattr_data: lgetxattr(%s,\"%s\",0) failed", |
| 200 | full_fname(fname), name); |
| 201 | return NULL; |
| 202 | } |
| 203 | |
| 204 | if (!datum_len && !extra_len) |
| 205 | extra_len = 1; /* request non-zero amount of memory */ |
| 206 | if (SIZE_MAX - datum_len < extra_len) |
| 207 | overflow_exit("get_xattr_data"); |
| 208 | ptr = new_array(char, datum_len + extra_len); |
| 209 | |
| 210 | if (datum_len) { |
| 211 | size_t len = sys_lgetxattr(fname, name, ptr, datum_len); |
| 212 | if (len != datum_len) { |
| 213 | if (len == (size_t)-1) { |
| 214 | rsyserr(FERROR_XFER, errno, |
| 215 | "get_xattr_data: lgetxattr(%s,\"%s\",%ld) failed", |
| 216 | full_fname(fname), name, (long)datum_len); |
| 217 | } else { |
| 218 | rprintf(FERROR_XFER, |
| 219 | "get_xattr_data: lgetxattr(%s,\"%s\",%ld) returned %ld\n", |
| 220 | full_fname(fname), name, |
| 221 | (long)datum_len, (long)len); |
| 222 | } |
| 223 | free(ptr); |
| 224 | return NULL; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return ptr; |
| 229 | } |
| 230 | |
| 231 | static int rsync_xal_get(const char *fname, item_list *xalp) |
| 232 | { |
no test coverage detected