Skip to content

src: replace postfix decremental loops#14911

Open
Rx1513 wants to merge 1 commit intoOISF:mainfrom
Rx1513:loop-underflows/v5
Open

src: replace postfix decremental loops#14911
Rx1513 wants to merge 1 commit intoOISF:mainfrom
Rx1513:loop-underflows/v5

Conversation

@Rx1513
Copy link
Contributor

@Rx1513 Rx1513 commented Feb 26, 2026

Previous PR: #14779

Contribution style:

Our Contribution agreements:

Changes:

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

Describe changes:

  • Replace decremental "while" loops with incremental "for" loops.

Changes from last PR:

  • Nest decrement counter for DetectRulePacketRules.
  • Different commit title.
  • Rebase to current main.

Attaching little reference unit tests, which may be used to inspect difference in generated assembly and results given by changes:
loop_checks.c

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.
@Rx1513 Rx1513 requested review from a team and victorjulien as code owners February 26, 2026 14:37
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.

1 participant