X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftransaction.c;h=dd94510c027343d1c6aac0e6ec0d6e3d28ffeaab;hp=1af1c4acafa90b44de277e147cb5d6cfc84fdd6c;hb=926996e88c32445c874ff9c4f47f159db6b45995;hpb=afa6d57b7d93fe4675a952f556eb462951baa257 diff --git a/ccan/tdb2/transaction.c b/ccan/tdb2/transaction.c index 1af1c4ac..dd94510c 100644 --- a/ccan/tdb2/transaction.c +++ b/ccan/tdb2/transaction.c @@ -345,16 +345,16 @@ static void transaction_write_existing(struct tdb_context *tdb, tdb_off_t off, /* out of bounds check during a transaction */ -static enum TDB_ERROR transaction_oob(struct tdb_context *tdb, tdb_off_t len, - bool probe) +static enum TDB_ERROR transaction_oob(struct tdb_context *tdb, + tdb_off_t off, tdb_len_t len, bool probe) { - if (len <= tdb->file->map_size || probe) { + if ((off + len >= off && off + len <= tdb->file->map_size) || probe) { return TDB_SUCCESS; } tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, "tdb_oob len %lld beyond transaction size %lld", - (long long)len, + (long long)(off + len), (long long)tdb->file->map_size); return TDB_ERR_IO; } @@ -601,7 +601,7 @@ enum TDB_ERROR tdb_transaction_start(struct tdb_context *tdb) /* make sure we know about any file expansions already done by anyone else */ - tdb->tdb2.io->oob(tdb, tdb->file->map_size + 1, true); + tdb->tdb2.io->oob(tdb, tdb->file->map_size, 1, true); tdb->tdb2.transaction->old_map_size = tdb->file->map_size; /* finally hook the io methods, replacing them with @@ -836,10 +836,13 @@ static tdb_off_t create_recovery_area(struct tdb_context *tdb, /* round up to a multiple of page size. Overallocate, since each * such allocation forces us to expand the file. */ - rec->max_len - = (((sizeof(*rec) + rec_length + rec_length / 2) - + PAGESIZE-1) & ~(PAGESIZE-1)) + rec->max_len = tdb_expand_adjust(tdb->file->map_size, rec_length); + + /* Round up to a page. */ + rec->max_len = ((sizeof(*rec) + rec->max_len + PAGESIZE-1) + & ~(PAGESIZE-1)) - sizeof(*rec); + off = tdb->file->map_size; /* Restore ->map_size before calling underlying expand_file.