ovs-ofctl: Fix write before beginning of string in "add-flow".
[openvswitch] / utilities / ovs-ofctl.c
index 9a75969bc828a24f43b1519122f69996b9c023ea..204e9582f22975dd5877eced8a78f9b3b432c9fa 100644 (file)
@@ -405,6 +405,20 @@ str_to_u32(const char *str)
     return value;
 }
 
+static uint64_t
+str_to_u64(const char *str) 
+{
+    char *tail;
+    uint64_t value;
+
+    errno = 0;
+    value = strtoull(str, &tail, 0);
+    if (errno == EINVAL || errno == ERANGE || *tail) {
+        ovs_fatal(0, "invalid numeric format %s", str);
+    }
+    return value;
+}
+
 static void
 str_to_mac(const char *str, uint8_t mac[6]) 
 {
@@ -627,6 +641,12 @@ str_to_action(char *str, struct ofpbuf *b)
             struct ofp_action_nw_tos *nt;
             nt = put_action(b, sizeof *nt, OFPAT_SET_NW_TOS);
             nt->nw_tos = str_to_u32(arg);
+        } else if (!strcasecmp(act, "resubmit")) {
+            struct nx_action_resubmit *nar;
+            nar = put_action(b, sizeof *nar, OFPAT_VENDOR);
+            nar->vendor = htonl(NX_VENDOR_ID);
+            nar->subtype = htons(NXAST_RESUBMIT);
+            nar->in_port = htons(str_to_u32(arg));
         } else if (!strcasecmp(act, "output")) {
             put_output_action(b, str_to_u32(arg));
         } else if (!strcasecmp(act, "drop")) {
@@ -760,9 +780,9 @@ str_to_flow(char *string, struct ofp_match *match, struct ofpbuf *actions,
         if (!act_str) {
             ovs_fatal(0, "must specify an action");
         }
-        *(act_str-1) = '\0';
+        *act_str = '\0';
 
-        act_str = strchr(act_str, '=');
+        act_str = strchr(act_str + 1, '=');
         if (!act_str) {
             ovs_fatal(0, "must specify an action");
         }
@@ -804,7 +824,7 @@ str_to_flow(char *string, struct ofp_match *match, struct ofpbuf *actions,
             } else if (hard_timeout && !strcmp(name, "hard_timeout")) {
                 *hard_timeout = atoi(value);
             } else if (cookie && !strcmp(name, "cookie")) {
-                *cookie = atoi(value);
+                *cookie = str_to_u64(value);
             } else if (parse_field(name, &f)) {
                 void *data = (char *) match + f->offset;
                 if (!strcmp(value, "*") || !strcmp(value, "ANY")) {