From 8d48e738b5f20de3526e7640ae5823916127b193 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Fri, 23 Feb 2018 00:28:00 +0000 Subject: [PATCH] getpeereid(3): Fix behavior on failure to match documentation. According to the getpeereid(3) documentation, on failure the value -1 is returned and the global variable errno is set to indicate the error. We were returning the error instead. Obtained from: Apple's Libc-1244.30.3 MFC after: 5 days --- lib/libc/gen/getpeereid.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/getpeereid.c b/lib/libc/gen/getpeereid.c index 09f513502ecf..530ae0e6100e 100644 --- a/lib/libc/gen/getpeereid.c +++ b/lib/libc/gen/getpeereid.c @@ -50,8 +50,10 @@ getpeereid(int s, uid_t *euid, gid_t *egid) error = _getsockopt(s, 0, LOCAL_PEERCRED, &xuc, &xuclen); if (error != 0) return (error); - if (xuc.cr_version != XUCRED_VERSION) - return (EINVAL); + if (xuc.cr_version != XUCRED_VERSION) { + errno = EINVAL; + return (-1); + } *euid = xuc.cr_uid; *egid = xuc.cr_gid; return (0);