app/testpmd: fix hexadecimal parser with odd length
[dpdk.git] / app / test-pmd / cmdline_flow.c
index d821877..bbe3dc0 100644 (file)
@@ -495,7 +495,7 @@ enum index {
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
-#define ITEM_RAW_PATTERN_SIZE 40
+#define ITEM_RAW_PATTERN_SIZE 512
 
 /** Maximum size for GENEVE option data pattern in bytes. */
 #define ITEM_GENEVE_OPT_DATA_SIZE 124
@@ -5880,7 +5880,7 @@ parse_vc_item_l2tpv2_type(struct context *ctx, const struct token *token,
        struct rte_flow_item_l2tpv2 *l2tpv2_mask;
        struct rte_flow_item *item;
        uint32_t data_size;
-       uint8_t msg_type = 0;
+       uint16_t msg_type = 0;
        struct buffer *out = buf;
        const struct arg *arg;
 
@@ -7702,9 +7702,8 @@ error:
 static int
 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 {
-       char *c = NULL;
-       uint32_t i, len;
-       char tmp[3];
+       uint32_t left = *size;
+       const uint8_t *head = dst;
 
        /* Check input parameters */
        if ((src == NULL) ||
@@ -7714,19 +7713,23 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
                return -1;
 
        /* Convert chars to bytes */
-       for (i = 0, len = 0; i < *size; i += 2) {
-               snprintf(tmp, 3, "%s", src + i);
-               dst[len++] = strtoul(tmp, &c, 16);
-               if (*c != 0) {
-                       len--;
-                       dst[len] = 0;
-                       *size = len;
+       while (left) {
+               char tmp[3], *end = tmp;
+               uint32_t read_lim = left & 1 ? 1 : 2;
+
+               snprintf(tmp, read_lim + 1, "%s", src);
+               *dst = strtoul(tmp, &end, 16);
+               if (*end) {
+                       *dst = 0;
+                       *size = (uint32_t)(dst - head);
                        return -1;
                }
+               left -= read_lim;
+               src += read_lim;
+               dst++;
        }
-       dst[len] = 0;
-       *size = len;
-
+       *dst = 0;
+       *size = (uint32_t)(dst - head);
        return 0;
 }
 
@@ -9213,7 +9216,7 @@ cmd_set_raw_parsed(const struct buffer *in)
                                        uint8_t qfi:6;
                                        uint8_t next;
                                } psc;
-                               psc.len = sizeof(psc);
+                               psc.len = sizeof(psc) / 4;
                                psc.pdu_type = opt->hdr.type;
                                psc.qfi = opt->hdr.qfi;
                                psc.next = 0;