Browse Source

tdb2: check for invalid flags in tdb_open.

This is vitally important for forwards compatibility.
Rusty Russell 15 years ago
parent
commit
95c98eb3ee
2 changed files with 13 additions and 0 deletions
  1. 6 0
      ccan/tdb2/doc/design.lyx
  2. 7 0
      ccan/tdb2/tdb.c

+ 6 - 0
ccan/tdb2/doc/design.lyx

@@ -785,9 +785,15 @@ Status
 \end_layout
 \end_layout
 
 
 \begin_layout Standard
 \begin_layout Standard
+
+\change_deleted 0 1300360559
 Incomplete.
 Incomplete.
  TDB_VOLATILE still defined, but implementation should fail on unknown flags
  TDB_VOLATILE still defined, but implementation should fail on unknown flags
  to be future-proof.
  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
 \end_layout
 
 
 \begin_layout Subsection
 \begin_layout Subsection

+ 7 - 0
ccan/tdb2/tdb.c

@@ -237,6 +237,13 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 		attr = attr->base.next;
 		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) {
 	if ((open_flags & O_ACCMODE) == O_WRONLY) {
 		ecode = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
 		ecode = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
 				   "tdb_open: can't open tdb %s write-only",
 				   "tdb_open: can't open tdb %s write-only",