summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2018-07-09 21:03:30 +0000
committerDamien Miller <djm@mindrot.org>2018-07-10 15:14:26 +1000
commitcecee2d607099a7bba0a84803e2325d15be4277b (patch)
treee5f685fb39c9d8512235334afc4b26e8461bfc36 /ssh.c
parentff55f4ad898137d4703e7a2bcc81167dfe8e9324 (diff)
upstream: client: switch to sshbuf API; ok djm@
OpenBSD-Commit-ID: 60cb0356114acc7625ab85105f6f6a7cd44a8d05
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/ssh.c b/ssh.c
index fe3e1a83a..914167789 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.481 2018/06/08 03:35:36 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.482 2018/07/09 21:03:30 markus 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
@@ -87,7 +87,7 @@
87#include "cipher.h" 87#include "cipher.h"
88#include "digest.h" 88#include "digest.h"
89#include "packet.h" 89#include "packet.h"
90#include "buffer.h" 90#include "sshbuf.h"
91#include "channels.h" 91#include "channels.h"
92#include "key.h" 92#include "key.h"
93#include "authfd.h" 93#include "authfd.h"
@@ -183,7 +183,7 @@ uid_t original_real_uid;
183uid_t original_effective_uid; 183uid_t original_effective_uid;
184 184
185/* command to be executed */ 185/* command to be executed */
186Buffer command; 186struct sshbuf *command;
187 187
188/* Should we execute a command or invoke a subsystem? */ 188/* Should we execute a command or invoke a subsystem? */
189int subsystem_flag = 0; 189int subsystem_flag = 0;
@@ -1042,7 +1042,8 @@ main(int ac, char **av)
1042#endif 1042#endif
1043 1043
1044 /* Initialize the command to execute on remote host. */ 1044 /* Initialize the command to execute on remote host. */
1045 buffer_init(&command); 1045 if ((command = sshbuf_new()) == NULL)
1046 fatal("sshbuf_new failed");
1046 1047
1047 /* 1048 /*
1048 * Save the command to execute on the remote host in a buffer. There 1049 * Save the command to execute on the remote host in a buffer. There
@@ -1059,9 +1060,10 @@ main(int ac, char **av)
1059 } else { 1060 } else {
1060 /* A command has been specified. Store it into the buffer. */ 1061 /* A command has been specified. Store it into the buffer. */
1061 for (i = 0; i < ac; i++) { 1062 for (i = 0; i < ac; i++) {
1062 if (i) 1063 if ((r = sshbuf_putf(command, "%s%s",
1063 buffer_append(&command, " ", 1); 1064 i ? " " : "", av[i])) != 0)
1064 buffer_append(&command, av[i], strlen(av[i])); 1065 fatal("%s: buffer error: %s",
1066 __func__, ssh_err(r));
1065 } 1067 }
1066 } 1068 }
1067 1069
@@ -1234,11 +1236,11 @@ main(int ac, char **av)
1234 options.use_privileged_port = 0; 1236 options.use_privileged_port = 0;
1235#endif 1237#endif
1236 1238
1237 if (buffer_len(&command) != 0 && options.remote_command != NULL) 1239 if (sshbuf_len(command) != 0 && options.remote_command != NULL)
1238 fatal("Cannot execute command-line and remote command."); 1240 fatal("Cannot execute command-line and remote command.");
1239 1241
1240 /* Cannot fork to background if no command. */ 1242 /* Cannot fork to background if no command. */
1241 if (fork_after_authentication_flag && buffer_len(&command) == 0 && 1243 if (fork_after_authentication_flag && sshbuf_len(command) == 0 &&
1242 options.remote_command == NULL && !no_shell_flag) 1244 options.remote_command == NULL && !no_shell_flag)
1243 fatal("Cannot fork into background without a command " 1245 fatal("Cannot fork into background without a command "
1244 "to execute."); 1246 "to execute.");
@@ -1251,7 +1253,7 @@ main(int ac, char **av)
1251 tty_flag = 1; 1253 tty_flag = 1;
1252 1254
1253 /* Allocate a tty by default if no command specified. */ 1255 /* Allocate a tty by default if no command specified. */
1254 if (buffer_len(&command) == 0 && options.remote_command == NULL) 1256 if (sshbuf_len(command) == 0 && options.remote_command == NULL)
1255 tty_flag = options.request_tty != REQUEST_TTY_NO; 1257 tty_flag = options.request_tty != REQUEST_TTY_NO;
1256 1258
1257 /* Force no tty */ 1259 /* Force no tty */
@@ -1313,8 +1315,9 @@ main(int ac, char **av)
1313 (char *)NULL); 1315 (char *)NULL);
1314 debug3("expanded RemoteCommand: %s", options.remote_command); 1316 debug3("expanded RemoteCommand: %s", options.remote_command);
1315 free(cp); 1317 free(cp);
1316 buffer_append(&command, options.remote_command, 1318 if ((r = sshbuf_put(command, options.remote_command,
1317 strlen(options.remote_command)); 1319 strlen(options.remote_command))) != 0)
1320 fatal("%s: buffer error: %s", __func__, ssh_err(r));
1318 } 1321 }
1319 1322
1320 if (options.control_path != NULL) { 1323 if (options.control_path != NULL) {
@@ -1846,7 +1849,7 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg)
1846 options.ip_qos_interactive, options.ip_qos_bulk); 1849 options.ip_qos_interactive, options.ip_qos_bulk);
1847 1850
1848 client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"), 1851 client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"),
1849 NULL, fileno(stdin), &command, environ); 1852 NULL, fileno(stdin), command, environ);
1850} 1853}
1851 1854
1852/* open new channel for a session */ 1855/* open new channel for a session */