cli: use ws_strtou function.
authorDario Lombardo <lomato@gmail.com>
Fri, 9 Sep 2016 14:41:15 +0000 (16:41 +0200)
committerPeter Wu <peter@lekensteyn.nl>
Thu, 15 Sep 2016 21:38:43 +0000 (21:38 +0000)
Change-Id: Ic358c50aa21dac485348ee5f7af8947f75e4f952
Reviewed-on: https://code.wireshark.org/review/17611
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
ui/cli/tap-diameter-avp.c

index 02106cd9f4aecabb5f6f1ec4547aeaa83c5150a2..4251c2562c03e6c54b567c317cff22d4fc5cf818 100644 (file)
@@ -42,6 +42,8 @@
 
 #include <glib.h>
 
+#include <wsutil/strtoi.h>
+
 #include <epan/packet_info.h>
 #include <epan/tap.h>
 #include <epan/epan_dissect.h>
@@ -238,8 +240,16 @@ diameteravp_init(const char *opt_arg, void *userdata _U_)
        opt_count = 0;
        while (tokens[opt_count])
                opt_count++;
-       if (opt_count > 2)
-               ds->cmd_code = (guint32)atoi(tokens[2]);
+       if (opt_count > 2) {
+               /* if the token is a not-null string and it's not *, the conversion must succeeed */
+               if (strlen(tokens[2]) > 0 && tokens[2][0] != '*') {
+                       if (!ws_strtou32(tokens[2], NULL, &ds->cmd_code)) {
+                               fprintf(stderr, "Invalid integer token: %s\n", tokens[2]);
+                               g_strfreev(tokens);
+                               exit(1);
+                       }
+               }
+       }
 
        /* Loop over diameter field names. */
        for (opt_idx=3; opt_idx<opt_count; opt_idx++)