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 fe3e1a83..91416778 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.481 2018/06/08 03:35:36 djm Exp $ */
+/* $OpenBSD: ssh.c,v 1.482 2018/07/09 21:03:30 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -87,7 +87,7 @@
#include "cipher.h"
#include "digest.h"
#include "packet.h"
-#include "buffer.h"
+#include "sshbuf.h"
#include "channels.h"
#include "key.h"
#include "authfd.h"
@@ -183,7 +183,7 @@ uid_t original_real_uid;
uid_t original_effective_uid;
/* command to be executed */
-Buffer command;
+struct sshbuf *command;
/* Should we execute a command or invoke a subsystem? */
int subsystem_flag = 0;
@@ -1042,7 +1042,8 @@ main(int ac, char **av)
#endif
/* Initialize the command to execute on remote host. */
- buffer_init(&command);
+ if ((command = sshbuf_new()) == NULL)
+ fatal("sshbuf_new failed");
/*
* Save the command to execute on the remote host in a buffer. There
@@ -1059,9 +1060,10 @@ main(int ac, char **av)
} else {
/* A command has been specified. Store it into the buffer. */
for (i = 0; i < ac; i++) {
- if (i)
- buffer_append(&command, " ", 1);
- buffer_append(&command, av[i], strlen(av[i]));
+ if ((r = sshbuf_putf(command, "%s%s",
+ i ? " " : "", av[i])) != 0)
+ fatal("%s: buffer error: %s",
+ __func__, ssh_err(r));
}
}
@@ -1234,11 +1236,11 @@ main(int ac, char **av)
options.use_privileged_port = 0;
#endif
- if (buffer_len(&command) != 0 && options.remote_command != NULL)
+ if (sshbuf_len(command) != 0 && options.remote_command != NULL)
fatal("Cannot execute command-line and remote command.");
/* Cannot fork to background if no command. */
- if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
+ if (fork_after_authentication_flag && sshbuf_len(command) == 0 &&
options.remote_command == NULL && !no_shell_flag)
fatal("Cannot fork into background without a command "
"to execute.");
@@ -1251,7 +1253,7 @@ main(int ac, char **av)
tty_flag = 1;
/* Allocate a tty by default if no command specified. */
- if (buffer_len(&command) == 0 && options.remote_command == NULL)
+ if (sshbuf_len(command) == 0 && options.remote_command == NULL)
tty_flag = options.request_tty != REQUEST_TTY_NO;
/* Force no tty */
@@ -1313,8 +1315,9 @@ main(int ac, char **av)
(char *)NULL);
debug3("expanded RemoteCommand: %s", options.remote_command);
free(cp);
- buffer_append(&command, options.remote_command,
- strlen(options.remote_command));
+ if ((r = sshbuf_put(command, options.remote_command,
+ strlen(options.remote_command))) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
}
if (options.control_path != NULL) {
@@ -1846,7 +1849,7 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg)
options.ip_qos_interactive, options.ip_qos_bulk);
client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"),
- NULL, fileno(stdin), &command, environ);
+ NULL, fileno(stdin), command, environ);
}
/* open new channel for a session */