detect: fail thread init on keyword ctx error (and fix cbindgen build break) - #15589
Closed
ssam18 wants to merge 2 commits into
Closed
detect: fail thread init on keyword ctx error (and fix cbindgen build break)#15589ssam18 wants to merge 2 commits into
ssam18 wants to merge 2 commits into
Conversation
Newer cbindgen (>= 0.29.3) exports the Rust DETECT_BYTEMATH_ENDIAN_DEFAULT constant into rust-bindings.h as a macro, which collides under -Werror with the macro defined under UNITTESTS in detect-bytemath.c and breaks the build. Guard the C definition with ifndef so it is only defined when the binding did not, keeping the build working with older cbindgen that does not emit it.
DetectEngineThreadCtxInitKeywords returns TM_ECODE_FAILED when a per-thread keyword init fails (for example DetectFilemagicThreadInit), but ThreadCtxDoInit discarded that result and still returned OK. The detect thread then ran with a partially initialized keyword context array, producing indeterminate results. Propagate the failure so the callers abort thread init and clean up. Add a unit test that registers a keyword whose thread init fails and verifies that DetectEngineThreadCtxInit reports the failure. Ticket: OISF#8237
5 tasks
victorjulien
requested changes
Jun 12, 2026
victorjulien
left a comment
Member
There was a problem hiding this comment.
We fixed the cbindgen issue in a different way. Could you rebase this PR without the cbindgen fix and submit a new PR?
5 tasks
Contributor
Author
|
Done — rebased on current main without the cbindgen commit and submitted as #15630. Closing this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (if applicable):
(including schema descriptions)
https://redmine.openinfosecfoundation.org/projects/suricata/issues
Link to ticket: https://redmine.openinfosecfoundation.org/issues/8237
Describe changes:
detect: guard duplicate bytemath endian macro. Newer cbindgen (>= 0.29.3, e.g. 0.29.4) now exports the long-standing Rustpub const DETECT_BYTEMATH_ENDIAN_DEFAULTintorust-bindings.has a macro. That collides under-Werrorwith the macro defined underUNITTESTSindetect-bytemath.c, which is why every build job onmainstarted failing. The C macro is now guarded with#ifndef, so it is only defined when the binding did not, keeping the build working with both newer and older cbindgen (theminsupported is 0.20.0; thecommit-checkjob uses 0.24.3, which does not emit the macro). Validated by buildingdetect-bytemath.oboth with the macro present (newer cbindgen) and absent (older cbindgen) and running the bytemath unit tests (19 passed).detect: fail thread init on keyword ctx error.ThreadCtxDoInitignored the return ofDetectEngineThreadCtxInitKeywords, so a failing per-thread keyword init (for exampleDetectFilemagicThreadInit) left a partially initialized keyword context array and the detect thread ran with indeterminate results. The failure is now propagated so the callers abort thread init and clean up, with a unit test that fails without the fix and passes with it.