detect: Clear errno before strtoul

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
pull/11809/head
Jeff Lucovsky 3 months ago committed by Victor Julien
parent a115acf208
commit 8f107c8252

@ -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;

@ -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;
}
}

@ -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;

Loading…
Cancel
Save