summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-06-08 20:50:51 +0000
committermillert <millert@openbsd.org>2003-06-08 20:50:51 +0000
commitce08dfce6bf7a5f3471aef0b62baf105c1c1c199 (patch)
treea03f5b4c086973a7e79545b6d721a0bf27675941
parentUse _PW_NAME_LEN not MAXLOGNAME since the latter does not include the NUL. (diff)
downloadwireguard-openbsd-ce08dfce6bf7a5f3471aef0b62baf105c1c1c199.tar.xz
wireguard-openbsd-ce08dfce6bf7a5f3471aef0b62baf105c1c1c199.zip
Add check for group too long and made an invalid group a fatal error
instead of just a warning which is consistent with the way an invalid user is treated.
-rw-r--r--usr.sbin/user/user.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c
index 7152192ff8b..0731ca5a691 100644
--- a/usr.sbin/user/user.c
+++ b/usr.sbin/user/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.43 2003/06/08 20:43:25 millert Exp $ */
+/* $OpenBSD: user.c,v 1.44 2003/06/08 20:50:51 millert Exp $ */
/* $NetBSD: user.c,v 1.45 2001/08/17 08:29:00 joda Exp $ */
/*
@@ -578,6 +578,8 @@ valid_group(char *group)
return 0;
}
}
+ if (cp - group > MaxUserNameLen)
+ return 0;
return 1;
}
@@ -1629,15 +1631,15 @@ groupadd(int argc, char **argv)
usermgmt_usage("groupadd");
}
checkeuid();
+ if (!valid_group(*argv)) {
+ errx(EXIT_FAILURE, "invalid group name `%s'", *argv);
+ }
if (gid < 0 && !getnextgid(&gid, LowGid, HighGid)) {
errx(EXIT_FAILURE, "can't add group: can't get next gid");
}
if (!dupgid && getgrgid((gid_t) gid) != NULL) {
errx(EXIT_FAILURE, "can't add group: gid %d is a duplicate", gid);
}
- if (!valid_group(*argv)) {
- warnx("warning - invalid group name `%s'", *argv);
- }
if (!creategid(*argv, gid, "")) {
errx(EXIT_FAILURE, "can't add group: problems with %s file",
_PATH_GROUP);
@@ -1741,7 +1743,7 @@ groupmod(int argc, char **argv)
errx(EXIT_FAILURE, "can't find group `%s' to modify", *argv);
}
if (newname != NULL && !valid_group(newname)) {
- warnx("warning - invalid group name `%s'", newname);
+ errx(EXIT_FAILURE, "invalid group name `%s'", newname);
}
if ((cc = snprintf(buf, sizeof(buf), "%s:%s:%u:",
(newname) ? newname : grp->gr_name, grp->gr_passwd,