Repository navigation
conf.c: require the index compare callback in TXT_DB lookups - #12034
yosuke-wolfssl wants to merge 1 commit into
Conversation
- WOLFSSL_TXT_DB gains a cmp_fn array. - wolfSSL_TXT_DB_create_index() stores cmp in cmp_fn[field]. - wolfSSL_TXT_DB_get_by_index() walks the rows itself and returns a row only when its hash matches and cmp_fn() returns 0. - test_wolfSSL_TXT_DB() exercises the colliding hashes case. Issue: F-8864
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the TXT_DB hash-collision fix.
No open issues 🎉
What changed in this PR
This PR fixes hash-collision handling in wolfSSL’s OpenSSL-compatible TXT_DB lookups by requiring both a matching hash and a successful comparison callback.
Changes:
- Stores a comparison callback for each TXT_DB index.
- Checks row equality during lookup and rejects NULL values or missing callbacks.
- Adds collision regression tests for matching and absent values.
| File | Description |
|---|---|
wolfssl/openssl/txt_db.h |
Adds per-index comparison callback storage. |
tests/api.c |
Tests successful and unsuccessful lookups with colliding hashes. |
src/conf.c |
Stores comparison callbacks and uses them to verify lookup matches. |
Review effort: Balanced
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12034
Scan targets checked: wolfssl-src, wolfssl-bugs
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
|
@claude review |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. It adds a field to the public WOLFSSL_TXT_DB struct in wolfssl/openssl/txt_db.h, which changes the struct layout for OPENSSL_ALL builds, so a maintainer should still confirm that the change is acceptable.
What was reviewed:
- The new lookup loop in
wolfSSL_TXT_DB_get_by_index. When the hash function changes, the existing sync loop resetsdata->hashto 0, so cached hashes don't go stale when an index is re-created. The new test relies on this when it switches fromTXT_DB_hashtoTXT_DB_hash_const. wolfssl_sk_node_get_dataisstaticinsrc/ssl_sk.c. It is still visible here becausessl.cincludesssl_sk.cbeforeconf.c.wolfSSL_TXT_DB_readzeroes the struct withXMEMSET, socmp_fnstarts out NULL.- Callers that set
hash_fn[idx]directly without callingcreate_indexwill now get NULL from every lookup. That only affects code that bypasses the API, so I don't consider it a bug.
Extended reasoning...
The change touches three files. In src/conf.c, the TXT_DB index creation now stores the compare callback, and the lookup now requires both a hash match and a compare match. wolfssl/openssl/txt_db.h gains a public struct field, and tests/api.c adds a test where every hash collides. It doesn't touch crypto, auth or network-parsing paths. The logic is small and follows the existing wolfSSL_lh_retrieve walk, and the test covers it. I deferred for two reasons: the public struct layout (ABI) change needs a maintainer's call, and the earlier reviews from other reviewers have no later commit, so I couldn't confirm they were addressed.
Problem
wolfSSL_TXT_DB_create_index()requires a non-NULLcmpcallback but discards it, andwolfSSL_TXT_DB_get_by_index()delegates towolfSSL_lh_retrieve(), which treats any hash match as a hit.Fix (
src/conf.c)WOLFSSL_TXT_DBgainscmp_fn[WOLFSSL_TXT_DB_MAX_FIELDS], appended afterhash_fn.wolfSSL_TXT_DB_create_index()storescmpincmp_fn[field].wolfSSL_TXT_DB_get_by_index()walks the rows itself and returns a row only when its cached hash matches andcmp_fn(row, value) == 0. It also rejects aNULLvalue and an index that has no compare callback.Closes f-8864.
Tests
test_wolfSSL_TXT_DB()re-creates index 3 with a constant hash, so every row collides, and checks:12DAreturns the12DArow (before the fix it returned the first row,12F8);FFFFreturnsNULL.Verification
./tests/unit.test(--enable-opensslall --enable-opensslextra): 0 failed, 1461 passed.test_wolfSSL_TXT_DB.-Werror: build clean, test passes.