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

detect: Improve support for larger address values. #5808

Closed
wants to merge 2 commits into from

Conversation

jlucovsky
Copy link
Contributor

Continuation of pr #5619

This PR modifies the address rule value parsing to permit larger address values in the rule variables section.

Link to redmine ticket: 3887

Describe changes:

  • Address review comments.

PRScript output (if applicable):

#suricata-verify-pr:
#suricata-verify-repo:
#suricata-verify-branch:
#suricata-update-pr:
#suricata-update-repo:
#suricata-update-branch:
#libhtp-pr:
#libhtp-repo:
#libhtp-branch:

This commit improves support for large address variables. Without this
commit, address size was fixed at 8196 or less. This commit permits
larger sized address variables.
@codecov
Copy link

codecov bot commented Jan 31, 2021

Codecov Report

Merging #5808 (7ddd5a5) into master (62e665c) will increase coverage by 0.00%.
The diff coverage is 90.32%.

@@           Coverage Diff           @@
##           master    #5808   +/-   ##
=======================================
  Coverage   72.38%   72.38%           
=======================================
  Files         604      604           
  Lines      179369   179390   +21     
=======================================
+ Hits       129837   129854   +17     
- Misses      49532    49536    +4     
Flag Coverage Δ
suricata-verify 49.14% <69.56%> (-0.01%) ⬇️
unittests 63.08% <90.32%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me...
Wonder if a deeper rewriting would be beneficial...


size_t address_length = strlen(s);
if (address_length > (MAX_ADDRESS_LENGTH - 1)) {
char *address = SCCalloc(1, address_length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to get rid of address and use only s ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address is a return parameter ... built as s is parsed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what is this return parameter for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recursion is possible when parsing addresses; when this happens address contains the subset of the original address to be parsed in the next step.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What recursion ? Between variables like EXTERNAL_NET and their values ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the calls in DetectAddressParseInternal that invoke DetectAddressParse2 for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I do not get it :-/
So I would upvote code simplicity over saving an allocation...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can gather (and remember), address is really only used to tokenize the input string on the fly. Other than making a copy the only modifications I can spot are inserting \0 chars to split the string before passing the parts on to further parsing logic. If this is indeed the case another approach could be to pass arrays of chars with an explicit length around. It does look like this is quite intrusive as we call out into various functions with the address part strings as the argument.

@victorjulien victorjulien self-assigned this Apr 20, 2021
SCLogError(SC_ERR_ADDRESS_ENGINE_GENERIC,
"Hit the address buffer"
" limit for the supplied address. Invalidating sig. "
"Please file a bug report on this.");
goto error;
}
address[x] = s[u];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about the logic here, and why we'd need a 'full size' address here. AFAICS we use it as a temporary place to put the address from s before passing it on. But does it need to be so big for that? Or could we have a smaller (local) temp var that is just reset after loop interations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose its because this parses anything between [...] which can have any length.

This was referenced Apr 21, 2021
@victorjulien
Copy link
Member

Merged in #6071, thanks!

@jlucovsky jlucovsky deleted the 3887/8 branch May 2, 2021 13:48
catenacyber added a commit to catenacyber/suricata that referenced this pull request Jan 25, 2023
Ticket: OISF#5808

May have been introduced by a24d7dc

Function http2_range_open expects to be called only when
tx.file_range is nil. One condition to ensure this is to check
that we are beginning the files contents. The filetracker field
file_open is not fit for this, as it may be reset to false.
catenacyber added a commit to catenacyber/suricata that referenced this pull request Jan 25, 2023
Ticket: OISF#5808

May have been introduced by a24d7dc

Function http2_range_open expects to be called only when
tx.file_range is nil. One condition to ensure this is to check
that we are beginning the files contents. The filetracker field
file_open is not fit for this, as it may be reset to false.
victorjulien pushed a commit to victorjulien/suricata that referenced this pull request Jan 26, 2023
Ticket: OISF#5808

May have been introduced by a24d7dc

Function http2_range_open expects to be called only when
tx.file_range is nil. One condition to ensure this is to check
that we are beginning the files contents. The filetracker field
file_open is not fit for this, as it may be reset to false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants