src: nest postfix decrement counters inside loops#14804
src: nest postfix decrement counters inside loops#14804
Conversation
During fuzzing, UBSan discovered that postfix increments/decrements inside a loop condition are executed after the condition is met. While in most cases loop counter is dropped right after it's been used in some cases where it doesn't it may lead to unexpected behaviour. Yet in both cases loop peforms extra addition/subtraction, which would be nice to eliminate. So the solution is to switch to incremental for loop or nest such counters inside loops so they are executed only if loop termination condition isn't met.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14804 +/- ##
==========================================
+ Coverage 82.15% 82.16% +0.01%
==========================================
Files 1003 1003
Lines 263691 263688 -3
==========================================
+ Hits 216626 216663 +37
+ Misses 47065 47025 -40
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| next_sflags = next_s->flags; | ||
| } | ||
| while (match_cnt--) { | ||
| while (match_cnt) { |
There was a problem hiding this comment.
Why is this last one remaining with while ?
Thanks for the rest of the work by the way
There was a problem hiding this comment.
Why is this last one remaining with
while?
Switching to incremental for loop changes too much logic.
Btw I forgot about for(; match_cnt > 0 ;match_cnt--).
catenacyber
left a comment
There was a problem hiding this comment.
Could you please have a green CI ?
See ./scripts/clang-format.sh check-branch
It's is a clang-format bug that breaks indentation style. Basically it tries to do this: So I don't think I can do anything. Probably there's something wrong with macros in code. |
|
Also not sure what's the problem with pcapng. |
This one is very likely unrelated to your patch. |
|
The npcap test fails a bit randomly lately. |
Indeed, but there were also other fixes done in #14831 |
Previous PR: #14779
Contribution style:
https://docs.suricata.io/en/latest/devguide/contributing/contribution-process.html
Our Contribution agreements:
https://suricata.io/about/contribution-agreement/ (note: this is only required once)
Changes:
https://redmine.openinfosecfoundation.org/projects/suricata/issues
Link to ticket: https://redmine.openinfosecfoundation.org/issues/8184
Describe changes:
Changes from last PR:
Attaching little reference unit tests, which may be used to inspect difference in generated assembly and results given by changes:
loop_checks.c
Provide values to any of the below to override the defaults.
link to the pull request in the respective
_BRANCHvariable.SV_REPO=
SV_BRANCH=
SU_REPO=
SU_BRANCH=