diff --git a/contrib/libarchive/libarchive/archive_write_disk_posix.c b/contrib/libarchive/libarchive/archive_write_disk_posix.c index bbd50a637648..9d94de1046f6 100644 --- a/contrib/libarchive/libarchive/archive_write_disk_posix.c +++ b/contrib/libarchive/libarchive/archive_write_disk_posix.c @@ -3707,7 +3707,7 @@ set_xattrs(struct archive_write_disk *a) size_t size; archive_entry_xattr_next(entry, &name, &value, &size); if (name != NULL) { - int e; + ssize_t e; int namespace; if (strncmp(name, "user.", 5) == 0) { @@ -3734,7 +3734,7 @@ set_xattrs(struct archive_write_disk *a) e = extattr_set_file(archive_entry_pathname(entry), namespace, name, value, size); } - if (e != (int)size) { + if (e != (ssize_t)size) { if (errno == ENOTSUP || errno == ENOSYS) { if (!warning_done) { warning_done = 1; diff --git a/contrib/libarchive/libarchive/test/test_extattr_freebsd.c b/contrib/libarchive/libarchive/test/test_extattr_freebsd.c index de74b1408dd6..f1fe53442262 100644 --- a/contrib/libarchive/libarchive/test/test_extattr_freebsd.c +++ b/contrib/libarchive/libarchive/test/test_extattr_freebsd.c @@ -47,7 +47,8 @@ DEFINE_TEST(test_extattr_freebsd) struct stat st; struct archive *a; struct archive_entry *ae; - int n, fd; + ssize_t n; + int fd; int extattr_privilege_bug = 0; /* diff --git a/lib/libc/sys/extattr_get_file.2 b/lib/libc/sys/extattr_get_file.2 index e8faa136aff2..db4ea92fd59f 100644 --- a/lib/libc/sys/extattr_get_file.2 +++ b/lib/libc/sys/extattr_get_file.2 @@ -50,7 +50,7 @@ .In sys/extattr.h .Ft ssize_t .Fn extattr_get_fd "int fd" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes" -.Ft int +.Ft ssize_t .Fn extattr_set_fd "int fd" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes" .Ft int .Fn extattr_delete_fd "int fd" "int attrnamespace" "const char *attrname" @@ -58,7 +58,7 @@ .Fn extattr_list_fd "int fd" "int attrnamespace" "void *data" "size_t nbytes" .Ft ssize_t .Fn extattr_get_file "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes" -.Ft int +.Ft ssize_t .Fn extattr_set_file "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes" .Ft int .Fn extattr_delete_file "const char *path" "int attrnamespace" "const char *attrname" @@ -66,7 +66,7 @@ .Fn extattr_list_file "const char *path" "int attrnamespace" "void *data" "size_t nbytes" .Ft ssize_t .Fn extattr_get_link "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes" -.Ft int +.Ft ssize_t .Fn extattr_set_link "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes" .Ft int .Fn extattr_delete_link "const char *path" "int attrnamespace" "const char *attrname" diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/syscalls.master index b798d8c1d842..0a40ab231ea3 100644 --- a/sys/compat/freebsd32/syscalls.master +++ b/sys/compat/freebsd32/syscalls.master @@ -634,7 +634,7 @@ 355 AUE_EXTATTRCTL NOPROTO { int extattrctl(const char *path, int cmd, \ const char *filename, int attrnamespace, \ const char *attrname); } -356 AUE_EXTATTR_SET_FILE NOPROTO { int extattr_set_file( \ +356 AUE_EXTATTR_SET_FILE NOPROTO { ssize_t extattr_set_file( \ const char *path, int attrnamespace, \ const char *attrname, void *data, \ size_t nbytes); } @@ -665,7 +665,7 @@ 368 AUE_NULL UNIMPL __cap_set_fd 369 AUE_NULL UNIMPL __cap_set_file 370 AUE_NULL UNIMPL nosys -371 AUE_EXTATTR_SET_FD NOPROTO { int extattr_set_fd(int fd, \ +371 AUE_EXTATTR_SET_FD NOPROTO { ssize_t extattr_set_fd(int fd, \ int attrnamespace, const char *attrname, \ void *data, size_t nbytes); } 372 AUE_EXTATTR_GET_FD NOPROTO { ssize_t extattr_get_fd(int fd, \ @@ -726,7 +726,7 @@ 409 AUE_NULL UNIMPL __mac_get_pid 410 AUE_NULL UNIMPL __mac_get_link 411 AUE_NULL UNIMPL __mac_set_link -412 AUE_EXTATTR_SET_LINK NOPROTO { int extattr_set_link( \ +412 AUE_EXTATTR_SET_LINK NOPROTO { ssize_t extattr_set_link( \ const char *path, int attrnamespace, \ const char *attrname, void *data, \ size_t nbytes); } diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index cf4138ab8f16..4b3348f83e31 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -632,7 +632,7 @@ 355 AUE_EXTATTRCTL STD { int extattrctl(const char *path, int cmd, \ const char *filename, int attrnamespace, \ const char *attrname); } -356 AUE_EXTATTR_SET_FILE STD { int extattr_set_file( \ +356 AUE_EXTATTR_SET_FILE STD { ssize_t extattr_set_file( \ const char *path, int attrnamespace, \ const char *attrname, void *data, \ size_t nbytes); } @@ -662,7 +662,7 @@ 368 AUE_NULL UNIMPL __cap_set_fd 369 AUE_NULL UNIMPL __cap_set_file 370 AUE_NULL UNIMPL nosys -371 AUE_EXTATTR_SET_FD STD { int extattr_set_fd(int fd, \ +371 AUE_EXTATTR_SET_FD STD { ssize_t extattr_set_fd(int fd, \ int attrnamespace, const char *attrname, \ void *data, size_t nbytes); } 372 AUE_EXTATTR_GET_FD STD { ssize_t extattr_get_fd(int fd, \ @@ -731,7 +731,7 @@ struct mac *mac_p); } 411 AUE_NULL STD { int __mac_set_link(const char *path_p, \ struct mac *mac_p); } -412 AUE_EXTATTR_SET_LINK STD { int extattr_set_link( \ +412 AUE_EXTATTR_SET_LINK STD { ssize_t extattr_set_link( \ const char *path, int attrnamespace, \ const char *attrname, void *data, \ size_t nbytes); } diff --git a/sys/sys/extattr.h b/sys/sys/extattr.h index 6e8b73541a6a..ce5619bef162 100644 --- a/sys/sys/extattr.h +++ b/sys/sys/extattr.h @@ -92,11 +92,11 @@ ssize_t extattr_list_file(const char *_path, int _attrnamespace, void *_data, size_t _nbytes); ssize_t extattr_list_link(const char *_path, int _attrnamespace, void *_data, size_t _nbytes); -int extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname, +ssize_t extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname, const void *_data, size_t _nbytes); -int extattr_set_file(const char *_path, int _attrnamespace, +ssize_t extattr_set_file(const char *_path, int _attrnamespace, const char *_attrname, const void *_data, size_t _nbytes); -int extattr_set_link(const char *_path, int _attrnamespace, +ssize_t extattr_set_link(const char *_path, int _attrnamespace, const char *_attrname, const void *_data, size_t _nbytes); __END_DECLS diff --git a/usr.sbin/extattr/rmextattr.c b/usr.sbin/extattr/rmextattr.c index cab6c7f37554..c061943db651 100644 --- a/usr.sbin/extattr/rmextattr.c +++ b/usr.sbin/extattr/rmextattr.c @@ -102,6 +102,8 @@ main(int argc, char *argv[]) char *buf, *visbuf, *p; const char *options, *attrname; + size_t len; + ssize_t ret; int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace, minargc; @@ -200,80 +202,84 @@ main(int argc, char *argv[]) continue; break; case EASET: + len = strlen(buf) + flag_null; if (flag_nofollow) - error = extattr_set_link(argv[arg_counter], - attrnamespace, attrname, buf, - strlen(buf) + flag_null); + ret = extattr_set_link(argv[arg_counter], + attrnamespace, attrname, buf, len); else - error = extattr_set_file(argv[arg_counter], - attrnamespace, attrname, buf, - strlen(buf) + flag_null); - if (error >= 0) + ret = extattr_set_file(argv[arg_counter], + attrnamespace, attrname, buf, len); + if (ret >= 0) { + if ((size_t)ret != len && !flag_quiet) { + warnx("Set %zd bytes of %zu for %s", + ret, len, attrname); + } continue; + } break; case EALS: if (flag_nofollow) - error = extattr_list_link(argv[arg_counter], + ret = extattr_list_link(argv[arg_counter], attrnamespace, NULL, 0); else - error = extattr_list_file(argv[arg_counter], + ret = extattr_list_file(argv[arg_counter], attrnamespace, NULL, 0); - if (error < 0) + if (ret < 0) break; - mkbuf(&buf, &buflen, error); + mkbuf(&buf, &buflen, ret); if (flag_nofollow) - error = extattr_list_link(argv[arg_counter], + ret = extattr_list_link(argv[arg_counter], attrnamespace, buf, buflen); else - error = extattr_list_file(argv[arg_counter], + ret = extattr_list_file(argv[arg_counter], attrnamespace, buf, buflen); - if (error < 0) + if (ret < 0) break; if (!flag_quiet) printf("%s\t", argv[arg_counter]); - for (i = 0; i < error; i += ch + 1) { + for (i = 0; i < ret; i += ch + 1) { /* The attribute name length is unsigned. */ ch = (unsigned char)buf[i]; printf("%s%*.*s", i ? "\t" : "", ch, ch, buf + i + 1); } - if (!flag_quiet || error > 0) + if (!flag_quiet || ret > 0) printf("\n"); continue; case EAGET: if (flag_nofollow) - error = extattr_get_link(argv[arg_counter], + ret = extattr_get_link(argv[arg_counter], attrnamespace, attrname, NULL, 0); else - error = extattr_get_file(argv[arg_counter], + ret = extattr_get_file(argv[arg_counter], attrnamespace, attrname, NULL, 0); - if (error < 0) + if (ret < 0) break; - mkbuf(&buf, &buflen, error); + mkbuf(&buf, &buflen, ret); if (flag_nofollow) - error = extattr_get_link(argv[arg_counter], + ret = extattr_get_link(argv[arg_counter], attrnamespace, attrname, buf, buflen); else - error = extattr_get_file(argv[arg_counter], + ret = extattr_get_file(argv[arg_counter], attrnamespace, attrname, buf, buflen); - if (error < 0) + if (ret < 0) break; if (!flag_quiet) printf("%s\t", argv[arg_counter]); if (flag_string) { - mkbuf(&visbuf, &visbuflen, error * 4 + 1); - strvisx(visbuf, buf, error, + mkbuf(&visbuf, &visbuflen, ret * 4 + 1); + strvisx(visbuf, buf, ret, VIS_SAFE | VIS_WHITE); printf("\"%s\"\n", visbuf); continue; } else if (flag_hex) { - for (i = 0; i < error; i++) + for (i = 0; i < ret; i++) printf("%s%02x", i ? " " : "", buf[i]); printf("\n"); continue; } else { - fwrite(buf, error, 1, stdout); + fwrite(buf, ret, 1, stdout); printf("\n"); continue; }