Don't allow invalid ranges to be specified for the stats tree. Bug 9130 (https:/...
authormmann <mmann@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 18 Oct 2013 21:17:01 +0000 (21:17 +0000)
committermmann <mmann@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 18 Oct 2013 21:17:01 +0000 (21:17 +0000)
Not sure which memory allocation should be used here (using wmem caused crash), but this revision can at least be easily backported to 1.10 where the bug was reported.

Also allow a single number to be used in the stats range since it's considered a valid "range" by the UAT.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@52679 f5534014-38df-0310-8fa8-9805f1628bb7

epan/stats_tree.c
plugins/stats_tree/pinfo_stats_tree.c

index ec0e190a91cc0d91af736d3fcedfba553c4b662d..3be00973aa68f535792d009f6e5ba28521a9f4a5 100644 (file)
@@ -621,29 +621,28 @@ get_range(char *rngstr)
           return NULL;
         }
 
-        /* means we have a non empty string
-         * which does not contain a delimiter */
-        if (split[1] == NULL) {
-          g_strfreev(split);
-          return NULL;
-        }
-
         rng = (range_pair_t *)g_malloc(sizeof(range_pair_t));
 
-        /* string == "X-?" */
-        if (*(split[0]) != '\0') {
+        if (split[1] == NULL) {
+          /* means we have a non empty string with no delimiter
+           * so it must be a single number */
             rng->floor = (gint)strtol(split[0],NULL,10);
-        } else
-          /* string == "-?" */
-          rng->floor = G_MININT;
-
-        /* string != "?-" */
-        if (*(split[1]) != '\0') {
-          rng->ceil  = (gint)strtol(split[1],NULL,10);
-        } else
-          /* string == "?-" */
-          rng->ceil = G_MAXINT;
-
+            rng->ceil = rng->floor;
+        } else {
+          /* string == "X-?" */
+          if (*(split[0]) != '\0') {
+              rng->floor = (gint)strtol(split[0],NULL,10);
+          } else
+            /* string == "-?" */
+            rng->floor = G_MININT;
+
+          /* string != "?-" */
+          if (*(split[1]) != '\0') {
+            rng->ceil  = (gint)strtol(split[1],NULL,10);
+          } else
+            /* string == "?-" */
+            rng->ceil = G_MAXINT;
+        }
         g_strfreev(split);
 
        return rng;
index 6529040d98999ccdda5ebab6598c0b2b63402fac..6adf6d4605fe0cb371ec5972f41fe0de6daa1a84 100644 (file)
@@ -68,6 +68,18 @@ static void* uat_plen_record_copy_cb(void* n, const void* o, size_t siz _U_) {
        return n;
 }
 
+static void
+uat_plen_record_update_cb(void *r, const char **err)
+{
+       uat_plen_record_t *rec = (uat_plen_record_t*)r;
+       if (rec->packet_range->nranges < 1) {
+               *err = ep_strdup_printf("Invalid range string");
+               return;
+       }
+
+       *err = NULL;
+}
+
 static void uat_plen_record_free_cb(void*r) {
     uat_plen_record_t* record = (uat_plen_record_t*)r;
 
@@ -206,7 +218,7 @@ void register_pinfo_stat_trees(void) {
                        0,                          /* not a dissector, so affects neither dissection nor fields */
                        NULL,                       /* help */
                        uat_plen_record_copy_cb,    /* copy callback */
-                       NULL,                       /* update callback */
+                       uat_plen_record_update_cb,  /* update callback */
                        uat_plen_record_free_cb,    /* free callback */
                        uat_plen_record_post_update_cb, /* post update callback */
                        plen_uat_flds);             /* UAT field definitions */