From b64494535dc62f4073fc6302847593ed6e6ec38b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 19 Dec 2011 15:47:50 +1030 Subject: tdb: be more careful on 4G files. I came across a tdb which had wrapped to 4G + 4K, and the contents had been destroyed by processes which thought it only 4k long. Fix this by checking on open, and making tdb_oob() check for wrap itself. Signed-off-by: Rusty Russell Autobuild-User: Rusty Russell Autobuild-Date: Mon Dec 19 07:52:01 CET 2011 on sn-devel-104 --- lib/tdb/common/open.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/tdb/common/open.c') diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index ec45689ffc..2965ea77b5 100644 --- a/lib/tdb/common/open.c +++ b/lib/tdb/common/open.c @@ -385,7 +385,17 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td goto fail; } + /* Beware truncation! */ tdb->map_size = st.st_size; + if (tdb->map_size != st.st_size) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " + "len %llu too large!\n", (long long)st.st_size)); + errno = EIO; + goto fail; + } + tdb->device = st.st_dev; tdb->inode = st.st_ino; tdb_mmap(tdb); -- cgit