summaryrefslogtreecommitdiff
path: root/extcap/sshdump.c
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2016-01-21 10:08:02 +0100
committerAlexis La Goutte <alexis.lagoutte@gmail.com>2016-01-22 18:21:21 +0000
commit19d43a03b671bfe73ba65ef664cb9ebb71192644 (patch)
tree50ec350257cd31d0eb4b5172690dfaffb6225641 /extcap/sshdump.c
parentc2606407526080b56a21c9a2fb3c07daea0dc808 (diff)
downloadwireshark-19d43a03b671bfe73ba65ef664cb9ebb71192644.tar.gz
sshdump: fix leak in ssh_open_remote_connection() (CID 1349731)
Change-Id: I55656d4600edb800fd93532345f7ea2c7fc16f7d Reviewed-on: https://code.wireshark.org/review/13466 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'extcap/sshdump.c')
-rw-r--r--extcap/sshdump.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/extcap/sshdump.c b/extcap/sshdump.c
index 63eb3e3f25..a160bde10e 100644
--- a/extcap/sshdump.c
+++ b/extcap/sshdump.c
@@ -364,14 +364,12 @@ static int ssh_open_remote_connection(const char* hostname, const unsigned int p
const char* sshkey, const char* sshkey_passphrase, const char* iface, const char* cfilter, const char* capture_bin,
const unsigned long int count, const char* fifo)
{
- ssh_session sshs;
- ssh_channel channel;
- int fd;
+ ssh_session sshs = NULL;
+ ssh_channel channel = NULL;
+ int fd = STDOUT_FILENO;
+ int ret = EXIT_FAILURE;
- if (!g_strcmp0(fifo, "-")) {
- /* use stdout */
- fd = STDOUT_FILENO;
- } else {
+ if (g_strcmp0(fifo, "-")) {
/* Open or create the output file */
fd = open(fifo, O_WRONLY);
if (fd == -1) {
@@ -386,19 +384,23 @@ static int ssh_open_remote_connection(const char* hostname, const unsigned int p
sshs = create_ssh_connection(hostname, port, username, password, sshkey, sshkey_passphrase);
if (!sshs)
- return EXIT_FAILURE;
+ goto cleanup;
channel = run_ssh_command(sshs, capture_bin, iface, cfilter, count);
if (!channel)
- return EXIT_FAILURE;
+ goto cleanup;
/* read from channel and write into fd */
ssh_loop_read(channel, fd);
+ ret = EXIT_SUCCESS;
+cleanup:
/* clean up and exit */
ssh_cleanup(sshs, channel);
- return EXIT_SUCCESS;
+ if (g_strcmp0(fifo, "-"))
+ close(fd);
+ return ret;
}
static void help(const char* binname)