daemon: Fix issue 2348, db->filenam not being correctly initialized

We were not correctly allocating the `db->filename`, failing to copy the
null-terminator. This was causing and error when reopening the database after
the call to `fork()`.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Reported-by: Sean McNally <@sfmcnally>
Changelog-fixed: Fixed a crash when running in daemon-mode due to db filename overrun
This commit is contained in:
Christian Decker 2019-02-17 15:40:53 +01:00
parent 3db534580c
commit a405c22fc9

View File

@ -557,7 +557,7 @@ static struct db *db_open(const tal_t *ctx, char *filename)
} }
db = tal(ctx, struct db); db = tal(ctx, struct db);
db->filename = tal_dup_arr(db, char, filename, strlen(filename), 0); db->filename = tal_strdup(db, filename);
db->sql = sql; db->sql = sql;
tal_add_destructor(db, destroy_db); tal_add_destructor(db, destroy_db);
db->in_transaction = NULL; db->in_transaction = NULL;