summaryrefslogtreecommitdiffstats
path: root/usr.sbin/user
diff options
context:
space:
mode:
authormestre <mestre@openbsd.org>2018-09-26 14:54:58 +0000
committermestre <mestre@openbsd.org>2018-09-26 14:54:58 +0000
commit636b7295b9723ec6d11cd94a6387ec2309cf2c46 (patch)
tree766e8c412424373e6856163e781d887c4fff4eea /usr.sbin/user
parentFix use-after-free by moving the free(3) of the configured interfaces to after (diff)
downloadwireguard-openbsd-636b7295b9723ec6d11cd94a6387ec2309cf2c46.tar.xz
wireguard-openbsd-636b7295b9723ec6d11cd94a6387ec2309cf2c46.zip
Fix segfault in usermod -l by swapping one of the getpwnam(3) with
uid_from_user(3). This started happening a few days ago after the change to the pwcache in libc. OK millert@
Diffstat (limited to 'usr.sbin/user')
-rw-r--r--usr.sbin/user/user.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c
index d8c1b34a3ef..077d76c618c 100644
--- a/usr.sbin/user/user.c
+++ b/usr.sbin/user/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.121 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: user.c,v 1.122 2018/09/26 14:54:58 mestre Exp $ */
/* $NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $ */
/*
@@ -1369,6 +1369,7 @@ moduser(char *login_name, char *newlogin, user_t *up)
int ptmpfd;
int rval;
int i;
+ uid_t uid;
if (!valid_login(newlogin)) {
errx(EXIT_FAILURE, "`%s' is not a valid login name", login_name);
@@ -1427,7 +1428,8 @@ moduser(char *login_name, char *newlogin, user_t *up)
if (up != NULL) {
if (up->u_flags & F_USERNAME) {
/* if changing name, check new name isn't already in use */
- if (strcmp(login_name, newlogin) != 0 && getpwnam(newlogin) != NULL) {
+ if (strcmp(login_name, newlogin) != 0 &&
+ uid_from_user(newlogin, &uid) != -1) {
close(ptmpfd);
pw_abort();
errx(EXIT_FAILURE, "already a `%s' user", newlogin);