Skip to content

Commit 9fea57e

Browse files
dondetirliviuchircu
authored andcommitted
cachedb_memcached: fix NULL deref when memcached_create() returns NULL
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.
1 parent 82e242e commit 9fea57e

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

modules/cachedb_memcached/cachedb_memcached.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ memcached_con* memcached_new_connection(struct cachedb_id *id)
400400
con->ref = 1;
401401

402402
con->memc = memcached_create(NULL);
403+
if (!con->memc) {
404+
LM_ERR("failed to create memcached handle\n");
405+
pkg_free(con);
406+
return 0;
407+
}
403408

404409
memset(host_buff,0,MAX_HOSTPORT_SIZE);
405410

0 commit comments

Comments
 (0)