Skip to content

Commit

Permalink
detect: Clear errno before strtoul
Browse files Browse the repository at this point in the history
Issue: 7126
  • Loading branch information
jlucovsky committed Jul 10, 2024
1 parent 94fa51e commit e569e8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/detect-gid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,4 +155,4 @@ static void GidRegisterTests(void)
UtRegisterTest("GidTestParse02", GidTestParse02);
UtRegisterTest("GidTestParse03", GidTestParse03);
}
#endif /* UNITTESTS */
#endif /* UNITTESTS */
5 changes: 3 additions & 2 deletions src/detect-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -68,4 +69,4 @@ static int DetectRevSetup (DetectEngineCtx *de_ctx, Signature *s, const char *ra

error:
return -1;
}
}
5 changes: 3 additions & 2 deletions src/detect-sid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,4 +146,4 @@ static void DetectSidRegisterTests(void)
UtRegisterTest("SidTestParse03", SidTestParse03);
UtRegisterTest("SidTestParse04", SidTestParse04);
}
#endif /* UNITTESTS */
#endif /* UNITTESTS */

0 comments on commit e569e8f

Please sign in to comment.