aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssh/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/misc.c')
-rw-r--r--crypto/openssh/misc.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/crypto/openssh/misc.c b/crypto/openssh/misc.c
index 1d89f99ac699..662d6bf48716 100644
--- a/crypto/openssh/misc.c
+++ b/crypto/openssh/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.133 2018/10/05 14:26:09 naddy Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -51,6 +51,7 @@
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
+#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
@@ -333,13 +334,16 @@ pwcopy(struct passwd *pw)
int
a2port(const char *s)
{
+ struct servent *se;
long long port;
const char *errstr;
port = strtonum(s, 0, 65535, &errstr);
- if (errstr != NULL)
- return -1;
- return (int)port;
+ if (errstr == NULL)
+ return (int)port;
+ if ((se = getservbyname(s, "tcp")) != NULL)
+ return ntohs(se->s_port);
+ return -1;
}
int
@@ -1949,6 +1953,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)
{