Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/net Enforce that getpeereid only returns success on...
details: https://anonhg.NetBSD.org/src/rev/4b30761a6686
branches: trunk
changeset: 359598:4b30761a6686
user: christos <christos%NetBSD.org@localhost>
date: Fri Feb 16 19:21:49 2018 +0000
description:
Enforce that getpeereid only returns success on AF_LOCAL sockets, instead
of returning garbage for other socket types.
diffstat:
lib/libc/net/getpeereid.c | 33 ++++++++++++++++++++++-----------
1 files changed, 22 insertions(+), 11 deletions(-)
diffs (58 lines):
diff -r 5e42ab0978ef -r 4b30761a6686 lib/libc/net/getpeereid.c
--- a/lib/libc/net/getpeereid.c Fri Feb 16 18:13:47 2018 +0000
+++ b/lib/libc/net/getpeereid.c Fri Feb 16 19:21:49 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getpeereid.c,v 1.2 2008/04/29 06:53:01 martin Exp $ */
+/* $NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -31,27 +31,38 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getpeereid.c,v 1.2 2008/04/29 06:53:01 martin Exp $");
+__RCSID("$NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
-#include <unistd.h>
#include <sys/un.h>
#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
int
getpeereid(int s, uid_t *euid, gid_t *egid)
{
struct unpcbid cred;
- socklen_t len = sizeof(cred);
- if (getsockopt(s, 0, LOCAL_PEEREID, &cred, &len) < 0) {
+ struct sockaddr_storage ss;
+ socklen_t len;
+
+ len = sizeof(ss);
+ if (getsockname(s, (void *)&ss, &len) == -1)
+ return -1;
+ if (ss.ss_family != AF_LOCAL) {
+ errno = EOPNOTSUPP;
return -1;
- } else {
- if (euid != NULL)
- *euid = cred.unp_euid;
- if (egid != NULL)
- *egid = cred.unp_egid;
- return 0;
}
+
+ len = sizeof(cred);
+ if (getsockopt(s, 0, LOCAL_PEEREID, &cred, &len) == -1)
+ return -1;
+
+ if (euid != NULL)
+ *euid = cred.unp_euid;
+ if (egid != NULL)
+ *egid = cred.unp_egid;
+ return 0;
}
Home |
Main Index |
Thread Index |
Old Index