summaryrefslogtreecommitdiff
path: root/lib/tdb
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2013-05-28 12:59:32 +0200
committerVolker Lendecke <vl@samba.org>2013-06-03 10:21:27 +0200
commite19d46f7e31a32e2b5ae3ec05e13f32b8ac2109d (patch)
treed0f6a042d849fc0a98fc49058ed7b38743bd3767 /lib/tdb
parenta07ba17e0c91d726416db946e6f65b064b2d17ec (diff)
downloadsamba-e19d46f7e31a32e2b5ae3ec05e13f32b8ac2109d.tar.gz
samba-e19d46f7e31a32e2b5ae3ec05e13f32b8ac2109d.tar.bz2
samba-e19d46f7e31a32e2b5ae3ec05e13f32b8ac2109d.zip
tdb: add overflow/ENOSPC handling to tdb_expand_file()
Pair-Programmed-With: Volker Lendecke <vl@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb')
-rw-r--r--lib/tdb/common/io.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c
index 44ef7289a6..d17764008f 100644
--- a/lib/tdb/common/io.c
+++ b/lib/tdb/common/io.c
@@ -294,7 +294,14 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
return -1;
}
- new_size = size + addition;
+ if (!tdb_add_off_t(size, addition, &new_size)) {
+ tdb->ecode = TDB_ERR_OOM;
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write "
+ "overflow detected current size[%u] addition[%u]!\n",
+ (unsigned)size, (unsigned)addition));
+ errno = ENOSPC;
+ return -1;
+ }
if (ftruncate(tdb->fd, new_size) == -1) {
char b = 0;
@@ -308,6 +315,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
errno = ENOSPC;
}
if (written != 1) {
+ tdb->ecode = TDB_ERR_OOM;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %u failed (%s)\n",
(unsigned)new_size, strerror(errno)));
return -1;
@@ -327,12 +335,14 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
}
if (written == 0) {
/* give up, trying to provide a useful errno */
+ tdb->ecode = TDB_ERR_OOM;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write "
"returned 0 twice: giving up!\n"));
errno = ENOSPC;
return -1;
}
if (written == -1) {
+ tdb->ecode = TDB_ERR_OOM;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of "
"%u bytes failed (%s)\n", (int)n,
strerror(errno)));