]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
host-info: remove pcre2_substring_list_free use 10768/head
authorVictor Julien <vjulien@oisf.net>
Thu, 4 Apr 2024 15:51:48 +0000 (17:51 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 4 Apr 2024 20:25:21 +0000 (22:25 +0200)
Function prototype has changed in a recent release. Rather than dealing
with detecting that, fall back to our regular pattern of using
pcre2_substring_copy_bynumber().

Bug: #6918.

src/util-host-info.c

index c0dd93b80cfcbcb7627856d6acc8c7390c14cf04..282b2fb240861ba41d3a1e7a355bd113579c6421 100644 (file)
@@ -44,7 +44,6 @@ int SCKernelVersionIsAtLeast(int major, int minor)
     PCRE2_SIZE eo;
     int ret;
     int kmajor, kminor;
-    PCRE2_UCHAR **list;
 
     /* get local version */
     if (uname(&kuname) != 0) {
@@ -79,25 +78,36 @@ int SCKernelVersionIsAtLeast(int major, int minor)
         goto error;
     }
 
-    pcre2_substring_list_get(version_regex_match, &list, NULL);
+    char majorstr[32];
+    size_t pcre2len = sizeof(majorstr);
+    ret = pcre2_substring_copy_bynumber(
+            version_regex_match, 1, (PCRE2_UCHAR8 *)majorstr, &pcre2len);
+    if (ret < 0) {
+        SCLogError("pcre2_substring_copy_bynumber failed");
+        goto error;
+    }
 
-    bool err = false;
-    if (StringParseInt32(&kmajor, 10, 0, (const char *)list[1]) < 0) {
-        SCLogError("Invalid value for kmajor: '%s'", list[1]);
-        err = true;
+    char minorstr[32];
+    pcre2len = sizeof(majorstr);
+    ret = pcre2_substring_copy_bynumber(
+            version_regex_match, 2, (PCRE2_UCHAR8 *)minorstr, &pcre2len);
+    if (ret < 0) {
+        SCLogError("pcre2_substring_copy_bynumber failed");
+        goto error;
     }
-    if (StringParseInt32(&kminor, 10, 0, (const char *)list[2]) < 0) {
-        SCLogError("Invalid value for kminor: '%s'", list[2]);
-        err = true;
+
+    if (StringParseInt32(&kmajor, 10, 0, (const char *)majorstr) < 0) {
+        SCLogError("Invalid value for kmajor: '%s'", minorstr);
+        goto error;
+    }
+    if (StringParseInt32(&kminor, 10, 0, (const char *)minorstr) < 0) {
+        SCLogError("Invalid value for kminor: '%s'", minorstr);
+        goto error;
     }
 
-    pcre2_substring_list_free((PCRE2_SPTR *)list);
     pcre2_match_data_free(version_regex_match);
     pcre2_code_free(version_regex);
 
-    if (err)
-        goto error;
-
     if (kmajor > major)
         return 1;
     if (kmajor == major && kminor >= minor)