]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/ipproto: Use builtin protocol table
authorJeff Lucovsky <jeff@lucovsky.org>
Sat, 12 Feb 2022 14:46:29 +0000 (09:46 -0500)
committerVictor Julien <vjulien@oisf.net>
Thu, 24 Feb 2022 17:23:28 +0000 (18:23 +0100)
Issue 5072

This commit causes the built-in protocol table to be used for protocol
name and number validation.

src/detect-ipproto.c

index 2eb4833692eb2efc5b2281c7f453486f8004ff9c..598f5ad761f46e300871c782cf30e541f1859037 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2020 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -38,6 +38,7 @@
 #include "detect-engine-address.h"
 
 #include "util-byte.h"
+#include "util-proto-name.h"
 #include "util-unittest.h"
 #include "util-unittest-helper.h"
 
@@ -121,13 +122,12 @@ static DetectIPProtoData *DetectIPProtoParse(const char *optstr)
 
     /* Protocol name/number */
     if (!isdigit((unsigned char)*(args[1]))) {
-        struct protoent *pent = getprotobyname(args[1]);
-        if (pent == NULL) {
-            SCLogError(SC_ERR_INVALID_VALUE, "Malformed protocol name: %s",
-                       str_ptr);
+        uint8_t proto;
+        if (!SCGetProtoByName(args[1], &proto)) {
+            SCLogError(SC_ERR_INVALID_VALUE, "Unknown protocol name: \"%s\"", str_ptr);
             goto error;
         }
-        data->proto = (uint8_t)pent->p_proto;
+        data->proto = proto;
     }
     else {
         if (StringParseUint8(&data->proto, 10, 0, args[1]) <= 0) {