cachedb_memcached, cachedb_cassandra: fix NULL deref in connection init#3849
Open
dondetir wants to merge 2 commits intoOpenSIPS:masterfrom
Open
cachedb_memcached, cachedb_cassandra: fix NULL deref in connection init#3849dondetir wants to merge 2 commits intoOpenSIPS:masterfrom
dondetir wants to merge 2 commits intoOpenSIPS:masterfrom
Conversation
memcached_create(NULL) can return NULL on allocation failure. The existing code never checks the return value, so a NULL memc pointer falls through to memcached_server_push(NULL, ...) which dereferences the NULL pointer. Add an explicit NULL check after memcached_create(), following the existing error-handling pattern in the function (pkg_free + return 0). Found during a systematic audit of cachedb backends following the cachedb_redis NULL-deref fix in commit 8fb569c.
cass_cluster_new() can return NULL on allocation failure. The existing code has a NULL check, but it comes after cass_cluster_set_credentials() already uses the pointer (when credentials are configured), so a NULL return causes a crash before the check is reached. Move the NULL check to immediately after cass_cluster_new(), before any use of the returned pointer. Found during a systematic audit of cachedb backends following the cachedb_redis NULL-deref fix in commit 8fb569c.
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.
Summary
Fix NULL pointer dereferences in
cachedb_memcachedandcachedb_cassandraconnection initialization, following the same pattern fixed incachedb_redis(8fb569c).Details
cachedb_rediswhereredisConnect()could return NULL on allocation failure but the return was used without a NULL check. A systematic audit of all other cachedb backends revealed the same pattern in two more modules:cachedb_memcached —
memcached_create(NULL)can return NULL on allocation failure (documented behavior). No NULL check exists before passing the pointer tomemcached_server_push(), causing a crash.cachedb_cassandra —
cass_cluster_new()can return NULL on allocation failure. A NULL check exists, but it comes aftercass_cluster_set_credentials()already dereferences the pointer (when credentials are configured), so the check is too late.Solution
memcached_create(), following the existing error pattern in the function (pkg_free(con); return 0).cass_cluster_new(), before any use of the pointer. No new code — just reordered.Compatibility
Closing Issues
N/A — no open issue for these. Found via code audit following 8fb569c.