fix(rep,cds): don't crash on two NULL slots reachable from public APIs (#149) - #155
Merged
Conversation
Fixes #149. Both reproduced as hard SIGSEGVs, then fixed and gated. 1. DB_ENV->rep_get_nsites() on a repmgr-configured but UNOPENED environment. __repmgr_get_nsites() (src/repmgr/repmgr_util.c:520) dereferenced db_rep->region, which is only attached at env open. The caller's guard, ENV_NOT_CONFIGURED(), expands to nothing until ENV_OPEN_CALLED is set (src/dbinc/db_int.in:614), so a pre-open call fell straight through: Program received signal SIGSEGV #0 __repmgr_get_nsites (...) at ../src/repmgr/repmgr_util.c:520 #1 main () at b.c:10 It now reports the same BDB3672 'Nsites unknown before repmgr_start()' error the function already had for the analogous unknown-nsites case. 2. __cdsgroup_begin() installed only 8 of DB_TXN's 12 methods, leaving get_priority, set_priority, set_commit_token and set_txn_lsnp as NULL function pointers, so calling one was an indirect call through NULL. The three int-returning slots now use the file's existing __cdsgroup_notsup() helper (DB_OPNOTSUP, 'CDS groups do not support %s'). set_txn_lsnp is declared void and so cannot report an error; it nulls its out-parameters instead, which is what the log-path callers already test for. No new message ids: both paths reuse existing strings (3672, 0687), so dist/s_message_id is unaffected. test/db/null_method_slots.c (9 checks) covers both, asserts all four slots are non-NULL as well as callable, and skips case 1 gracefully if a build has no repmgr. Proven to have teeth: reverting either fix makes the runner report FAIL (rc=139, Segmentation fault). Added to the CI regression-runner step. Found by the coverage-driver work in #147.
Coccinelle convention checksNo new violations. ✅ Resolved since baseline (2) -- update dist/cocci/baseline.txt to lock these in. |
ABI diff vs
|
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.
Fixes #149. Both parts reproduced as hard SIGSEGVs from documented public APIs with valid arguments, then fixed and gated.
1.
rep_get_nsites()on a repmgr-configured but unopened environment__repmgr_get_nsites()dereferenceddb_rep->region, which is only attached at env open. The caller's guard is the problem:ENV_NOT_CONFIGURED()expands to nothing untilENV_OPEN_CALLEDis set (src/dbinc/db_int.in:614), so a pre-open call fell straight through.Now returns the BDB3672
Nsites unknown before repmgr_start()error the function already had for the analogous unknown-nsites case. Note the trigger is touching any repmgr setting — that allocatesDB_REPwithout attaching its region. A plaindb_env_create+rep_get_nsitesdoes not crash, which is why this needed the repmgr variant to reproduce.2.
__cdsgroup_begin()left 4 ofDB_TXN's 12 method slots NULLget_priority,set_priority,set_commit_token,set_txn_lsnp— calling any one was an indirect call through a NULL function pointer.The three
int-returning slots now use the file's existing__cdsgroup_notsup()helper (DB_OPNOTSUP, "CDS groups do not support %s"), matching the eight already-installed methods.set_txn_lsnpis declared void and so cannot report an error — it nulls its out-parameters instead, which is what the log-path callers already test for.Test
test/db/null_method_slots.c— 9 checks:It asserts each slot is non-NULL and that calling it returns, and skips case 1 gracefully if a build lacks repmgr. Proven to have teeth: reverting either fix makes the runner report
FAIL (rc=139, Segmentation fault). Wired into the CI regression-runner step.Notes
dist/s_message_idis unaffected (verified: it rewrites nothing).test/dbrunners,lockmatrix,isolation,soak,fuzzall PASS.Found by the coverage-driver work in #147.