From b17c5d06d2a9f27d3e7b3c3db125da5b977fdaaa Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Tue, 22 Jul 2014 13:01:14 +0100 Subject: [PATCH] Guard max lock setting with error check We weren't checking for an error before setting the DB4 maxlocks parameter, which could cause a NULL dereference in the error path. --- keydb_db4.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/keydb_db4.c b/keydb_db4.c index 369788e..b2d34c5 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -1706,12 +1706,14 @@ struct onak_dbctx *keydb_db4_init(bool readonly) * Up the number of locks we're allowed at once. We base this on * the maximum number of keys we're going to return. */ - maxlocks = config.maxkeys * 16; - if (maxlocks < 1000) { - maxlocks = 1000; + if (ret == 0) { + maxlocks = config.maxkeys * 16; + if (maxlocks < 1000) { + maxlocks = 1000; + } + privctx->dbenv->set_lk_max_locks(privctx->dbenv, maxlocks); + privctx->dbenv->set_lk_max_objects(privctx->dbenv, maxlocks); } - privctx->dbenv->set_lk_max_locks(privctx->dbenv, maxlocks); - privctx->dbenv->set_lk_max_objects(privctx->dbenv, maxlocks); /* * Enable deadlock detection so that we don't block indefinitely on -- 2.39.2