From b067025e8b878706a02f5f315c23fb5ffe9bec0f Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sat, 12 Dec 2015 19:25:06 +0100 Subject: [PATCH 1/3] mdbx: backport - Catch strdup failure in mdb_dbi_open(). Change-Id: I754e8c966cc093f162cfbb33d3b179585e3ea4a2 --- mdb.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mdb.c b/mdb.c index 374a5f8a..4f599dcb 100644 --- a/mdb.c +++ b/mdb.c @@ -9696,6 +9696,7 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned flags, MDB_dbi *dbi) MDB_db dummy; int rc, dbflag, exact; unsigned unused = 0, seq; + char *namedup; size_t len; if (unlikely(!txn || !dbi)) @@ -9764,8 +9765,16 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned flags, MDB_dbi *dbi) MDB_node *node = NODEPTR(mc.mc_pg[mc.mc_top], mc.mc_ki[mc.mc_top]); if (unlikely((node->mn_flags & (F_DUPDATA|F_SUBDATA)) != F_SUBDATA)) return MDB_INCOMPATIBLE; - } else if (rc == MDB_NOTFOUND && (flags & MDB_CREATE)) { - /* Create if requested */ + } else if (! (rc == MDB_NOTFOUND && (flags & MDB_CREATE))) { + return rc; + } + + /* Done here so we cannot fail after creating a new DB */ + if (unlikely((namedup = strdup(name)) == NULL)) + return ENOMEM; + + if (unlikely(rc)) { + /* MDB_NOTFOUND and MDB_CREATE: Create new DB */ data.mv_size = sizeof(MDB_db); data.mv_data = &dummy; memset(&dummy, 0, sizeof(dummy)); @@ -9775,10 +9784,12 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned flags, MDB_dbi *dbi) dbflag |= DB_DIRTY; } - /* OK, got info, add to table */ - if (likely(rc == MDB_SUCCESS)) { + if (unlikely(rc)) { + free(namedup); + } else { + /* Got info, register DBI in this txn */ unsigned slot = unused ? unused : txn->mt_numdbs; - txn->mt_dbxs[slot].md_name.mv_data = strdup(name); + txn->mt_dbxs[slot].md_name.mv_data = namedup; txn->mt_dbxs[slot].md_name.mv_size = len; txn->mt_dbxs[slot].md_rel = NULL; txn->mt_dbflags[slot] = dbflag; From 7086623d9fc1fb5bfef420be034d9b2d56e80806 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 16 Dec 2015 20:33:56 +0300 Subject: [PATCH 2/3] mdbx: drops include Change-Id: Ie7253b2515a6a4cd4a0d976f22d4713f99126ef2 --- reopen.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/reopen.h b/reopen.h index 943ca503..29c9a940 100644 --- a/reopen.h +++ b/reopen.h @@ -31,8 +31,6 @@ # define _GNU_SOURCE #endif -#include - #ifndef __has_attribute # define __has_attribute(x) (0) #endif From c0c3c1b688df8ed59d431474e42c1a43d1820715 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 16 Dec 2015 21:35:43 +0300 Subject: [PATCH 3/3] mdbx: force gdb-level3 for debuginfo. Change-Id: Ie11630f4c56482862d765764e5e0c4c9564a476b --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d583eca2..b8c261be 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ mandir ?= $(prefix)/man CC ?= gcc XCFLAGS ?= -CFLAGS ?= -O2 -g -Wall -Werror -Wno-unused-parameter +CFLAGS ?= -O2 -ggdb3 -Wall -Werror -Wno-unused-parameter CFLAGS += -pthread $(XCFLAGS) ########################################################################