summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index ae4d29b8..c4ca1256 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.131 2018/07/27 05:13:02 dtucker Exp $ */
+/* $OpenBSD: misc.c,v 1.132 2018/10/03 06:38:35 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -1948,6 +1948,25 @@ bad:
return 0;
}
+/*
+ * Verify that a environment variable name (not including initial '$') is
+ * valid; consisting of one or more alphanumeric or underscore characters only.
+ * Returns 1 on valid, 0 otherwise.
+ */
+int
+valid_env_name(const char *name)
+{
+ const char *cp;
+
+ if (name[0] == '\0')
+ return 0;
+ for (cp = name; *cp != '\0'; cp++) {
+ if (!isalnum((u_char)*cp) && *cp != '_')
+ return 0;
+ }
+ return 1;
+}
+
const char *
atoi_err(const char *nptr, int *val)
{