summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2022-12-15 19:36:46 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2022-12-15 19:36:46 +0000
commit5726119b2193931f8f2a7e963ca85a012c3a7dec (patch)
tree5f70277f4dbaa05e4370b55d550c34db3cc37608
parentfb145a59e411e55116f4e2d781103b3958634a89 (diff)
priv_validgroup: do not read more than IF_NAMESIZE chars of name
Store the length locally instead of computing it multiple times. OK dv@, previous version OK deraadt@
-rw-r--r--usr.sbin/vmd/priv.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.sbin/vmd/priv.c b/usr.sbin/vmd/priv.c
index 860aac3f5f7..1732140eaea 100644
--- a/usr.sbin/vmd/priv.c
+++ b/usr.sbin/vmd/priv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: priv.c,v 1.20 2022/12/15 16:01:40 dv Exp $ */
+/* $OpenBSD: priv.c,v 1.21 2022/12/15 19:36:45 millert Exp $ */
/*
* Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
@@ -316,10 +316,12 @@ priv_findname(const char *name, const char **names)
int
priv_validgroup(const char *name)
{
- if (strlen(name) >= IF_NAMESIZE)
+ const size_t len = strnlen(name, IF_NAMESIZE);
+
+ if (len == IF_NAMESIZE)
return (-1);
/* Group can not end with a digit */
- if (name[0] && isdigit((unsigned char)name[strlen(name) - 1]))
+ if (len > 0 && isdigit((unsigned char)name[len - 1]))
return (-1);
return (0);
}