aboutsummaryrefslogtreecommitdiffstats
path: root/extcap/sshdump.c
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-03-28 17:50:28 +0200
committerRoland Knall <rknall@gmail.com>2016-03-29 06:01:31 +0000
commit0aa0fb25e048c1d9abca03a8a1681b99ddcc7410 (patch)
tree9ff3e8bada67da033c6d1e6c839d845af696474b /extcap/sshdump.c
parent24768a7147b27daba28e2e88c333f0826724fe80 (diff)
Another round of extcap memleak fixes
Fix a bunch of memory leaks, mainly because extcap_base_cleanup is not called on most execution paths and because memory allocated for options were not freed. Additionally, randpkt will now fail if no option is given (it previously returned 0 if --capture was missing). Logic using "goto" is introduced with the idea that a program should fail (ret = EXIT_FAILURE) unless proven otherwise. Now none of the extcap programs are leaking: for what in ssh cisco; do for arg in '' --help --extcap-interfaces --extcap-interface=$what; do extcap/${what}dump $arg; done; done ./tshark -D Change-Id: I6df1027ed0c32bd53fe87e6c54d355bc8ddd01f5 Reviewed-on: https://code.wireshark.org/review/14671 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'extcap/sshdump.c')
-rw-r--r--extcap/sshdump.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/extcap/sshdump.c b/extcap/sshdump.c
index 92c6a0f4fd..77dc11ad04 100644
--- a/extcap/sshdump.c
+++ b/extcap/sshdump.c
@@ -361,7 +361,7 @@ int main(int argc, char **argv)
char* sshkey_passphrase = NULL;
char* remote_filter = NULL;
unsigned long int count = 0;
- int ret = 0;
+ int ret = EXIT_FAILURE;
extcap_parameters * extcap_conf = g_new0(extcap_parameters, 1);
#ifdef _WIN32
@@ -378,7 +378,7 @@ int main(int argc, char **argv)
if (argc == 1) {
help(argv[0]);
- return EXIT_FAILURE;
+ goto end;
}
for (i = 0; i < argc; i++) {
@@ -392,7 +392,8 @@ int main(int argc, char **argv)
case OPT_HELP:
help(argv[0]);
- return EXIT_SUCCESS;
+ ret = EXIT_SUCCESS;
+ goto end;
case OPT_VERBOSE:
verbose = TRUE;
@@ -400,11 +401,11 @@ int main(int argc, char **argv)
case OPT_VERSION:
printf("%s.%s.%s\n", SSHDUMP_VERSION_MAJOR, SSHDUMP_VERSION_MINOR, SSHDUMP_VERSION_RELEASE);
- return EXIT_SUCCESS;
+ ret = EXIT_SUCCESS;
+ goto end;
case OPT_REMOTE_HOST:
- if (remote_host)
- g_free(remote_host);
+ g_free(remote_host);
remote_host = g_strdup(optarg);
break;
@@ -412,51 +413,44 @@ int main(int argc, char **argv)
remote_port = (unsigned int)strtoul(optarg, NULL, 10);
if (remote_port > 65535 || remote_port == 0) {
errmsg_print("Invalid port: %s", optarg);
- return EXIT_FAILURE;
+ goto end;
}
break;
case OPT_REMOTE_USERNAME:
- if (remote_username)
- g_free(remote_username);
+ g_free(remote_username);
remote_username = g_strdup(optarg);
break;
case OPT_REMOTE_PASSWORD:
- if (remote_password)
- g_free(remote_password);
+ g_free(remote_password);
remote_password = g_strdup(optarg);
memset(optarg, 'X', strlen(optarg));
break;
case OPT_SSHKEY:
- if (sshkey)
- g_free(sshkey);
+ g_free(sshkey);
sshkey = g_strdup(optarg);
break;
case OPT_SSHKEY_PASSPHRASE:
- if (sshkey_passphrase)
- g_free(sshkey_passphrase);
+ g_free(sshkey_passphrase);
sshkey_passphrase = g_strdup(optarg);
memset(optarg, 'X', strlen(optarg));
break;
case OPT_REMOTE_INTERFACE:
- if (remote_interface)
- g_free(remote_interface);
+ g_free(remote_interface);
remote_interface = g_strdup(optarg);
break;
case OPT_REMOTE_CAPTURE_BIN:
- if (remote_capture_bin)
- g_free(remote_capture_bin);
+ g_free(remote_capture_bin);
remote_capture_bin = g_strdup(optarg);
break;
case OPT_REMOTE_FILTER:
- if (remote_filter)
- g_free(remote_filter);
+ g_free(remote_filter);
remote_filter = g_strdup(optarg);
break;
@@ -472,28 +466,32 @@ int main(int argc, char **argv)
default:
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg)) {
errmsg_print("Invalid option: %s", argv[optind - 1]);
- return EXIT_FAILURE;
+ goto end;
}
}
}
if (optind != argc) {
errmsg_print("Unexpected extra option: %s", argv[optind]);
- return EXIT_FAILURE;
+ goto end;
}
- if (extcap_base_handle_interface(extcap_conf))
- return EXIT_SUCCESS;
+ if (extcap_base_handle_interface(extcap_conf)) {
+ ret = EXIT_SUCCESS;
+ goto end;
+ }
- if (extcap_conf->show_config)
- return list_config(extcap_conf->interface, remote_port);
+ if (extcap_conf->show_config) {
+ ret = list_config(extcap_conf->interface, remote_port);
+ goto end;
+ }
#ifdef _WIN32
result = WSAStartup(MAKEWORD(1,1), &wsaData);
if (result != 0) {
if (verbose)
errmsg_print("ERROR: WSAStartup failed with error: %d", result);
- return EXIT_FAILURE;
+ goto end;
}
#endif /* _WIN32 */
@@ -502,7 +500,7 @@ int main(int argc, char **argv)
if (!remote_host) {
errmsg_print("Missing parameter: --remote-host");
- return EXIT_FAILURE;
+ goto end;
}
filter = concat_filters(extcap_conf->capture_filter, remote_filter);
ret = ssh_open_remote_connection(remote_host, remote_port, remote_username,
@@ -514,7 +512,16 @@ int main(int argc, char **argv)
ret = EXIT_FAILURE;
}
+end:
/* clean up stuff */
+ g_free(remote_host);
+ g_free(remote_username);
+ g_free(remote_password);
+ g_free(remote_interface);
+ g_free(remote_capture_bin);
+ g_free(sshkey);
+ g_free(sshkey_passphrase);
+ g_free(remote_filter);
extcap_base_cleanup(&extcap_conf);
return ret;
}