=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/clientloop.c,v retrieving revision 1.317 retrieving revision 1.318 diff -u -r1.317 -r1.318 --- src/usr.bin/ssh/clientloop.c 2018/07/11 18:53:29 1.317 +++ src/usr.bin/ssh/clientloop.c 2018/09/21 12:46:22 1.318 @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.317 2018/07/11 18:53:29 markus Exp $ */ +/* $OpenBSD: clientloop.c,v 1.318 2018/09/21 12:46:22 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -271,7 +271,7 @@ const char *xauth_path, u_int trusted, u_int timeout, char **_proto, char **_data) { - char cmd[1024], line[512], xdisplay[512]; + char *cmd, line[512], xdisplay[512]; char xauthfile[PATH_MAX], xauthdir[PATH_MAX]; static char proto[512], data[512]; FILE *f; @@ -335,19 +335,30 @@ return -1; } - if (timeout >= UINT_MAX - X11_TIMEOUT_SLACK) - x11_timeout_real = UINT_MAX; - else - x11_timeout_real = timeout + X11_TIMEOUT_SLACK; - if ((r = snprintf(cmd, sizeof(cmd), - "%s -f %s generate %s " SSH_X11_PROTO - " untrusted timeout %u 2>" _PATH_DEVNULL, - xauth_path, xauthfile, display, - x11_timeout_real)) < 0 || - (size_t)r >= sizeof(cmd)) - fatal("%s: cmd too long", __func__); + if (timeout == 0) { + /* auth doesn't time out */ + xasprintf(&cmd, "%s -f %s generate %s %s " + "untrusted 2>%s", + xauth_path, xauthfile, display, + SSH_X11_PROTO, _PATH_DEVNULL); + } else { + /* Add some slack to requested expiry */ + if (timeout < UINT_MAX - X11_TIMEOUT_SLACK) + x11_timeout_real = timeout + + X11_TIMEOUT_SLACK; + else { + /* Don't overflow on long timeouts */ + x11_timeout_real = UINT_MAX; + } + xasprintf(&cmd, "%s -f %s generate %s %s " + "untrusted timeout %u 2>%s", + xauth_path, xauthfile, display, + SSH_X11_PROTO, x11_timeout_real, + _PATH_DEVNULL); + } debug2("%s: %s", __func__, cmd); - if (x11_refuse_time == 0) { + + if (timeout != 0 && x11_refuse_time == 0) { now = monotime() + 1; if (UINT_MAX - timeout < now) x11_refuse_time = UINT_MAX; @@ -358,6 +369,7 @@ } if (system(cmd) == 0) generated = 1; + free(cmd); } /* @@ -366,7 +378,7 @@ * above. */ if (trusted || generated) { - snprintf(cmd, sizeof(cmd), + xasprintf(&cmd, "%s %s%s list %s 2>" _PATH_DEVNULL, xauth_path, generated ? "-f " : "" , @@ -379,6 +391,7 @@ got_data = 1; if (f) pclose(f); + free(cmd); } }