ntdb: simply disallow NULL names.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Jun 2012 03:08:33 +0000 (12:38 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Jun 2012 03:38:06 +0000 (05:38 +0200)
TDB allows this for internal databases, but it's a bad idea, since the
name is useful for logging.

They're a hassle to deal with, and we'd just end up putting "unnamed"
in there, so let the user deal with it.  If they don't, they get an
informative core dump.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/ntdb/ntdb.h
lib/ntdb/open.c
lib/ntdb/test/helprun-layout.c

index f2b80023cdeb6787b3613ebd0d698fa69ed160c8..1a011fddf5bc5455c6a690abbbca413a1634ea35 100644 (file)
@@ -89,7 +89,7 @@ typedef struct TDB_DATA NTDB_DATA;
 
 /**
  * ntdb_open - open a database file
- * @name: the file name (can be NULL if flags contains NTDB_INTERNAL)
+ * @name: the file name (or database name if flags contains NTDB_INTERNAL)
  * @ntdb_flags: options for this database
  * @open_flags: flags argument for ntdb's open() call.
  * @mode: mode argument for ntdb's open() call.
@@ -680,8 +680,7 @@ void ntdb_unset_attribute(struct ntdb_context *ntdb,
  * ntdb_name - get the name of a ntdb
  * @ntdb: the ntdb context returned from ntdb_open()
  *
- * This returns a copy of the name string, made at ntdb_open() time.  If that
- * argument was NULL (possible for a NTDB_INTERNAL db) this will return NULL.
+ * This returns a copy of the name string, made at ntdb_open() time.
  *
  * This is mostly useful for logging.
  */
index 5a781c93287355d4e74ee63915bc6a1b47c0b831..01a0928074ba61ebdb64dc38e6509c1725f47ae6 100644 (file)
@@ -422,18 +422,14 @@ _PUBLIC_ struct ntdb_context *ntdb_open(const char *name, int ntdb_flags,
        enum NTDB_ERROR ecode;
        int openlock;
 
-       ntdb = malloc(sizeof(*ntdb) + (name ? strlen(name) + 1 : 0));
+       ntdb = malloc(sizeof(*ntdb) + strlen(name) + 1);
        if (!ntdb) {
                /* Can't log this */
                errno = ENOMEM;
                return NULL;
        }
        /* Set name immediately for logging functions. */
-       if (name) {
-               ntdb->name = strcpy((char *)(ntdb + 1), name);
-       } else {
-               ntdb->name = NULL;
-       }
+       ntdb->name = strcpy((char *)(ntdb + 1), name);
        ntdb->flags = ntdb_flags;
        ntdb->log_fn = NULL;
        ntdb->open_flags = open_flags;
index c8f1fd03c49b61466b54c484214cc3de5bac2c88..7f1f9f9d8e4b85220024f2fac185ef393ecfc195 100644 (file)
@@ -313,7 +313,7 @@ struct ntdb_context *ntdb_layout_get(struct ntdb_layout *layout,
        /* Fill with some weird pattern. */
        memset(mem, 0x99, off);
        /* Now populate our header, cribbing from a real NTDB header. */
-       ntdb = ntdb_open(NULL, NTDB_INTERNAL, O_RDWR, 0, attr);
+       ntdb = ntdb_open("layout", NTDB_INTERNAL, O_RDWR, 0, attr);
        memcpy(mem, ntdb->file->map_ptr, sizeof(struct ntdb_header));
 
        /* Mug the ntdb we have to make it use this. */