From 960e96723f6cfe64c370b7c1168c664f4c49deae Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 3 Jan 2025 08:02:22 -0800 Subject: fixes #2061 Move IPC parameters from uint64 to int --- src/platform/posix/posix_ipcconn.c | 30 +++++++++++++++--------------- src/platform/posix/posix_peerid.c | 30 ++++++++++++------------------ src/platform/posix/posix_peerid.h | 7 +++---- src/platform/posix/posix_sockfd.c | 28 ++++++++++++++-------------- src/platform/windows/win_ipcconn.c | 7 +++++-- 5 files changed, 49 insertions(+), 53 deletions(-) (limited to 'src/platform') diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c index b3376815..41676340 100644 --- a/src/platform/posix/posix_ipcconn.c +++ b/src/platform/posix/posix_ipcconn.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -304,14 +304,14 @@ ipc_get_peer_uid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &id, &ignore, &ignore, &ignore)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -319,14 +319,14 @@ ipc_get_peer_gid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &ignore, &id, &ignore, &ignore)) != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -334,18 +334,18 @@ ipc_get_peer_zoneid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &ignore, &ignore, &ignore, &id)) != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal zone id (illumos/Solaris) return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -353,18 +353,18 @@ ipc_get_peer_pid(void *arg, void *buf, size_t *szp, nni_type t) { ipc_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; if ((rv = nni_posix_peerid(nni_posix_pfd_fd(&c->pfd), &ignore, &ignore, &id, &ignore)) != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal process id return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int diff --git a/src/platform/posix/posix_peerid.c b/src/platform/posix/posix_peerid.c index e0020150..0ce9d6bc 100644 --- a/src/platform/posix/posix_peerid.c +++ b/src/platform/posix/posix_peerid.c @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -38,10 +38,8 @@ #define SOL_LOCAL 0 #endif - int -nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, - uint64_t *znid) +nni_posix_peerid(int fd, int *euid, int *egid, int *prid, int *znid) { #if defined(NNG_HAVE_GETPEEREID) && !defined(NNG_HAVE_LOCALPEERCRED) uid_t uid; @@ -52,8 +50,8 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, } *euid = uid; *egid = gid; - *prid = (uint64_t) -1; - *znid = (uint64_t) -1; + *prid = -1; + *znid = -1; return (0); #elif defined(NNG_HAVE_GETPEERUCRED) ucred_t *ucp = NULL; @@ -75,7 +73,7 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, *euid = uc.uid; *egid = uc.gid; *prid = uc.pid; - *znid = (uint64_t) -1; + *znid = -1; return (0); #elif defined(NNG_HAVE_SOPEERCRED) struct ucred uc; @@ -86,7 +84,7 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, *euid = uc.uid; *egid = uc.gid; *prid = uc.pid; - *znid = (uint64_t) -1; + *znid = -1; return (0); #elif defined(NNG_HAVE_LOCALPEERCRED) struct xucred xu; @@ -96,17 +94,14 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, } *euid = xu.cr_uid; *egid = xu.cr_gid; - *prid = (uint64_t) -1; - *znid = (uint64_t) -1; + *prid = -1; + *znid = -1; #if defined(NNG_HAVE_LOCALPEERPID) // documented on macOS since 10.8 - { - pid_t pid; - if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERPID, &pid, &len) == - 0) { - *prid = (uint64_t) pid; - } + pid_t pid; + if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERPID, &pid, &len) == 0) { + *prid = pid; } -#endif // NNG_HAVE_LOCALPEERPID +#endif // NNG_HAVE_LOCALPEERPID return (0); #else if (fd < 0) { @@ -119,4 +114,3 @@ nni_posix_peerid(int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, return (NNG_ENOTSUP); #endif } - diff --git a/src/platform/posix/posix_peerid.h b/src/platform/posix/posix_peerid.h index 57e9abff..be3d67de 100644 --- a/src/platform/posix/posix_peerid.h +++ b/src/platform/posix/posix_peerid.h @@ -1,5 +1,5 @@ // -// Copyright 2023 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -19,7 +19,6 @@ #include "core/nng_impl.h" #include -int nni_posix_peerid( - int fd, uint64_t *euid, uint64_t *egid, uint64_t *prid, uint64_t *znid); +int nni_posix_peerid(int fd, int *euid, int *egid, int *prid, int *znid); -#endif // PLATFORM_POSIX_PEERID_H \ No newline at end of file +#endif // PLATFORM_POSIX_PEERID_H diff --git a/src/platform/posix/posix_sockfd.c b/src/platform/posix/posix_sockfd.c index 96782c04..0bdee2d6 100644 --- a/src/platform/posix/posix_sockfd.c +++ b/src/platform/posix/posix_sockfd.c @@ -339,14 +339,14 @@ sfd_get_peer_uid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &id, &ignore, &ignore, &ignore); if (rv != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -354,14 +354,14 @@ sfd_get_peer_gid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &ignore, &id, &ignore, &ignore); if (rv != 0) { return (rv); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -369,18 +369,18 @@ sfd_get_peer_zoneid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &ignore, &ignore, &ignore, &id); if (rv != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal zone id (illumos/Solaris) return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static int @@ -388,18 +388,18 @@ sfd_get_peer_pid(void *arg, void *buf, size_t *szp, nni_type t) { nni_sfd_conn *c = arg; int rv; - uint64_t ignore; - uint64_t id = 0; + int ignore; + int id = 0; rv = nni_posix_peerid(c->fd, &ignore, &ignore, &id, &ignore); if (rv != 0) { return (rv); } - if (id == (uint64_t) -1) { + if (id == -1) { // NB: -1 is not a legal process id return (NNG_ENOTSUP); } - return (nni_copyout_u64(id, buf, szp, t)); + return (nni_copyout_int(id, buf, szp, t)); } static const nni_option sfd_options[] = { diff --git a/src/platform/windows/win_ipcconn.c b/src/platform/windows/win_ipcconn.c index f6c1b2a4..353d703f 100644 --- a/src/platform/windows/win_ipcconn.c +++ b/src/platform/windows/win_ipcconn.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -407,7 +407,10 @@ ipc_conn_get_peer_pid(void *c, void *buf, size_t *szp, nni_opt_type t) return (nni_win_error(GetLastError())); } } - return (nni_copyout_u64(id, buf, szp, t)); + // While the above APIs take ULONG, the actual process IDs in + // Windows are DWORD (i.e. int). See GetProcessId() that returns an + // int. + return (nni_copyout_int((int) id, buf, szp, t)); } static const nni_option ipc_conn_options[] = { -- cgit v1.2.3-70-g09d2