tdb: Truncate the file after expand failure
authorVolker Lendecke <vl@samba.org>
Wed, 23 Aug 2017 10:48:03 +0000 (12:48 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 23 Aug 2017 23:46:08 +0000 (01:46 +0200)
commitc7211882a79a99ed70a1aceeafa232cd521c915d
treef3e8254388f6f20cf012620a16e9b4582d046ec6
parent3e7efbfb36a54e99bda55a0695b645f6a09e99a3
tdb: Truncate the file after expand failure

Without this it's very easy to create virtually huge files: ftruncate expands a
file, the pwrites fail with ENOSPC, thus the write fails. The next writer runs
into the same situation, and ftruncate-expands the file even further. tdb_check
will then spend ages reading the 4GB of zeros byte by byte.

Here we hold the freelist lock or are inside a transaction, so it is safe to
cut the file again. Nobody can have used the space that we have tried to
allocate, so we can't have any stray pointers corrupting the database.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/tdb/common/io.c