upstream: Expand path to ~/.ssh/rc rather than relying on it

being relative to the current directory, so that it'll still be found if the
shell startup changes its directory.  Since the path is potentially longer,
make the cmd buffer that uses it dynamically sized.  bz#3185, with & ok djm@

OpenBSD-Commit-ID: 36e33ff01497af3dc8226d0c4c1526fc3a1e46bf
This commit is contained in:
dtucker@openbsd.org 2020-06-26 04:45:11 +00:00 committed by Damien Miller
parent 07f5f369a2
commit c9e24daac6
1 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: session.c,v 1.319 2020/03/13 03:17:07 djm Exp $ */
/* $OpenBSD: session.c,v 1.320 2020/06/26 04:45:11 dtucker Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@ -1206,19 +1206,21 @@ static void
do_rc_files(struct ssh *ssh, Session *s, const char *shell)
{
FILE *f = NULL;
char cmd[1024];
char *cmd = NULL, *user_rc = NULL;
int do_xauth;
struct stat st;
do_xauth =
s->display != NULL && s->auth_proto != NULL && s->auth_data != NULL;
user_rc = tilde_expand_filename("~/" _PATH_SSH_USER_RC, getuid());
/* ignore _PATH_SSH_USER_RC for subsystems and admin forced commands */
if (!s->is_subsystem && options.adm_forced_command == NULL &&
auth_opts->permit_user_rc && options.permit_user_rc &&
stat(_PATH_SSH_USER_RC, &st) >= 0) {
snprintf(cmd, sizeof cmd, "%s -c '%s %s'",
shell, _PATH_BSHELL, _PATH_SSH_USER_RC);
stat(user_rc, &st) >= 0) {
if (xasprintf(&cmd, "%s -c '%s %s'", shell, _PATH_BSHELL,
user_rc) == -1)
fatal("%s: xasprintf: %s", __func__, strerror(errno));
if (debug_flag)
fprintf(stderr, "Running %s\n", cmd);
f = popen(cmd, "w");
@ -1229,7 +1231,7 @@ do_rc_files(struct ssh *ssh, Session *s, const char *shell)
pclose(f);
} else
fprintf(stderr, "Could not run %s\n",
_PATH_SSH_USER_RC);
user_rc);
} else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) {
if (debug_flag)
fprintf(stderr, "Running %s %s\n", _PATH_BSHELL,
@ -1254,8 +1256,8 @@ do_rc_files(struct ssh *ssh, Session *s, const char *shell)
options.xauth_location, s->auth_display,
s->auth_proto, s->auth_data);
}
snprintf(cmd, sizeof cmd, "%s -q -",
options.xauth_location);
if (xasprintf(&cmd, "%s -q -", options.xauth_location) == -1)
fatal("%s: xasprintf: %s", __func__, strerror(errno));
f = popen(cmd, "w");
if (f) {
fprintf(f, "remove %s\n",
@ -1269,6 +1271,8 @@ do_rc_files(struct ssh *ssh, Session *s, const char *shell)
cmd);
}
}
free(cmd);
free(user_rc);
}
static void