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

applayer/htp: convert to new FAIL/PASS API /v5 #11973

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nancyenos
Copy link

@Nancyenos Nancyenos commented Oct 16, 2024

Ticket: #6935

Make sure these boxes are checked accordingly before submitting your Pull Request -- thank you.

Contribution style:

Our Contribution agreements:

Changes (if applicable):

Link to ticket: https://redmine.openinfosecfoundation.org/issues/

Describe changes:

Provide values to any of the below to override the defaults.

  • To use an LibHTP, Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=
SU_REPO=
SU_BRANCH=
LIBHTP_REPO=
LIBHTP_BRANCH=

@jufajardini jufajardini added the outreachy Contributions made by Outreachy applicants label Oct 16, 2024
Copy link

NOTE: This PR may contain new authors.

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 98.87955% with 4 lines in your changes missing coverage. Please review.

Project coverage is 82.84%. Comparing base (37fa2a6) to head (ed07b85).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11973      +/-   ##
==========================================
+ Coverage   82.77%   82.84%   +0.06%     
==========================================
  Files         910      910              
  Lines      249016   248530     -486     
==========================================
- Hits       206134   205890     -244     
+ Misses      42882    42640     -242     
Flag Coverage Δ
fuzzcorpus 60.57% <ø> (-0.21%) ⬇️
livemode 18.71% <ø> (ø)
pcap 43.94% <ø> (-0.15%) ⬇️
suricata-verify 62.23% <ø> (+0.03%) ⬆️
unittests 59.09% <98.87%> (+0.07%) ⬆️

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

@jufajardini jufajardini self-assigned this Oct 17, 2024
Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

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

I know this is a very big file, with lots of tests. You're brave for picking up this one!

Test HTPBodyReassemblyTest01 still has a mixed style: it hasn't been fully converted to the FAIL/PASS style.

I think I've covered all cases where we need some improvement, still, so you can get a good understanding of what the next steps are.

There is one thing that I asked someone else to do a sanity check. If you are idly waiting, feel free to claim another task, in this case, ok?

Comment on lines +3708 to +3711
FAIL_IF(bstr_ptr(tx_ud->request_uri_normalized)[0] != '/' ||
bstr_ptr(tx_ud->request_uri_normalized)[1] != '%' ||
bstr_ptr(tx_ud->request_uri_normalized)[2] != '0' ||
bstr_ptr(tx_ud->request_uri_normalized)[3] != '0')
{
printf("normalized uri \"");
PrintRawUriFp(stdout, bstr_ptr(tx_ud->request_uri_normalized), bstr_len(tx_ud->request_uri_normalized));
printf("\": ");
goto end;
}
}
bstr_ptr(tx_ud->request_uri_normalized)[3] != '0');
Copy link
Contributor

Choose a reason for hiding this comment

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

let's break each of these into their own FAIL... macros

printf("Could not get config for: %s\n", addr);
goto end;
}
FAIL_IF_NULL(user_data);
Copy link
Contributor

Choose a reason for hiding this comment

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

As the tests passed, I suppose there's no harm here. But wanted to point out that this changes the original format a bit, since we don't jump to end in this case, even if user_data was NULL

Comment on lines 3997 to 4006
if (inet_pton(AF_INET, addr, buf) == 1) {
(void)SCRadixFindKeyIPV4BestMatch(buf, cfgtree, &user_data);
if (user_data != NULL) {
HTPCfgRec *htp_cfg_rec = user_data;
htp = htp_cfg_rec->cfg;
SCLogDebug("LIBHTP using config: %p", htp);
}
if (htp == NULL) {
printf("Could not get config for: %s\n", addr);
goto end;
}
FAIL_IF_NULL(user_data);
HTPCfgRec *htp_cfg_rec = user_data;
htp = htp_cfg_rec->cfg;
SCLogDebug("LIBHTP using config: %p", htp);

FAIL_IF_NULL(htp);

}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can simplify this to just check:

FAIL_IF_NOT(inet_pton(AF_INET, addr, buf) == 1)

since the else case will simply be a FAIL. What do you think, @inashivb ?

Copy link
Member

@inashivb inashivb Oct 18, 2024

Choose a reason for hiding this comment

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

I think we need to check user data and htp config too. So, yes to your suggestion, followed by the rest of the matches too. The block could look like:

        FAIL_IF(inet_pton(AF_INET, addr, buf) != 1)
        (void)SCRadixFindKeyIPV4BestMatch(buf, cfgtree, &user_data);
        if (user_data != NULL) {
            HTPCfgRec *htp_cfg_rec = user_data;
            htp = htp_cfg_rec->cfg;
            SCLogDebug("LIBHTP using config: %p", htp);

            FAIL_IF_NULL(htp);
        }

Copy link
Contributor

Choose a reason for hiding this comment

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

Then maybe... Would this until make sense?

FAIL_IF(inet_pton(AF_INET, addr, buf) != 1);
(void)SCRadixFindKeyIPV4BestMatch(buf, cfgtree, &user_data);
FAIL_IF_NULL(user_data);
HTPCfgRec *htp_cfg_rec = user_data;
FAIL_IF_NULL(htp);
htp = htp_cfg_rec->cfg;
SCLogDebug("LIBHTP using config: %p", htp);

Copy link
Member

Choose a reason for hiding this comment

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

yeah this was my first choice but then I was trying to make it replicate the current code.. I guess this works though. Let's do this! :)

Comment on lines +3766 to -3947
FAIL_IF(bstr_ptr(tx_ud->request_uri_normalized)[0] != '/' ||
bstr_ptr(tx_ud->request_uri_normalized)[1] != '?' ||
bstr_ptr(tx_ud->request_uri_normalized)[2] != 'a' ||
bstr_ptr(tx_ud->request_uri_normalized)[3] != '=' ||
bstr_ptr(tx_ud->request_uri_normalized)[4] != '%' ||
bstr_ptr(tx_ud->request_uri_normalized)[5] != '0' ||
bstr_ptr(tx_ud->request_uri_normalized)[6] != '0')
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as with other case :)

goto end;
}
FAIL_IF_NULL(tx);
FAIL_IF_NULL(tx_ud);
Copy link
Contributor

Choose a reason for hiding this comment

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

This check doesn't seem necessary here (also comparing with other similar tests in this file)

@Nancyenos
Copy link
Author

Nancyenos commented Oct 18, 2024

Thankyou @jufajardini ..It was first time naivety! I did not realize how much work was required, almost gave up but am glad i stuck through.
yes i will be working on something else as i await that final check

@Nancyenos
Copy link
Author

I know this is a very big file, with lots of tests. You're brave for picking up this one!

Test HTPBodyReassemblyTest01 still has a mixed style: it hasn't been fully converted to the FAIL/PASS style.

I think I've covered all cases where we need some improvement, still, so you can get a good understanding of what the next steps are.

There is one thing that I asked someone else to do a sanity check. If you are idly waiting, feel free to claim another task, in this case, ok?

Hey @jufajardini , did the sanity test pass?

@jufajardini
Copy link
Contributor

I know this is a very big file, with lots of tests. You're brave for picking up this one!
Test HTPBodyReassemblyTest01 still has a mixed style: it hasn't been fully converted to the FAIL/PASS style.
I think I've covered all cases where we need some improvement, still, so you can get a good understanding of what the next steps are.
There is one thing that I asked someone else to do a sanity check. If you are idly waiting, feel free to claim another task, in this case, ok?

Hey @jufajardini , did the sanity test pass?

Yep! See Shivani's comment on the thread where we were discussing the check formats :)

You can submit a new version of this work whenever you have the time ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
outreachy Contributions made by Outreachy applicants
Development

Successfully merging this pull request may close these issues.

3 participants