]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: Clear errno before strtoul
authorJeff Lucovsky <jlucovsky@oisf.net>
Tue, 9 Jul 2024 13:39:17 +0000 (09:39 -0400)
committerVictor Julien <victor@inliniac.net>
Sun, 22 Sep 2024 04:45:33 +0000 (06:45 +0200)
Per the notes for strtoul, since 0 or ULONG_MAX is a legitimate return
value, errno must be cleared before the call so an error can be checked
after the call by testing errno.

Issue: 7126

src/detect-gid.c
src/detect-rev.c
src/detect-sid.c

index a278edbc2666d0d3ff048864425a060195d7dea3..e131b535918f40c1d650722590d91a7772554ce2 100644 (file)
@@ -73,8 +73,9 @@ static int DetectGidSetup (DetectEngineCtx *de_ctx, Signature *s, const char *ra
 {
     unsigned long gid = 0;
     char *endptr = NULL;
+    errno = 0;
     gid = strtoul(rawstr, &endptr, 10);
-    if (endptr == NULL || *endptr != '\0') {
+    if (errno == ERANGE || endptr == NULL || *endptr != '\0') {
         SCLogError("invalid character as arg "
                    "to gid keyword");
         goto error;
@@ -154,4 +155,4 @@ static void GidRegisterTests(void)
     UtRegisterTest("GidTestParse02", GidTestParse02);
     UtRegisterTest("GidTestParse03", GidTestParse03);
 }
-#endif /* UNITTESTS */
\ No newline at end of file
+#endif /* UNITTESTS */
index dda513cc0a9fe3b1870431764e3814baac2b4739..6f0f94b1305b7846d2ff0e23e7b1ac4e971f6f5d 100644 (file)
@@ -43,8 +43,9 @@ static int DetectRevSetup (DetectEngineCtx *de_ctx, Signature *s, const char *ra
 {
     unsigned long rev = 0;
     char *endptr = NULL;
+    errno = 0;
     rev = strtoul(rawstr, &endptr, 10);
-    if (endptr == NULL || *endptr != '\0') {
+    if (errno == ERANGE || endptr == NULL || *endptr != '\0') {
         SCLogError("invalid character as arg "
                    "to rev keyword");
         goto error;
@@ -68,4 +69,4 @@ static int DetectRevSetup (DetectEngineCtx *de_ctx, Signature *s, const char *ra
 
  error:
     return -1;
-}
\ No newline at end of file
+ }
index 0002e1066384837839ce00ac386e4d9f76752e93..971be9df46c91f3b9a8cfdb4aab73d14e1329882 100644 (file)
@@ -53,8 +53,9 @@ static int DetectSidSetup (DetectEngineCtx *de_ctx, Signature *s, const char *si
 {
     unsigned long id = 0;
     char *endptr = NULL;
+    errno = 0;
     id = strtoul(sidstr, &endptr, 10);
-    if (endptr == NULL || *endptr != '\0') {
+    if (errno == ERANGE || endptr == NULL || *endptr != '\0') {
         SCLogError("invalid character as arg "
                    "to sid keyword");
         goto error;
@@ -145,4 +146,4 @@ static void DetectSidRegisterTests(void)
     UtRegisterTest("SidTestParse03", SidTestParse03);
     UtRegisterTest("SidTestParse04", SidTestParse04);
 }
-#endif /* UNITTESTS */
\ No newline at end of file
+#endif /* UNITTESTS */