=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/session.c,v retrieving revision 1.319 retrieving revision 1.320 diff -u -r1.319 -r1.320 --- src/usr.bin/ssh/session.c 2020/03/13 03:17:07 1.319 +++ src/usr.bin/ssh/session.c 2020/06/26 04:45:11 1.320 @@ -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 , Espoo, Finland * All rights reserved @@ -966,19 +966,21 @@ 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"); @@ -989,7 +991,7 @@ 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, @@ -1014,8 +1016,8 @@ 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", @@ -1029,6 +1031,8 @@ cmd); } } + free(cmd); + free(user_rc); } static void