diff options
author | Dario Lombardo <lomato@gmail.com> | 2016-08-31 10:14:33 +0200 |
---|---|---|
committer | Dario Lombardo <lomato@gmail.com> | 2016-09-16 14:21:16 +0000 |
commit | d67c1db3f2b16185d7cff250e098f48d94883f0e (patch) | |
tree | f111269e33ea8b0ac29532c18e2ce16762f4f515 /extcap | |
parent | 2492fe41ba165738aa8667ebfe7f9e96f69ef350 (diff) |
extcap: make extcap use the ws_strtoi/u functions.
Change-Id: Id75c72eba869c8a0f413ce8b5d6329ce172aed1f
Reviewed-on: https://code.wireshark.org/review/17415
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Roland Knall <rknall@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Diffstat (limited to 'extcap')
-rw-r--r-- | extcap/androiddump.c | 18 | ||||
-rw-r--r-- | extcap/ciscodump.c | 23 | ||||
-rw-r--r-- | extcap/randpktdump.c | 14 | ||||
-rw-r--r-- | extcap/ssh-base.c | 2 | ||||
-rw-r--r-- | extcap/ssh-base.h | 4 | ||||
-rw-r--r-- | extcap/sshdump.c | 23 |
6 files changed, 53 insertions, 31 deletions
diff --git a/extcap/androiddump.c b/extcap/androiddump.c index 896142d31b..b92c1705fc 100644 --- a/extcap/androiddump.c +++ b/extcap/androiddump.c @@ -30,6 +30,7 @@ #include <string.h> #include <errno.h> #include <time.h> +#include <wsutil/strtoi.h> #ifdef HAVE_NETINET_IN_H # include <netinet/in.h> @@ -438,7 +439,7 @@ static socket_handle_t adb_connect(const char *server_ip, unsigned short *server static char *adb_send_and_receive(socket_handle_t sock, const char *adb_service, char *buffer, int buffer_length, gssize *data_length) { gssize used_buffer_length; - gssize length; + gint32 length; gssize result; char status[4]; char tmp_buffer; @@ -2587,7 +2588,10 @@ int main(int argc, char **argv) { g_warning("Impossible exception. Parameter required argument, but there is no it right now."); goto end; } - *adb_server_tcp_port = (unsigned short) g_ascii_strtoull(optarg, NULL, 10); + if (!ws_strtou16(optarg, NULL, adb_server_tcp_port)) { + g_warning("Invalid adb server TCP port: %s", optarg); + goto end; + } break; case OPT_CONFIG_LOGCAT_TEXT: logcat_text = (g_ascii_strncasecmp(optarg, "TRUE", 4) == 0); @@ -2598,7 +2602,10 @@ int main(int argc, char **argv) { g_warning("Impossible exception. Parameter required argument, but there is no it right now."); goto end; } - *bt_server_tcp_port = (unsigned short) g_ascii_strtoull(optarg, NULL, 10); + if (!ws_strtou16(optarg, NULL, bt_server_tcp_port)) { + g_warning("Invalid bluetooth server TCP port: %s", optarg); + goto end; + } break; case OPT_CONFIG_BT_FORWARD_SOCKET: bt_forward_socket = (g_ascii_strncasecmp(optarg, "TRUE", 4) == 0); @@ -2612,7 +2619,10 @@ int main(int argc, char **argv) { g_warning("Impossible exception. Parameter required argument, but there is no it right now."); goto end; } - *bt_local_tcp_port = (unsigned short) g_ascii_strtoull(optarg, NULL, 10); + if (!ws_strtou16(optarg, NULL, bt_local_tcp_port)) { + g_warning("Invalid bluetooth local tcp port: %s", optarg); + goto end; + } break; default: if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg)) diff --git a/extcap/ciscodump.c b/extcap/ciscodump.c index eae0edb90d..159b8d334f 100644 --- a/extcap/ciscodump.c +++ b/extcap/ciscodump.c @@ -26,6 +26,7 @@ #include <extcap/extcap-base.h> #include <wsutil/interface.h> +#include <wsutil/strtoi.h> #include <extcap/ssh-base.h> #include <writecap/pcapio.h> @@ -153,7 +154,7 @@ static void ciscodump_cleanup(ssh_session sshs, ssh_channel channel, const char* ssh_cleanup(&sshs, &channel); } -static int wait_until_data(ssh_channel channel, const long unsigned count) +static int wait_until_data(ssh_channel channel, const guint32 count) { long unsigned got = 0; char output[SSH_READ_BLOCK_SIZE]; @@ -226,7 +227,7 @@ static int parse_line(char* packet _U_, unsigned* offset, char* line, int status return CISCODUMP_PARSER_IN_PACKET; } -static void ssh_loop_read(ssh_channel channel, FILE* fp, const long unsigned count) +static void ssh_loop_read(ssh_channel channel, FILE* fp, const guint32 count) { char line[SSH_READ_BLOCK_SIZE]; char chr; @@ -308,7 +309,7 @@ static int check_ios_version(ssh_channel channel) return FALSE; } -static ssh_channel run_capture(ssh_session sshs, const char* iface, const char* cfilter, const unsigned long int count) +static ssh_channel run_capture(ssh_session sshs, const char* iface, const char* cfilter, const guint32 count) { char* cmdline = NULL; ssh_channel channel; @@ -339,7 +340,7 @@ static ssh_channel run_capture(ssh_session sshs, const char* iface, const char* if (ssh_channel_printf(channel, "monitor capture buffer %s max-size 9500\n", WIRESHARK_CAPTURE_BUFFER) == EXIT_FAILURE) goto error; - if (ssh_channel_printf(channel, "monitor capture buffer %s limit packet-count %lu\n", WIRESHARK_CAPTURE_BUFFER, count) == EXIT_FAILURE) + if (ssh_channel_printf(channel, "monitor capture buffer %s limit packet-count %u\n", WIRESHARK_CAPTURE_BUFFER, count) == EXIT_FAILURE) goto error; if (cfilter) { @@ -412,7 +413,7 @@ error: static int ssh_open_remote_connection(const char* hostname, const unsigned int port, const char* username, const char* password, const char* sshkey, const char* sshkey_passphrase, const char* iface, const char* cfilter, - const unsigned long int count, const char* fifo) + const guint32 count, const char* fifo) { ssh_session sshs; ssh_channel channel; @@ -520,14 +521,14 @@ int main(int argc, char **argv) int option_idx = 0; int i; char* remote_host = NULL; - unsigned int remote_port = 22; + guint16 remote_port = 22; char* remote_username = NULL; char* remote_password = NULL; char* remote_interface = NULL; char* sshkey = NULL; char* sshkey_passphrase = NULL; char* remote_filter = NULL; - unsigned long int count = 0; + guint32 count = 0; int ret = EXIT_FAILURE; extcap_parameters * extcap_conf = g_new0(extcap_parameters, 1); char* help_header = NULL; @@ -597,8 +598,7 @@ int main(int argc, char **argv) break; case OPT_REMOTE_PORT: - remote_port = (unsigned int)strtoul(optarg, NULL, 10); - if (remote_port > 65535 || remote_port == 0) { + if (!ws_strtou16(optarg, NULL, &remote_port) || remote_port == 0) { g_warning("Invalid port: %s", optarg); goto end; } @@ -637,7 +637,10 @@ int main(int argc, char **argv) break; case OPT_REMOTE_COUNT: - count = strtoul(optarg, NULL, 10); + if (!ws_strtou32(optarg, NULL, &count)) { + g_warning("Invalid packet count: %s", optarg); + goto end; + } break; case ':': diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c index 974f7f3947..16e4edec09 100644 --- a/extcap/randpktdump.c +++ b/extcap/randpktdump.c @@ -27,6 +27,7 @@ #include "extcap-base.h" #include "randpkt_core/randpkt_core.h" +#include <wsutil/strtoi.h> #define RANDPKT_EXTCAP_INTERFACE "randpkt" #define RANDPKTDUMP_VERSION_MAJOR "0" @@ -126,7 +127,7 @@ int main(int argc, char *argv[]) { int option_idx = 0; int result; - int maxbytes = 5000; + guint16 maxbytes = 5000; guint64 count = 1000; int random_type = FALSE; int all_random = FALSE; @@ -192,15 +193,18 @@ int main(int argc, char *argv[]) goto end; case OPT_MAXBYTES: - maxbytes = atoi(optarg); - if (maxbytes > MAXBYTES_LIMIT) { - g_warning("randpktdump: Max bytes is %d", MAXBYTES_LIMIT); + if (!ws_strtou16(optarg, NULL, &maxbytes)) { + g_warning("Invalid parameter maxbytes: %s (max value is %u)", + optarg, G_MAXUINT16); goto end; } break; case OPT_COUNT: - count = g_ascii_strtoull(optarg, NULL, 10); + if (!ws_strtou64(optarg, NULL, &count)) { + g_warning("Invalid packet count: %s", optarg); + goto end; + } break; case OPT_RANDOM_TYPE: diff --git a/extcap/ssh-base.c b/extcap/ssh-base.c index f9856c164d..aabf2a8528 100644 --- a/extcap/ssh-base.c +++ b/extcap/ssh-base.c @@ -30,7 +30,7 @@ #include <log.h> #include <string.h> -ssh_session create_ssh_connection(const char* hostname, const unsigned int port, const char* username, +ssh_session create_ssh_connection(const char* hostname, const guint16 port, const char* username, const char* password, const char* sshkey_path, const char* sshkey_passphrase, char** err_info) { ssh_session sshs; diff --git a/extcap/ssh-base.h b/extcap/ssh-base.h index 28a4b08acb..d407d309e8 100644 --- a/extcap/ssh-base.h +++ b/extcap/ssh-base.h @@ -27,6 +27,8 @@ #include <libssh/libssh.h> +#include <glib.h> + #ifndef STDERR_FILENO #define STDERR_FILENO 2 #endif @@ -47,7 +49,7 @@ { "sshkey-passphrase", required_argument, NULL, OPT_SSHKEY_PASSPHRASE} /* Create a ssh connection using all the possible authentication menthods */ -ssh_session create_ssh_connection(const char* hostname, const unsigned int port, const char* username, +ssh_session create_ssh_connection(const char* hostname, const guint16 port, const char* username, const char* password, const char* sshkey_path, const char* sshkey_passphrase, char** err_info); /* Write a formatted message in the channel */ diff --git a/extcap/sshdump.c b/extcap/sshdump.c index f5173c381e..9e1752cb3f 100644 --- a/extcap/sshdump.c +++ b/extcap/sshdump.c @@ -25,9 +25,10 @@ #include "config.h" #include <extcap/extcap-base.h> +#include <extcap/ssh-base.h> #include <wsutil/interface.h> #include <wsutil/file_util.h> -#include <extcap/ssh-base.h> +#include <wsutil/strtoi.h> #include <errno.h> #include <string.h> @@ -95,7 +96,7 @@ static void ssh_loop_read(ssh_channel channel, int fd) return; } -static char* local_interfaces_to_filter(const unsigned int remote_port) +static char* local_interfaces_to_filter(const guint16 remote_port) { GSList* interfaces = local_interfaces_to_list(); char* filter = interfaces_list_to_filter(interfaces, remote_port); @@ -104,7 +105,7 @@ static char* local_interfaces_to_filter(const unsigned int remote_port) } static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_bin, const char* iface, const char* cfilter, - unsigned long int count) + const guint32 count) { gchar* cmdline; ssh_channel channel; @@ -140,7 +141,7 @@ static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_bin, co cfilter = default_filter; quoted_filter = g_shell_quote(cfilter); if (count > 0) - count_str = g_strdup_printf("-c %lu", count); + count_str = g_strdup_printf("-c %u", count); cmdline = g_strdup_printf("%s -i %s -w - -f %s %s", quoted_bin, quoted_iface, quoted_filter, count_str ? count_str : ""); @@ -165,7 +166,7 @@ static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_bin, co static int ssh_open_remote_connection(const char* hostname, const unsigned int port, const char* username, const char* password, 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) + const guint32 count, const char* fifo) { ssh_session sshs = NULL; ssh_channel channel = NULL; @@ -307,7 +308,7 @@ int main(int argc, char **argv) int option_idx = 0; int i; char* remote_host = NULL; - unsigned int remote_port = 22; + guint16 remote_port = 22; char* remote_username = NULL; char* remote_password = NULL; char* remote_interface = NULL; @@ -315,7 +316,7 @@ int main(int argc, char **argv) char* sshkey = NULL; char* sshkey_passphrase = NULL; char* remote_filter = NULL; - unsigned long int count = 0; + guint32 count = 0; int ret = EXIT_FAILURE; extcap_parameters * extcap_conf = g_new0(extcap_parameters, 1); char* help_header = NULL; @@ -381,8 +382,7 @@ int main(int argc, char **argv) break; case OPT_REMOTE_PORT: - remote_port = (unsigned int)strtoul(optarg, NULL, 10); - if (remote_port > 65535 || remote_port == 0) { + if (!ws_strtou16(optarg, NULL, &remote_port) || remote_port == 0) { g_warning("Invalid port: %s", optarg); goto end; } @@ -426,7 +426,10 @@ int main(int argc, char **argv) break; case OPT_REMOTE_COUNT: - count = strtoul(optarg, NULL, 10); + if (!ws_strtou32(optarg, NULL, &count)) { + g_warning("Invalid value for count: %s", optarg); + goto end; + } break; case ':': |