From: Jonathan McDowell Date: Tue, 22 Jul 2014 12:01:14 +0000 (+0100) Subject: Guard max lock setting with error check X-Git-Tag: onak-0.4.3~9 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=b17c5d06d2a9f27d3e7b3c3db125da5b977fdaaa;p=onak.git 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. --- 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