]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
napatech: fix warnings with ByteExtractStringUint8
authorRalph Eastwood <rea@napatech.com>
Thu, 3 Aug 2023 13:32:10 +0000 (15:32 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 5 Sep 2023 12:21:34 +0000 (14:21 +0200)
The WARN_UNUSED attribute has been added to ByteExtractStringUint8
in commit 698816811406572c443ca1e95c309d292f489376.  The return
value is now handled and appropriate errors printed.

src/util-napatech.c

index 74ff82fda71401fd43eec714b0aac06d2d44b009..e8c842fabc4c0fa94b65ad86ac28d5db674b9f2c 100644 (file)
@@ -1454,8 +1454,16 @@ uint32_t NapatechSetupTraffic(uint32_t first_stream, uint32_t last_stream)
             if (strchr(port->val, '-')) {
                 stream_spec = CONFIG_SPECIFIER_RANGE;
 
-                ByteExtractStringUint8(&ports_spec.first[iteration], 10, 0, port->val);
-                ByteExtractStringUint8(&ports_spec.second[iteration], 10, 0, strchr(port->val, '-')+1);
+                if (ByteExtractStringUint8(&ports_spec.first[iteration], 10, 0, port->val) == -1) {
+                    FatalError("Invalid value '%s' in napatech.ports specification in conf file.",
+                            port->val);
+                }
+
+                if (ByteExtractStringUint8(&ports_spec.second[iteration], 10, 0,
+                            strchr(port->val, '-') + 1) == -1) {
+                    FatalError("Invalid value '%s' in napatech.ports specification in conf file.",
+                            port->val);
+                }
 
                 if (ports_spec.first[iteration] == ports_spec.second[iteration]) {
                     if (is_inline) {
@@ -1533,8 +1541,17 @@ uint32_t NapatechSetupTraffic(uint32_t first_stream, uint32_t last_stream)
                 }
                 stream_spec = CONFIG_SPECIFIER_RANGE;
 
-                ByteExtractStringUint8(&ports_spec.first[iteration], 10, 0, port->val);
-                ByteExtractStringUint8(&ports_spec.second[iteration], 10, 0, strchr(port->val, '-') + 1);
+                if (ByteExtractStringUint8(&ports_spec.first[iteration], 10, 0, port->val) == -1) {
+                    FatalError("Invalid value '%s' in napatech.ports specification in conf file.",
+                            port->val);
+                }
+
+                if (ByteExtractStringUint8(&ports_spec.second[iteration], 10, 0,
+                            strchr(port->val, '-') + 1) == -1) {
+                    FatalError("Invalid value '%s' in napatech.ports specification in conf file.",
+                            port->val);
+                }
+
                 snprintf(ports_spec.str, sizeof (ports_spec.str), "(%d..%d)", ports_spec.first[iteration], ports_spec.second[iteration]);
             } else {
                 /* check that the sting in the config file is correctly specified */
@@ -1544,7 +1561,10 @@ uint32_t NapatechSetupTraffic(uint32_t first_stream, uint32_t last_stream)
                 }
                 stream_spec = CONFIG_SPECIFIER_INDIVIDUAL;
 
-                ByteExtractStringUint8(&ports_spec.first[iteration], 10, 0, port->val);
+                if (ByteExtractStringUint8(&ports_spec.first[iteration], 10, 0, port->val) == -1) {
+                    FatalError("Invalid value '%s' in napatech.ports specification in conf file.",
+                            port->val);
+                }
 
                 /* Determine the ports to use on the NTPL assign statement*/
                 if (iteration == 0) {