Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host-info: remove pcre2_substring_list_free use #10780

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/util-host-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
Loading