Skip to content

util-byte: add string extraction limited to a buffer - v1 - #16729

Draft
victorjulien wants to merge 5 commits into
OISF:mainfrom
victorjulien:byte-test-oob-string/v1
Draft

victorjulien wants to merge 5 commits into
OISF:mainfrom
victorjulien:byte-test-oob-string/v1

Conversation

@victorjulien

Copy link
Copy Markdown
Member

Ticket: https://redmine.openinfosecfoundation.org/issues/9089

This branch carries the upstream v2 fix for the zero-byte-count
string conversion (ByteExtractStringUint64Bounded and the three
detect keywords), rebased on main, plus a unit case for the
one-byte value at the avail boundary. byte_test, byte_jump and
byte_extract with the string option and a byte count of 0 previously
converted the caller's buffer in place and ran on until a non-digit:
for a one-byte value (a Content-Length: 0) the stale byte after it in
the pool could shift the parse, and the rule verdict varied from run to
run.

byte_math needs no change: its match validation rejects a count below 1,
so the unbounded path is unreachable there.

SV_BRANCH=OISF/suricata-verify#3547

@suricata-review-bot suricata-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI-generated review.

Verdict: approve

No high- or medium-severity findings.

Automated at commit 70b7c24c1043 using Claude Code with claude-opus-5-5/xhigh. Run: 5c3a33ad3b09332d.

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.98%. Comparing base (2dd24e7) to head (2779ec8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16729      +/-   ##
==========================================
- Coverage   83.98%   83.98%   -0.01%     
==========================================
  Files        1008     1008              
  Lines      286748   286904     +156     
==========================================
+ Hits       240832   240952     +120     
- Misses      45916    45952      +36     
Flag Coverage Δ
fuzzcorpus 61.60% <75.92%> (+<0.01%) ⬆️
livemode 25.91% <0.00%> (-0.02%) ⬇️
netns 26.32% <0.00%> (+<0.01%) ⬆️
pcap 46.18% <59.25%> (-0.04%) ⬇️
suricata-verify 69.12% <75.92%> (-0.01%) ⬇️
unittests 59.27% <100.00%> (+0.03%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@catenacyber

Copy link
Copy Markdown
Contributor

There was a previous PR with some comments of mine that are unanswered like #16657 (comment)

@suricata-qa

Copy link
Copy Markdown

Information: QA ran without warnings.

Pipeline = 36132

jlucovsky and others added 5 commits November 27, 2026 06:20
ByteExtractString() treated a length of 0 as a NUL-terminated string and
ran strtoull() on the caller's pointer. Inspection buffers are not
guaranteed to be NUL terminated, so a length of 0 could make strtoull()
read past the end of one.

Add ByteExtractStringUint64Bounded(), which also takes the number of
bytes that can be read. With a length of 0 it finds the end of the
number without reading past that limit. It skips leading whitespace and
zeros before applying the 23-byte limit that ByteExtractString() applies
to len, so every number that fits in a uint64_t converts in full. It
returns the number of bytes consumed, counting leading whitespace and
any sign.

Issue: 9089
byte_test with the string option and a byte count of 0 passed the count
to ByteExtractStringUint64(), which treated a length of 0 as a NUL-
terminated string and ran strtoull() on the inspection buffer.
Inspection buffers are not guaranteed to be NUL terminated, so the
conversion could read digits past the end of the buffer, and the
comparison used them. The count can come from a byte_extract variable,
so a packet could set it to 0.

Call ByteExtractStringUint64Bounded() with the number of bytes left in
the buffer, and do not match when none are left. A number that runs past
the end of the buffer converts only the bytes inside it, so a number cut
off by the end of the buffer can now match. Rules with a count of 0
still load, and a number inside the buffer converts as it did before,
including one padded with more than 23 leading zeros or spaces.

Issue: 9089
byte_jump with the string option and a byte count of 0 passed the count
to ByteExtractStringUint64(), which treated a length of 0 as a NUL-
terminated string and ran strtoull() on the inspection buffer.
Inspection buffers are not guaranteed to be NUL terminated, so the
conversion could read digits past the end of the buffer. The jump
distance came from those digits. For a jump that is neither
from_beginning nor from_end, the number of bytes the conversion consumed
was also added to the jump target. The count can come from a
byte_extract variable, so a packet could set it to 0.

Call ByteExtractStringUint64Bounded() with the number of bytes left in
the buffer, and do not match when none are left. A number that runs past
the end of the buffer converts only the bytes inside it. Rules with a
count of 0 still load. A number inside the buffer converts as it did
before, and the jump steps over the same bytes as before.

Issue: 9089
byte_extract with the string option and a byte count of 0 passed the
count to ByteExtractStringUint64(), which treated a length of 0 as a
NUL-terminated string and ran strtoull() on the inspection buffer.
Inspection buffers are not guaranteed to be NUL terminated, so the
conversion could read digits past the end of the buffer into the
extracted variable and move the read position past the end of the
buffer.

Call ByteExtractStringUint64Bounded() with the number of bytes left in
the buffer, and do not match when none are left. A number that runs past
the end of the buffer converts only the bytes inside it. A number inside
the buffer converts as it did before, and the read position ends right
after it.

Issue: 9089
Content-Length: 0 leaves a one-byte inspection value; the byte after
it in the pool can be a digit. The bounded conversion must stop at
the avail boundary, which ByteTest17 does not exercise at avail 1.

Ticket: OISF#9089.
@victorjulien
victorjulien force-pushed the byte-test-oob-string/v1 branch from 70b7c24 to 2779ec8 Compare November 27, 2026 09:18

@suricata-review-bot suricata-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI-generated review.

Verdict: comment

Previous feedback:

  • Not addressed — catenacyber's comment — The code matches the reviewed earlier version patch for patch; the nbytes-per-base consistency, byte_extract hex limit, docs and len/avail questions remain unanswered and unchanged.

No high- or medium-severity findings.

Automated at commit 2779ec895e7f using Claude Code with claude-opus-5-5/xhigh. Run: cd579509e72589a7.

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.

5 participants