diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2020-02-05 12:38:17 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2020-02-05 12:38:17 +0000 |
commit | 0efa232c593d8fe393b56fb1ff4dda751660b3b3 (patch) | |
tree | b037fe733cd026b5cefb5b27d7f3f6cbc8f4c3ac | |
parent | 86b01acdc561eb9c47f9d9e8c33b2d15e064aed7 (diff) | |
parent | 7484d76e78bc19298de9589214be103d65cf3989 (diff) | |
download | illumos-joyent-0efa232c593d8fe393b56fb1ff4dda751660b3b3.tar.gz |
[illumos-gate merge]
commit 7484d76e78bc19298de9589214be103d65cf3989
12263 libc: NULL pointer errors (sparc)
commit b36afad7ffe84071c2c6831936cc1c524bd1ca90
12216 Clean up libc-tests smatch
commit 69c811ab73b7ce531454837ae68c4343e8724e0b
9965 Want support for O_DIRECTORY
commit 2fe8bc68ec8e8e8e05997b3ac2f081bfdded45ab
12275 check_rtime(1onbld): BUNDEF_OBJ and BUNUSED_OBJ
commit 5fe3b0929d8a195dbfa4196d72a3f9b15b745171
12084 idm_conn_event_handler mishandles CA_DROP action
Conflicts:
usr/src/test/os-tests/tests/Makefile
27 files changed, 448 insertions, 84 deletions
diff --git a/usr/src/cmd/mandoc/config.h b/usr/src/cmd/mandoc/config.h index 3ae0245c08..e4bc9a6a3b 100644 --- a/usr/src/cmd/mandoc/config.h +++ b/usr/src/cmd/mandoc/config.h @@ -3,12 +3,21 @@ #include <sys/types.h> +/* + * The tools build may be on a system without O_DIRECTORY. So we need to + * explicitly include sys/fcntl.h and check for O_DIRECTORY and if not present, + * use the default of it being zero. + */ +#include <sys/fcntl.h> +#ifndef O_DIRECTORY +#define O_DIRECTORY 0 +#endif + #define MAN_CONF_FILE "/etc/man.conf" #define MANPATH_BASE "/usr/share/man" #define MANPATH_DEFAULT "/usr/share/man:/usr/gnu/share/man" #define UTF8_LOCALE "en_US.UTF-8" #define EFTYPE EINVAL -#define O_DIRECTORY 0 #define HAVE_CMSG_XPG42 0 #define HAVE_DIRENT_NAMLEN 0 #define HAVE_ENDIAN 1 diff --git a/usr/src/cmd/truss/codes.c b/usr/src/cmd/truss/codes.c index de04009d59..88c67ea994 100644 --- a/usr/src/cmd/truss/codes.c +++ b/usr/src/cmd/truss/codes.c @@ -1962,7 +1962,7 @@ pathconfname(int code) #define ALL_O_FLAGS \ (O_NDELAY|O_APPEND|O_SYNC|O_DSYNC|O_NONBLOCK|O_CREAT|O_TRUNC\ |O_EXCL|O_NOCTTY|O_LARGEFILE|O_RSYNC|O_XATTR|O_NOFOLLOW|O_NOLINKS\ - |O_CLOEXEC|FXATTRDIROPEN) + |O_CLOEXEC|O_DIRECTORY|FXATTRDIROPEN) const char * openarg(private_t *pri, int arg) @@ -2022,6 +2022,8 @@ openarg(private_t *pri, int arg) (void) strlcat(str, "|O_NOLINKS", sizeof (pri->code_buf)); if (arg & O_CLOEXEC) (void) strlcat(str, "|O_CLOEXEC", sizeof (pri->code_buf)); + if (arg & O_DIRECTORY) + (void) strlcat(str, "|O_DIRECTORY", sizeof (pri->code_buf)); if (arg & FXATTRDIROPEN) (void) strlcat(str, "|FXATTRDIROPEN", sizeof (pri->code_buf)); diff --git a/usr/src/lib/libc/port/gen/walkstack.c b/usr/src/lib/libc/port/gen/walkstack.c index 02afc8f214..85963f53ab 100644 --- a/usr/src/lib/libc/port/gen/walkstack.c +++ b/usr/src/lib/libc/port/gen/walkstack.c @@ -192,9 +192,9 @@ walkcontext(const ucontext_t *uptr, int (*operate_func)(uintptr_t, int, void *), ucontext_t *oldctx = uptr->uc_link; int fd; - int sig; + int sig; #if defined(__sparc) - int signo = 0; + int signo = 0; #endif struct frame *savefp; @@ -227,7 +227,7 @@ walkcontext(const ucontext_t *uptr, int (*operate_func)(uintptr_t, int, void *), */ #if defined(__sparc) - uintptr_t special_pc = NULL; + uintptr_t special_pc = (uintptr_t)NULL; int special_size = 0; extern void thr_sighndlrinfo(void (**func)(), int *funcsize); @@ -415,8 +415,8 @@ callback(uintptr_t pc, int signo, void *arg) int backtrace(void **buffer, int count) { - backtrace_t bt; - ucontext_t u; + backtrace_t bt; + ucontext_t u; bt.bt_buffer = buffer; bt.bt_maxcount = count; diff --git a/usr/src/lib/libc/sparc/threads/machdep.c b/usr/src/lib/libc/sparc/threads/machdep.c index 85cf4facf9..12487363cb 100644 --- a/usr/src/lib/libc/sparc/threads/machdep.c +++ b/usr/src/lib/libc/sparc/threads/machdep.c @@ -61,7 +61,7 @@ setup_top_frame(void *stk, size_t stksize, ulwp_t *ulwp) int setup_context(ucontext_t *ucp, void *(*func)(ulwp_t *), - ulwp_t *ulwp, caddr_t stk, size_t stksize) + ulwp_t *ulwp, caddr_t stk, size_t stksize) { uintptr_t stack; @@ -72,7 +72,8 @@ setup_context(ucontext_t *ucp, void *(*func)(ulwp_t *), * Clear the top stack frame. * If this fails, pass the problem up to the application. */ - if ((stack = (uintptr_t)setup_top_frame(stk, stksize, ulwp)) == NULL) + stack = (uintptr_t)setup_top_frame(stk, stksize, ulwp); + if (stack == (uintptr_t)NULL) return (ENOMEM); /* fill in registers of interest */ diff --git a/usr/src/man/man2/open.2 b/usr/src/man/man2/open.2 index 3ad37a86c7..86e00e575a 100644 --- a/usr/src/man/man2/open.2 +++ b/usr/src/man/man2/open.2 @@ -47,7 +47,7 @@ .\" All Rights Reserved. .\" Copyright 2015 Nexenta Systems, Inc. All rights reserved. .\" -.TH OPEN 2 "Feb 14, 2015" +.TH OPEN 2 "Jan 20, 2020" .SH NAME open, openat \- open a file .SH SYNOPSIS @@ -176,6 +176,37 @@ whether the file is open for reading, writing or for both. .sp .ne 2 .na +.B O_DIRECTORY +.ad +.sp .6 +.RS 4n +Indicates that attempts to open +.I path +should fail unless +.I path +is a directory. +If both +.B O_CREAT +and +.B O_DIRECTORY +are specified then the call will fail if it would result in a file being +created. +If a directory already exists at +.I path +then it will behave as if the +.B O_DIRECTORY +flag had not been present. +If the +.B O_EXCL +and +.B O_CREAT +flags are specified, then the call will always fail as they imply a file +should always be created. +.RE + +.sp +.ne 2 +.na \fB\fBO_DSYNC\fR\fR .ad .sp .6 @@ -686,6 +717,14 @@ The maximum allowable number of files is currently open in the system. The \fBO_CREAT\fR flag is not set and the named file does not exist; or the \fBO_CREAT\fR flag is set and either the path prefix does not exist or the \fIpath\fR argument points to an empty string. +.sp +The +.B O_CREAT +and +.B O_DIRECTORY +flags were both set and +.I path +did not point to a file. .RE .sp @@ -747,6 +786,10 @@ A component of the path prefix is not a directory or a relative path was supplied to \fBopenat()\fR, the \fBO_XATTR\fR flag was not supplied, and the file descriptor does not refer to a directory. The \fBO_SEARCH\fR flag was passed and \fIpath\fR does not refer to a directory. +.sp +The +.B O_DIRECTORY +flag was set and the file was not a directory. .RE .sp diff --git a/usr/src/man/man3head/fcntl.h.3head b/usr/src/man/man3head/fcntl.h.3head index fa75967763..3e272db601 100644 --- a/usr/src/man/man3head/fcntl.h.3head +++ b/usr/src/man/man3head/fcntl.h.3head @@ -43,7 +43,7 @@ .\" Copyright 1989 AT&T .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. .\" -.TH FCNTL.H 3HEAD "April 9, 2016" +.TH FCNTL.H 3HEAD "January 20, 2020" .SH NAME fcntl.h, fcntl \- file control options .SH SYNOPSIS @@ -374,6 +374,15 @@ Create file if it does not exist. .sp .ne 2 .na +.B O_DIRECTORY +.ad +.RS 12n +Fail unless the path is a directory. +.RE + +.sp +.ne 2 +.na \fB\fBO_EXCL\fR\fR .ad .RS 12n @@ -426,6 +435,15 @@ Set append mode. .sp .ne 2 .na +.B O_CLOEXEC +.ad +.RS 12n +The file should be closed on any calls to \fBexec\fR(2). +.RE + +.sp +.ne 2 +.na \fB\fBO_NDELAY\fR\fR .ad .RS 14n diff --git a/usr/src/pkg/manifests/system-test-ostest.mf b/usr/src/pkg/manifests/system-test-ostest.mf index 5567b6db89..2c0f8e39bf 100644 --- a/usr/src/pkg/manifests/system-test-ostest.mf +++ b/usr/src/pkg/manifests/system-test-ostest.mf @@ -51,6 +51,8 @@ file path=opt/os-tests/tests/file-locking/runtests.64 mode=0555 $(i386_ONLY)file path=opt/os-tests/tests/i386/badseg mode=0555 $(i386_ONLY)file path=opt/os-tests/tests/i386/badseg_exec mode=0555 $(i386_ONLY)file path=opt/os-tests/tests/i386/ldt mode=0555 +file path=opt/os-tests/tests/odirectory.32 mode=0555 +file path=opt/os-tests/tests/odirectory.64 mode=0555 file path=opt/os-tests/tests/pf_key/acquire-compare mode=0555 file path=opt/os-tests/tests/pf_key/acquire-spray mode=0555 file path=opt/os-tests/tests/pf_key/eacq-enabler mode=0555 diff --git a/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg b/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg index 92806885bc..0a359e92ce 100644 --- a/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg +++ b/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg @@ -42,6 +42,7 @@ value | O_RDWR | int | fcntl.h | POSIX+ SUS+ value | O_RSYNC | int | fcntl.h | XPG3+ POSIX-1993+ value | O_SYNC | int | fcntl.h | XPG3+ POSIX-1993+ value | O_WRONLY | int | fcntl.h | POSIX+ SUS+ +value | O_DIRECTORY | int | fcntl.h | -ALL SUSv4+ # # Functions diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index 3342c04bc6..093f42ebc8 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -58,9 +58,6 @@ SCRIPTS = \ CPPFLAGS += -D_REENTRANT -# needs work -SMOFF += all_func_returns,snprintf_overflow,unreachable - PROGS32 = $(PROGS:%=%.32) PROGS64 = \ $(PROGS:%=%.64) \ diff --git a/usr/src/test/libc-tests/tests/c11_threads.c b/usr/src/test/libc-tests/tests/c11_threads.c index 4504a9c262..2c7185ce47 100644 --- a/usr/src/test/libc-tests/tests/c11_threads.c +++ b/usr/src/test/libc-tests/tests/c11_threads.c @@ -51,10 +51,10 @@ static int cthr_test_sleep_thr(void *arg) { for (;;) { - sleep(1000); + (void) sleep(1000); } - abort(); + return (0); } static void diff --git a/usr/src/test/libc-tests/tests/call_once.c b/usr/src/test/libc-tests/tests/call_once.c index 8c10420bcd..17a7dcd98a 100644 --- a/usr/src/test/libc-tests/tests/call_once.c +++ b/usr/src/test/libc-tests/tests/call_once.c @@ -42,8 +42,9 @@ static int co_thr(void *arg) { VERIFY3S(mtx_lock(&co_mtx), ==, thrd_success); - while (co_go == B_FALSE) - cnd_wait(&co_cnd, &co_mtx); + while (co_go == B_FALSE) { + (void) cnd_wait(&co_cnd, &co_mtx); + } VERIFY3S(mtx_unlock(&co_mtx), ==, thrd_success); call_once(&co_once, co_once_func); return (0); diff --git a/usr/src/test/libc-tests/tests/fnmatch.c b/usr/src/test/libc-tests/tests/fnmatch.c index ca42d9e904..503ae78d32 100644 --- a/usr/src/test/libc-tests/tests/fnmatch.c +++ b/usr/src/test/libc-tests/tests/fnmatch.c @@ -208,7 +208,7 @@ flags_to_string(int flags) if (p == result) memcpy(p, "0", 2); else if (flags != 0) - sprintf(p, "%d", flags); + (void) sprintf(p, "%d", flags); else *p = '\0'; return (result); diff --git a/usr/src/test/libc-tests/tests/memset_s.c b/usr/src/test/libc-tests/tests/memset_s.c index eb44230d60..e02fef20b2 100644 --- a/usr/src/test/libc-tests/tests/memset_s.c +++ b/usr/src/test/libc-tests/tests/memset_s.c @@ -46,33 +46,33 @@ main(void) char b[3]; /* null ptr */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); assert(memset_s(0, 1, 1, 1) != 0); /* smax > rmax */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); assert(memset_s(&b, RSIZE_MAX + 1, 1, 1) != 0); /* smax < 0 */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); assert(memset_s(&a, -1, 1, 1) != 0); /* normal */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); a = 3; assert(memset_s(&a, 1, 5, 1) == 0); assert(a == 5); /* n > rmax */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); assert(memset_s(&a, 1, 1, RSIZE_MAX + 1) != 0); /* n < 0 */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); assert(memset_s(&a, 1, 1, -1) != 0); /* n < smax */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); b[0] = 1; b[1] = 2; b[2] = 3; assert(memset_s(&b[0], 3, 9, 1) == 0); assert(b[0] == 9); @@ -80,7 +80,7 @@ main(void) assert(b[2] == 3); /* n > smax, handler */ - set_constraint_handler_s(h); + (void) set_constraint_handler_s(h); e = 0; m = NULL; b[0] = 1; b[1] = 2; b[2] = 3; @@ -92,7 +92,7 @@ main(void) assert(b[2] == 3); /* smax > rmax, handler */ - set_constraint_handler_s(h); + (void) set_constraint_handler_s(h); e = 0; m = NULL; assert(memset_s(&a, RSIZE_MAX + 1, 1, 1) != 0); @@ -100,7 +100,7 @@ main(void) assert(strcmp(m, "memset_s: smax > RSIZE_MAX") == 0); /* smax < 0, handler */ - set_constraint_handler_s(h); + (void) set_constraint_handler_s(h); e = 0; m = NULL; assert(memset_s(&a, -1, 1, 1) != 0); @@ -108,7 +108,7 @@ main(void) assert(strcmp(m, "memset_s: smax > RSIZE_MAX") == 0); /* n > rmax, handler */ - set_constraint_handler_s(h); + (void) set_constraint_handler_s(h); e = 0; m = NULL; assert(memset_s(&a, 1, 1, RSIZE_MAX + 1) != 0); @@ -116,7 +116,7 @@ main(void) assert(strcmp(m, "memset_s: n > RSIZE_MAX") == 0); /* n < 0, handler */ - set_constraint_handler_s(h); + (void) set_constraint_handler_s(h); e = 0; m = NULL; assert(memset_s(&a, 1, 1, -1) != 0); diff --git a/usr/src/test/libc-tests/tests/printf-6961.c b/usr/src/test/libc-tests/tests/printf-6961.c index 5c60b96425..c98c2b6a79 100644 --- a/usr/src/test/libc-tests/tests/printf-6961.c +++ b/usr/src/test/libc-tests/tests/printf-6961.c @@ -41,71 +41,71 @@ main(void) char buf[32]; /* ~0L in octal */ - char octal0[] = { 'r', 'r', 'r', 'r', '1', '7', '7', '7', '7', '7', '7', + char octal0[32] = { 'r', 'r', 'r', 'r', '1', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', - '7', '7', '\0', 'r', 'r', 'r', 'r', 'r', 'r' }; + '7', '7', '7', '\0', 'r', 'r', 'r', 'r', 'r' }; - char decimal0[] = { 'r', 'r', 'r', 'r', '-', '1', '\0', 'r', 'r', 'r', + char decimal0[32] = { 'r', 'r', 'r', 'r', '-', '1', '\0', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', - 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; + 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; - char hex0[] = { 'r', 'r', 'r', 'r', 'f', 'f', 'f', 'f', 'f', 'f', + char hex0[32] = { 'r', 'r', 'r', 'r', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', '\0', 'r', 'r', - 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; + 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; /* 42 in octal */ - char octal1[] = { 'r', 'r', 'r', 'r', '5', '2', '\0', 'r', 'r', 'r', + char octal1[32] = { 'r', 'r', 'r', 'r', '5', '2', '\0', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', - 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; + 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; /* 42 in decimal */ - char decimal1[] = { 'r', 'r', 'r', 'r', '4', '2', '\0', 'r', 'r', 'r', + char decimal1[32] = { 'r', 'r', 'r', 'r', '4', '2', '\0', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', - 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; + 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; /* 42 in hex */ - char hex1[] = { 'r', 'r', 'r', 'r', '2', 'a', '\0', 'r', 'r', 'r', 'r', + char hex1[32] = { 'r', 'r', 'r', 'r', '2', 'a', '\0', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' }; (void) memset(buf, 'r', sizeof (buf)); - (void) snprintf(buf + 4, sizeof (buf), "%lo", ~0L); + (void) snprintf(buf + 4, sizeof (buf) - 4, "%lo", ~0L); if (bcmp(octal0, buf, sizeof (buf)) != 0) { print_diff("~0 in Octal", octal0, buf); ret++; } (void) memset(buf, 'r', sizeof (buf)); - (void) snprintf(buf + 4, sizeof (buf), "%lo", 42L); + (void) snprintf(buf + 4, sizeof (buf) - 4, "%lo", 42L); if (bcmp(octal1, buf, sizeof (buf)) != 0) { print_diff("42 in Octal", octal1, buf); ret++; } (void) memset(buf, 'r', sizeof (buf)); - (void) snprintf(buf + 4, sizeof (buf), "%ld", ~0L); + (void) snprintf(buf + 4, sizeof (buf) - 4, "%ld", ~0L); if (bcmp(decimal0, buf, sizeof (buf)) != 0) { print_diff("~0 in Decimal", decimal0, buf); ret++; } (void) memset(buf, 'r', sizeof (buf)); - (void) snprintf(buf + 4, sizeof (buf), "%ld", 42L); + (void) snprintf(buf + 4, sizeof (buf) - 4, "%ld", 42L); if (bcmp(decimal1, buf, sizeof (buf)) != 0) { print_diff("42 in Decimal", decimal1, buf); ret++; } (void) memset(buf, 'r', sizeof (buf)); - (void) snprintf(buf + 4, sizeof (buf), "%lx", ~0L); + (void) snprintf(buf + 4, sizeof (buf) - 4, "%lx", ~0L); if (bcmp(hex0, buf, sizeof (buf)) != 0) { print_diff("~0 in Hex", hex0, buf); ret++; } (void) memset(buf, 'r', sizeof (buf)); - (void) snprintf(buf + 4, sizeof (buf), "%lx", 42L); + (void) snprintf(buf + 4, sizeof (buf) - 4, "%lx", 42L); if (bcmp(hex1, buf, sizeof (buf)) != 0) { print_diff("42 in Hex", hex1, buf); ret++; diff --git a/usr/src/test/libc-tests/tests/select/Makefile b/usr/src/test/libc-tests/tests/select/Makefile index 2b0d80c6d6..ce019e281a 100644 --- a/usr/src/test/libc-tests/tests/select/Makefile +++ b/usr/src/test/libc-tests/tests/select/Makefile @@ -25,9 +25,6 @@ PROGS= select_test CSTD= $(CSTD_GNU99) -# needs work -SMOFF += all_func_returns - select_test: select_test.c $(LINK64.c) -o $@ select_test.c $(LDLIBS64) $(POST_PROCESS) diff --git a/usr/src/test/libc-tests/tests/select/select_test.c b/usr/src/test/libc-tests/tests/select/select_test.c index f6af3718cb..2b30df4f5c 100644 --- a/usr/src/test/libc-tests/tests/select/select_test.c +++ b/usr/src/test/libc-tests/tests/select/select_test.c @@ -39,12 +39,12 @@ print_set(fd_set *a, size_t size) { for (int i = 0; i < size; i++) { if (FD_ISSET(i, a)) - putc('1', stdout); + (void) putc('1', stdout); else - putc('0', stdout); + (void) putc('0', stdout); } - putc('\n', stdout); + (void) putc('\n', stdout); } int @@ -85,8 +85,10 @@ main(int argc, char **argv) if ((null = open("/dev/null", O_RDONLY)) == -1) err(1, "couldn't open /dev/null"); - read(null, &buf, 1); - read(null, &buf, 1); + if (read(null, &buf, 1) < 0) + err(1, "failed to read fd"); + if (read(null, &buf, 1) < 0) + err(1, "failed to read fd"); if ((zero = open("/dev/zero", O_RDWR)) == -1) err(1, "couldn't open /dev/zero"); @@ -103,11 +105,11 @@ main(int argc, char **argv) } if (swrite != NULL) - puts("write"); + (void) puts("write"); else if (sread != NULL) - puts("read"); + (void) puts("read"); else if (serr != NULL) - puts("err"); + (void) puts("err"); print_set(&proto, 80); diff --git a/usr/src/test/libc-tests/tests/set_constraint_handler_s.c b/usr/src/test/libc-tests/tests/set_constraint_handler_s.c index 770d5d46a4..1f9d6fe6df 100644 --- a/usr/src/test/libc-tests/tests/set_constraint_handler_s.c +++ b/usr/src/test/libc-tests/tests/set_constraint_handler_s.c @@ -33,11 +33,11 @@ main(void) assert(set_constraint_handler_s(abort_handler_s) == NULL); /* abort handler */ - set_constraint_handler_s(abort_handler_s); + (void) set_constraint_handler_s(abort_handler_s); assert(set_constraint_handler_s(ignore_handler_s) == abort_handler_s); /* ignore handler */ - set_constraint_handler_s(ignore_handler_s); + (void) set_constraint_handler_s(ignore_handler_s); assert(set_constraint_handler_s(abort_handler_s) == ignore_handler_s); return (0); diff --git a/usr/src/test/libc-tests/tests/symbols/Makefile b/usr/src/test/libc-tests/tests/symbols/Makefile index ac2ede1092..a5eef8a3a8 100644 --- a/usr/src/test/libc-tests/tests/symbols/Makefile +++ b/usr/src/test/libc-tests/tests/symbols/Makefile @@ -50,9 +50,6 @@ EXTRAPROG += $(SYMTESTS) include ../Makefile.com -# needs work -SMOFF += testing_index_after_use - LDLIBS += -lcustr LDLIBS64 += -lcustr diff --git a/usr/src/test/libc-tests/tests/symbols/symbols_test.c b/usr/src/test/libc-tests/tests/symbols/symbols_test.c index ac92feb2b6..ca714eb9f2 100644 --- a/usr/src/test/libc-tests/tests/symbols/symbols_test.c +++ b/usr/src/test/libc-tests/tests/symbols/symbols_test.c @@ -372,7 +372,7 @@ mkprog(struct sym_test *st) case SYM_FUNC: addprogstr("\ntest_func("); - for (int i = 0; st->st_atypes[i] != NULL && i < MAXARG; i++) { + for (int i = 0; i < MAXARG && st->st_atypes[i] != NULL; i++) { int didname = 0; if (i > 0) { addprogstr(", "); @@ -422,7 +422,7 @@ mkprog(struct sym_test *st) /* add the function call */ addprogfmt("%s(", st->st_name); - for (int i = 0; st->st_atypes[i] != NULL && i < MAXARG; i++) { + for (int i = 0; i < MAXARG && st->st_atypes[i] != NULL; i++) { if (strcmp(st->st_atypes[i], "") != 0 && strcmp(st->st_atypes[i], "void") != 0) { addprogfmt("%sa%d", i > 0 ? ", " : "", i); diff --git a/usr/src/test/os-tests/runfiles/default.run b/usr/src/test/os-tests/runfiles/default.run index 940b9bf97a..795f559c50 100644 --- a/usr/src/test/os-tests/runfiles/default.run +++ b/usr/src/test/os-tests/runfiles/default.run @@ -26,6 +26,9 @@ outputdir = /var/tmp/test_results user = root tests = ['poll_test', 'epoll_test'] +[/opt/os-tests/tests/odirectory.32] +[/opt/os-tests/tests/odirectory.64] + [/opt/os-tests/tests/secflags] user = root tests = ['secflags_aslr', diff --git a/usr/src/test/os-tests/tests/Makefile b/usr/src/test/os-tests/tests/Makefile index 3107af540c..a0a5592ef1 100644 --- a/usr/src/test/os-tests/tests/Makefile +++ b/usr/src/test/os-tests/tests/Makefile @@ -33,26 +33,30 @@ SUBDIRS = \ $(SUBDIRS_$(MACH)) PROGS = \ + odirectory \ OS-6097 +CPPFLAGS += -D_REENTRANT PROGS32 = $(PROGS:%=%.32) PROGS64 = $(PROGS:%=%.64) -OS-6097.32 := LDLIBS += -ldlpi -OS-6097.64 := LDLIBS64 += -ldlpi - ROOTOPTDIR = $(ROOT)/opt/os-tests/tests ROOTOPTPROGS = $(PROGS32:%=$(ROOTOPTDIR)/%) \ $(PROGS64:%=$(ROOTOPTDIR)/%) \ $(SCRIPTS:%=$(ROOTOPTDIR)/%) +odirectory.32 := LDLIBS += -lsocket +odirectory.64 := LDLIBS64 += -lsocket + +OS-6097.32 := LDLIBS += -ldlpi +OS-6097.64 := LDLIBS64 += -ldlpi + include $(SRC)/cmd/Makefile.cmd all := TARGET = all install := TARGET = install clean := TARGET = clean clobber := TARGET = clobber -lint := TARGET = lint .KEEP_STATE: @@ -60,7 +64,7 @@ install: $(SUBDIRS) $(ROOTOPTPROGS) all: $(SUBDIRS) $(PROGS32) $(PROGS64) -clean lint: $(SUBDIRS) +clean: $(SUBDIRS) $(ROOTOPTPROGS): $(PROGS32) $(PROGS64) $(ROOTOPTDIR) diff --git a/usr/src/test/os-tests/tests/odirectory.c b/usr/src/test/os-tests/tests/odirectory.c new file mode 100644 index 0000000000..e994126227 --- /dev/null +++ b/usr/src/test/os-tests/tests/odirectory.c @@ -0,0 +1,251 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2020 Robert Mustacchi + */ + +/* + * Test different O_DIRECTORY open cases. + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <err.h> +#include <string.h> +#include <stdlib.h> +#include <limits.h> +#include <door.h> +#include <stropts.h> +#include <sys/socket.h> + +static uint_t odir_failures; +static char odir_fpath[PATH_MAX]; +static char odir_dpath[PATH_MAX]; +static char odir_doorpath[PATH_MAX]; +static char odir_enoent[PATH_MAX]; +static char odir_udspath[PATH_MAX]; +static int odir_did = -1; +static int odir_uds = -1; + +static void +odir_test_one(const char *test, const char *path, int flags, int err) +{ + int fd = open(path, flags | O_DIRECTORY | O_RDONLY, 0644); + if (fd >= 0) { + (void) close(fd); + if (err != 0) { + odir_failures++; + warnx("TEST FAILED: %s: opened %s, but expected error: " + "%d", test, path, err); + } + } else { + if (err == 0) { + odir_failures++; + warnx("TEST FAILED: %s: failed to open %s, error: %d", + test, path, err); + } else if (err != errno) { + odir_failures++; + warnx("TEST FAILED: %s: wrong error for path %s, " + "found %d, expected %d", test, path, errno, err); + } + } +} + +static void +odir_door_server(void *cookie, char *argp, size_t arg_size, door_desc_t *dp, + uint_t ndesc) +{ + (void) door_return(NULL, 0, NULL, 0); +} + +static boolean_t +odir_setup(void) +{ + int fd; + struct stat st; + struct sockaddr_un un; + pid_t pid = getpid(); + + (void) snprintf(odir_fpath, sizeof (odir_fpath), + "/tmp/odir.%d.file", pid); + if ((fd = creat(odir_fpath, 0644)) < 0) { + warn("failed to create temp file %s", odir_fpath); + odir_fpath[0] = '\0'; + return (B_FALSE); + } + (void) close(fd); + + (void) snprintf(odir_dpath, sizeof (odir_dpath), + "/tmp/odir.%d.dir", pid); + if (mkdir(odir_dpath, 0755) != 0) { + warn("failed to create temp directory %s", odir_dpath); + odir_dpath[0] = '\0'; + return (B_FALSE); + } + + odir_did = door_create(odir_door_server, NULL, 0); + if (odir_did == -1) { + warnx("failed to create door"); + return (B_FALSE); + } + (void) snprintf(odir_doorpath, sizeof (odir_doorpath), + "/tmp/odir.%d.door", pid); + if ((fd = creat(odir_doorpath, 0644)) < 0) { + warn("failed to create %s", odir_doorpath); + odir_doorpath[0] = '\0'; + return (B_FALSE); + } + (void) close(fd); + if (fattach(odir_did, odir_doorpath) != 0) { + warn("failed to attach door to %s", odir_doorpath); + (void) unlink(odir_doorpath); + odir_doorpath[0] = '\0'; + return (B_FALSE); + } + + (void) snprintf(odir_enoent, sizeof (odir_enoent), + "/tmp/odir.%d.enoent", pid); + if (stat(odir_enoent, &st) == 0) { + warnx("somehow random file %s exists!", odir_enoent); + } + + odir_uds = socket(PF_UNIX, SOCK_STREAM, 0); + if (odir_uds == -1) { + warn("failed to create UDS"); + return (B_FALSE); + } + (void) snprintf(odir_udspath, sizeof (odir_udspath), + "/tmp/odir.%d.uds", pid); + (void) memset(&un, '\0', sizeof (un)); + un.sun_family = AF_UNIX; + if (strlcpy(un.sun_path, odir_udspath, sizeof (un.sun_path)) >= + sizeof (un.sun_path)) { + warnx("%s overflows AF_UNIX path", odir_udspath); + odir_udspath[0] = '\0'; + return (B_FALSE); + } + + if (bind(odir_uds, (struct sockaddr *)&un, SUN_LEN(&un)) != 0) { + warn("failed to bind %s", odir_udspath); + odir_udspath[0] = '\0'; + return (B_FALSE); + } + + if (listen(odir_uds, 1) != 0) { + warn("failed to listen on %s", odir_udspath); + return (B_FALSE); + } + + return (B_TRUE); +} + +static void +odir_verify_enoent(void) +{ + struct stat st; + + if (stat(odir_enoent, &st) == 0) { + warnx("TEST FAILED: %s was created", odir_enoent); + odir_failures++; + } else if (errno != ENOENT) { + warn("TEST FAILED: stat on %s failed", odir_enoent); + odir_failures++; + } +} + +static void +odir_cleanup(void) +{ + if (odir_udspath[0] != '\0') { + if (unlink(odir_udspath) != 0) { + warn("failed to unlink %s", odir_udspath); + } + } + + if (odir_uds != -1) { + if (close(odir_uds) != 0) { + warn("failed to close UDS"); + } + } + + if (odir_doorpath[0] != '\0') { + if (fdetach(odir_doorpath) != 0) { + warn("failed to detach door %s", odir_doorpath); + } + + if (unlink(odir_doorpath) != 0) { + warn("failed to unlink %s", odir_doorpath); + } + } + + if (odir_did != -1) { + if (door_revoke(odir_did) != 0) { + warn("failed to revoke door"); + } + } + + if (odir_dpath[0] != '\0') { + if (rmdir(odir_dpath) != 0) { + warn("failed to clean up %s", odir_dpath); + } + } + + if (odir_fpath[0] != '\0') { + if (unlink(odir_fpath) != 0) { + warn("failed to clean up %s", odir_fpath); + } + } +} + +int +main(void) +{ + if (!odir_setup()) { + odir_cleanup(); + return (EXIT_FAILURE); + } + + odir_test_one("regular file", odir_fpath, 0, ENOTDIR); + odir_test_one("directory", odir_dpath, 0, 0); + odir_test_one("character device", "/dev/null", 0, ENOTDIR); + odir_test_one("door server", odir_doorpath, 0, ENOTDIR); + odir_test_one("missing file", odir_enoent, 0, ENOENT); + odir_test_one("UDS", odir_udspath, 0, ENOTDIR); + + odir_test_one("O_CREAT | O_DIRECTORY on a regular file", odir_fpath, + O_CREAT, ENOTDIR); + odir_test_one("O_CREAT | O_DIRECTORY | O_EXCL on a regular file", + odir_fpath, O_CREAT | O_EXCL, EINVAL); + + odir_test_one("O_CREAT | O_DIRECTORY on a directory", odir_dpath, + O_CREAT, 0); + odir_test_one("O_CREAT | O_DIRECTORY | O_EXCL on a directory", + odir_dpath, O_CREAT | O_EXCL, EINVAL); + + odir_test_one("O_CREAT | O_DIRECTORY on a missing file", odir_enoent, + O_CREAT, ENOENT); + odir_verify_enoent(); + odir_test_one("O_CREAT | O_DIRECTORY | O_EXCL on a missing file", + odir_enoent, O_CREAT | O_EXCL, EINVAL); + odir_verify_enoent(); + + odir_cleanup(); + if (odir_failures > 0) { + warnx("%u tests failed", odir_failures); + } + + return (odir_failures > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +} diff --git a/usr/src/tools/scripts/check_rtime.1onbld b/usr/src/tools/scripts/check_rtime.1onbld index f53ce0dcb0..e6825361ca 100644 --- a/usr/src/tools/scripts/check_rtime.1onbld +++ b/usr/src/tools/scripts/check_rtime.1onbld @@ -19,7 +19,7 @@ .\" .\" CDDL HEADER END .\" -.Dd February 19, 2018 +.Dd February 3, 2020 .Dt CHECK_RTIME 1ONBLD .Os .Sh NAME @@ -192,7 +192,7 @@ the symbol sorting sections, and for direct bindings. These checks are carried out for the following reasons: .Bl -bullet .It -A concatenated relocation section +A concatenated relocation section .Pq Em .SUNW_reloc provides optimal symbol table access at runtime, and thus reduces the overhead of relocating the shared object. @@ -389,11 +389,11 @@ Dependencies are printed as: .Dl foo: NEEDED=bar.so.1 .It Dependencies may be marked as forbidden -.Pq see Sx EXCEPTION FILE FORMAT +.Pq see Sx EXCEPTION FILE FORMAT this allows the build to warn should people use them accidentally. Forbidden dependencies are printed as: .Pp -.Dl foo: NEEDED=bar.so.1 <forbidden dependency, missing -nodefaultlibs?> +.Dl foo: NEEDED=bar.so.1 <forbidden dependency, missing -nodefaultlibs?> .El .Pp .Nm check_rtime @@ -546,7 +546,7 @@ regular expression: Since whitespace is used as a separator, the regular expression cannot itself contain whitespace. Use of the -.Ql \\s +.Ql \es character class to represent whitespace within the regular expression is recommended. .Pp @@ -595,13 +595,13 @@ exceptions will not suffice. Objects that are allowed to contain debugging information (stabs). .It TEXTREL Objects for which we allow relocations to the text segment. -.It BUNDEF_OBJ +.It UNREF_OBJ Objects that are allowed to be unreferenced. .It UNDEF_REF Objects that are allowed undefined references. .It UNUSED_DEPS Objects that are allowed to have unused dependencies. -.It BUNUSED_OBJ +.It UNUSED_OBJ Objects that are always allowed to be unused dependencies. .It UNUSED_RPATH Objects that are allowed to have unused runpath directories. diff --git a/usr/src/uts/common/fs/vnode.c b/usr/src/uts/common/fs/vnode.c index e16dbbbc8d..9e0b071999 100644 --- a/usr/src/uts/common/fs/vnode.c +++ b/usr/src/uts/common/fs/vnode.c @@ -972,6 +972,7 @@ vn_openat( int estale_retry = 0; struct shrlock shr; struct shr_locowner shr_own; + boolean_t create; mode = 0; accessflags = 0; @@ -991,8 +992,31 @@ vn_openat( if (filemode & FAPPEND) accessflags |= V_APPEND; + /* + * We need to handle the case of FCREAT | FDIRECTORY and the case of + * FEXCL. If all three are specified, then we always fail because we + * cannot create a directory through this interface and FEXCL says we + * need to fail the request if we can't create it. If, however, only + * FCREAT | FDIRECTORY are specified, then we can treat this as the case + * of opening a file that already exists. If it exists, we can do + * something and if not, we fail. Effectively FCREAT | FDIRECTORY is + * treated as FDIRECTORY. + */ + if ((filemode & (FCREAT | FDIRECTORY | FEXCL)) == + (FCREAT | FDIRECTORY | FEXCL)) { + return (EINVAL); + } + + if ((filemode & (FCREAT | FDIRECTORY)) == (FCREAT | FDIRECTORY)) { + create = B_FALSE; + } else if ((filemode & FCREAT) != 0) { + create = B_TRUE; + } else { + create = B_FALSE; + } + top: - if (filemode & FCREAT) { + if (create) { enum vcexcl excl; /* @@ -1089,11 +1113,13 @@ top: */ if (error = VOP_ACCESS(vp, mode, accessflags, CRED(), NULL)) goto out; + /* - * Require FSEARCH to return a directory. - * Require FEXEC to return a regular file. + * Require FSEARCH and FDIRECTORY to return a directory. Require + * FEXEC to return a regular file. */ - if ((filemode & FSEARCH) && vp->v_type != VDIR) { + if ((filemode & (FSEARCH|FDIRECTORY)) != 0 && + vp->v_type != VDIR) { error = ENOTDIR; goto out; } diff --git a/usr/src/uts/common/io/idm/idm_conn_sm.c b/usr/src/uts/common/io/idm/idm_conn_sm.c index 011a1ca784..45ba8872b8 100644 --- a/usr/src/uts/common/io/idm/idm_conn_sm.c +++ b/usr/src/uts/common/io/idm/idm_conn_sm.c @@ -23,6 +23,7 @@ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright 2017 Nexenta Systems, Inc. All rights reserved. + * Copyright 2020 Joyent, Inc. */ #include <sys/cpuvar.h> @@ -341,6 +342,7 @@ idm_conn_event_handler(void *event_ctx_opaque) */ IDM_SM_LOG(CE_NOTE, "*** drop PDU %p", (void *) pdu); idm_pdu_complete(pdu, IDM_STATUS_FAIL); + event_ctx->iec_info = (uintptr_t)NULL; break; default: ASSERT(0); @@ -420,6 +422,10 @@ idm_conn_event_handler(void *event_ctx_opaque) } } break; + case CA_DROP: + /* Already completed above. */ + ASSERT3P(event_ctx->iec_info, ==, NULL); + break; default: ASSERT(0); break; diff --git a/usr/src/uts/common/sys/fcntl.h b/usr/src/uts/common/sys/fcntl.h index 3167fd4a1d..cf55ebbf2a 100644 --- a/usr/src/uts/common/sys/fcntl.h +++ b/usr/src/uts/common/sys/fcntl.h @@ -86,6 +86,9 @@ extern "C" { #define O_NOFOLLOW 0x20000 /* don't follow symlinks */ #define O_NOLINKS 0x40000 /* don't allow multiple hard links */ #define O_CLOEXEC 0x800000 /* set the close-on-exec flag */ +#if !defined(_STRICT_SYMBOLS) || defined(_XPG7) +#define O_DIRECTORY 0x1000000 /* fail if not a directory */ +#endif /* * fcntl(2) requests @@ -181,7 +184,7 @@ extern "C" { #endif /* _STRICT_SYMBOLS */ #endif /* _LP64 || _FILE_OFFSET_BITS == 32 */ -#if defined(_LARGEFILE64_SOURCE) +#if defined(_LARGEFILE64_SOURCE) #if !defined(_LP64) || defined(_KERNEL) /* @@ -260,7 +263,7 @@ typedef struct flock32 { /* transitional large file interface version */ -#if defined(_LARGEFILE64_SOURCE) +#if defined(_LARGEFILE64_SOURCE) typedef struct flock64 { short l_type; diff --git a/usr/src/uts/common/sys/file.h b/usr/src/uts/common/sys/file.h index f63f2a10da..816f6a7d33 100644 --- a/usr/src/uts/common/sys/file.h +++ b/usr/src/uts/common/sys/file.h @@ -118,6 +118,7 @@ typedef struct fpollinfo { #define FEXEC 0x400000 /* O_EXEC = 0x400000 */ #define FCLOEXEC 0x800000 /* O_CLOEXEC = 0x800000 */ +#define FDIRECTORY 0x1000000 /* O_DIRECTORY = 0x1000000 */ #if defined(_KERNEL) || defined(_FAKE_KERNEL) |