summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auth-options.c17
-rw-r--r--misc.c21
-rw-r--r--misc.h3
-rw-r--r--readconf.c15
-rw-r--r--ssh.c24
-rw-r--r--ssh_config.58
6 files changed, 72 insertions, 16 deletions
diff --git a/auth-options.c b/auth-options.c
index 27c0eb05e..b05d6d6f3 100644
--- a/auth-options.c
+++ b/auth-options.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth-options.c,v 1.83 2018/06/19 02:59:41 djm Exp $ */ 1/* $OpenBSD: auth-options.c,v 1.84 2018/10/03 06:38:35 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2018 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -469,13 +469,16 @@ sshauthopt_parse(const char *opts, const char **errstrp)
469 errstr = "invalid environment string"; 469 errstr = "invalid environment string";
470 goto fail; 470 goto fail;
471 } 471 }
472 for (cp = opt; cp < tmp; cp++) { 472 if ((cp = strdup(opt)) == NULL)
473 if (!isalnum((u_char)*cp) && *cp != '_') { 473 goto alloc_fail;
474 free(opt); 474 cp[tmp - opt] = '\0'; /* truncate at '=' */
475 errstr = "invalid environment string"; 475 if (!valid_env_name(cp)) {
476 goto fail; 476 free(cp);
477 } 477 free(opt);
478 errstr = "invalid environment string";
479 goto fail;
478 } 480 }
481 free(cp);
479 /* Append it. */ 482 /* Append it. */
480 oarray = ret->env; 483 oarray = ret->env;
481 if ((ret->env = recallocarray(ret->env, ret->nenv, 484 if ((ret->env = recallocarray(ret->env, ret->nenv,
diff --git a/misc.c b/misc.c
index ae4d29b84..c4ca12560 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.131 2018/07/27 05:13:02 dtucker Exp $ */ 1/* $OpenBSD: misc.c,v 1.132 2018/10/03 06:38:35 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -1948,6 +1948,25 @@ bad:
1948 return 0; 1948 return 0;
1949} 1949}
1950 1950
1951/*
1952 * Verify that a environment variable name (not including initial '$') is
1953 * valid; consisting of one or more alphanumeric or underscore characters only.
1954 * Returns 1 on valid, 0 otherwise.
1955 */
1956int
1957valid_env_name(const char *name)
1958{
1959 const char *cp;
1960
1961 if (name[0] == '\0')
1962 return 0;
1963 for (cp = name; *cp != '\0'; cp++) {
1964 if (!isalnum((u_char)*cp) && *cp != '_')
1965 return 0;
1966 }
1967 return 1;
1968}
1969
1951const char * 1970const char *
1952atoi_err(const char *nptr, int *val) 1971atoi_err(const char *nptr, int *val)
1953{ 1972{
diff --git a/misc.h b/misc.h
index 6be289fd2..31b207a8d 100644
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.h,v 1.74 2018/07/27 05:13:02 dtucker Exp $ */ 1/* $OpenBSD: misc.h,v 1.75 2018/10/03 06:38:35 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -74,6 +74,7 @@ double monotime_double(void);
74void lowercase(char *s); 74void lowercase(char *s);
75int unix_listener(const char *, int, int); 75int unix_listener(const char *, int, int);
76int valid_domain(char *, int, const char **); 76int valid_domain(char *, int, const char **);
77int valid_env_name(const char *);
77const char *atoi_err(const char *, int *); 78const char *atoi_err(const char *, int *);
78int parse_absolute_time(const char *, uint64_t *); 79int parse_absolute_time(const char *, uint64_t *);
79void format_absolute_time(uint64_t, char *, size_t); 80void format_absolute_time(uint64_t, char *, size_t);
diff --git a/readconf.c b/readconf.c
index 057726d0e..d39cfa3c5 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.298 2018/09/20 03:30:44 djm Exp $ */ 1/* $OpenBSD: readconf.c,v 1.299 2018/10/03 06:38:35 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1700,7 +1700,18 @@ parse_keytypes:
1700 1700
1701 case oIdentityAgent: 1701 case oIdentityAgent:
1702 charptr = &options->identity_agent; 1702 charptr = &options->identity_agent;
1703 goto parse_string; 1703 arg = strdelim(&s);
1704 if (!arg || *arg == '\0')
1705 fatal("%.200s line %d: Missing argument.",
1706 filename, linenum);
1707 /* Extra validation if the string represents an env var. */
1708 if (arg[0] == '$' && !valid_env_name(arg + 1)) {
1709 fatal("%.200s line %d: Invalid environment name %s.",
1710 filename, linenum, arg);
1711 }
1712 if (*activep && *charptr == NULL)
1713 *charptr = xstrdup(arg);
1714 break;
1704 1715
1705 case oDeprecated: 1716 case oDeprecated:
1706 debug("%s line %d: Deprecated option \"%s\"", 1717 debug("%s line %d: Deprecated option \"%s\"",
diff --git a/ssh.c b/ssh.c
index 849fae355..0777c31e4 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.493 2018/09/21 03:11:36 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.494 2018/10/03 06:38:35 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1453,9 +1453,27 @@ main(int ac, char **av)
1453 "r", options.user, 1453 "r", options.user,
1454 "u", pw->pw_name, 1454 "u", pw->pw_name,
1455 (char *)NULL); 1455 (char *)NULL);
1456 setenv(SSH_AUTHSOCKET_ENV_NAME, cp, 1);
1457 free(cp);
1458 free(p); 1456 free(p);
1457 /*
1458 * If identity_agent represents an environment variable
1459 * then recheck that it is valid (since processing with
1460 * percent_expand() may have changed it) and substitute
1461 * its value.
1462 */
1463 if (cp[0] == '$') {
1464 if (!valid_env_name(cp + 1)) {
1465 fatal("Invalid IdentityAgent "
1466 "environment variable name %s", cp);
1467 }
1468 if ((p = getenv(cp + 1)) == NULL)
1469 unsetenv(SSH_AUTHSOCKET_ENV_NAME);
1470 else
1471 setenv(SSH_AUTHSOCKET_ENV_NAME, p, 1);
1472 } else {
1473 /* identity_agent specifies a path directly */
1474 setenv(SSH_AUTHSOCKET_ENV_NAME, cp, 1);
1475 }
1476 free(cp);
1459 } 1477 }
1460 } 1478 }
1461 1479
diff --git a/ssh_config.5 b/ssh_config.5
index 27136dbd6..4d5b01d3e 100644
--- a/ssh_config.5
+++ b/ssh_config.5
@@ -33,8 +33,8 @@
33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: ssh_config.5,v 1.285 2018/09/21 12:46:22 djm Exp $ 36.\" $OpenBSD: ssh_config.5,v 1.286 2018/10/03 06:38:35 djm Exp $
37.Dd $Mdocdate: September 21 2018 $ 37.Dd $Mdocdate: October 3 2018 $
38.Dt SSH_CONFIG 5 38.Dt SSH_CONFIG 5
39.Os 39.Os
40.Sh NAME 40.Sh NAME
@@ -877,6 +877,10 @@ If the string
877is specified, the location of the socket will be read from the 877is specified, the location of the socket will be read from the
878.Ev SSH_AUTH_SOCK 878.Ev SSH_AUTH_SOCK
879environment variable. 879environment variable.
880Otherwise if the specified value begins with a
881.Sq $
882character, then it will be treated as an environment variable containing
883the location of the socket.
880.Pp 884.Pp
881Arguments to 885Arguments to
882.Cm IdentityAgent 886.Cm IdentityAgent