Skip to content

Commit e7c8bf0

Browse files
dondetirliviuchircu
authored andcommitted
cachedb_cassandra: fix NULL deref when cass_cluster_new() returns NULL
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. (cherry picked from commit 8f959e7)
1 parent b747385 commit e7c8bf0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

modules/cachedb_cassandra/cachedb_cassandra_dbase.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ int cassandra_reopen(cassandra_con *cass_con)
141141
int cassandra_new_connection(cassandra_con *con, char *host, int port, char *username, char *password)
142142
{
143143
con->cluster = cass_cluster_new();
144-
if (username && password) {
145-
cass_cluster_set_credentials(con->cluster, username, password);
146-
}
147144
if (!con->cluster) {
148145
LM_ERR("Failed to create Cassandra Cluster object\n");
149146
return -1;
150147
}
148+
if (username && password) {
149+
cass_cluster_set_credentials(con->cluster, username, password);
150+
}
151151

152152
#if CASS_VERSION_MAJOR >= 2 && CASS_VERSION_MINOR >= 15
153153
/* since version 2.15, DSE support is available in the standard driver

0 commit comments

Comments
 (0)