From 95c98eb3ee9fcb3913ecb6c2618fcdaf3c8ce60a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Mar 2011 22:12:21 +1030 Subject: [PATCH] tdb2: check for invalid flags in tdb_open. This is vitally important for forwards compatibility. --- ccan/tdb2/doc/design.lyx | 6 ++++++ ccan/tdb2/tdb.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/ccan/tdb2/doc/design.lyx b/ccan/tdb2/doc/design.lyx index d9488d04..cc453e58 100644 --- a/ccan/tdb2/doc/design.lyx +++ b/ccan/tdb2/doc/design.lyx @@ -785,9 +785,15 @@ Status \end_layout \begin_layout Standard + +\change_deleted 0 1300360559 Incomplete. TDB_VOLATILE still defined, but implementation should fail on unknown flags to be future-proof. +\change_inserted 0 1300360588 +Complete. + Unknown flags cause tdb_open() to fail as well, so they can be detected + at runtime. \end_layout \begin_layout Subsection diff --git a/ccan/tdb2/tdb.c b/ccan/tdb2/tdb.c index 2315c485..ce431208 100644 --- a/ccan/tdb2/tdb.c +++ b/ccan/tdb2/tdb.c @@ -237,6 +237,13 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, attr = attr->base.next; } + if (tdb_flags & ~(TDB_INTERNAL | TDB_NOLOCK | TDB_NOMMAP | TDB_CONVERT + | TDB_NOSYNC)) { + ecode = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, + "tdb_open: unknown flags %u", tdb_flags); + goto fail; + } + if ((open_flags & O_ACCMODE) == O_WRONLY) { ecode = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, "tdb_open: can't open tdb %s write-only", -- 2.39.2