From: Jonas 'Sortie' Termansen Subject: Miscellaneous LibreSSL portability fixes To: tech@openbsd.org Date: Sat, 2 Nov 2024 14:42:55 +0100 Hi, Here's a few portability fixes that LibreSSL work in circumstances allowed by POSIX. uid_t can be 64-bit per POSIX. That's the case on my Sortix OS. Yeah I'm aware that it causes breakage like this every now and then, but those cases are easy to fix. mktemp was removed in POSIX 2008. mkstemp is the safer standard replacement, although this pattern used here is correct for unix socket creation. It is easy to use mkstemp instead though. caddr_t is not a standard type. It's cleaner to use just char* instead. Although in this case msg_control is standardized as void* so no cast is needed at all, now that I think about it. Hopefully you'll take these patches, it's most of what I need for LibreSSL to support my operating system, besides a few issues that I need to fix on my side :) Jonas Termansen diff --git a/lib/libtls/tls_config.c b/lib/libtls/tls_config.c index 22fa8455a..e35026488 100644 --- a/lib/libtls/tls_config.c +++ b/lib/libtls/tls_config.c @@ -742,8 +742,8 @@ tls_config_set_session_fd(struct tls_config *config, int session_fd) if (sb.st_uid != getuid()) { tls_config_set_errorx(config, TLS_ERROR_UNKNOWN, - "session file has incorrect owner (uid %u != %u)", - sb.st_uid, getuid()); + "session file has incorrect owner (uid %llu != %llu)" + (unsigned long long)sb.st_uid, (unsigned long long)getuid()); return (-1); } mugo = sb.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO); diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index a25c4f175..de13006b2 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -457,8 +457,11 @@ main(int argc, char *argv[]) } else { strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX", UNIX_DG_TMP_SOCKET_SIZE); - if (mktemp(unix_dg_tmp_socket_buf) == NULL) + int fd = mkstemp(unix_dg_tmp_socket_buf); + if (fd < 0) err(1, "mktemp"); + unlink(unix_dg_tmp_socket_buf); + close(fd); unix_dg_tmp_socket = unix_dg_tmp_socket_buf; } } @@ -1367,7 +1370,7 @@ fdpass(int nfd) memset(&cmsgbuf, 0, sizeof(cmsgbuf)); memset(&iov, 0, sizeof(iov)); - mh.msg_control = (caddr_t)&cmsgbuf.buf; + mh.msg_control = (char*)&cmsgbuf.buf; mh.msg_controllen = sizeof(cmsgbuf.buf); cmsg = CMSG_FIRSTHDR(&mh); cmsg->cmsg_len = CMSG_LEN(sizeof(int));