diff options
author | Volker Lendecke <vl@samba.org> | 2013-05-30 14:52:59 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2013-06-03 10:21:20 +0200 |
commit | 4483bf143ddfee9ec07aed8f124559b00f757d9a (patch) | |
tree | 45f4a34ac35fefca010248428f30c0d1bfa27c75 /lib/tdb | |
parent | 42b0b275059f9c98b9bf417f2048fdc973449def (diff) | |
download | samba-4483bf143ddfee9ec07aed8f124559b00f757d9a.tar.gz samba-4483bf143ddfee9ec07aed8f124559b00f757d9a.tar.bz2 samba-4483bf143ddfee9ec07aed8f124559b00f757d9a.zip |
tdb: Add overflow-checking tdb_add_off_t
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/tdb.c | 11 | ||||
-rw-r--r-- | lib/tdb/common/tdb_private.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c index a2ae187f57..6256a05d04 100644 --- a/lib/tdb/common/tdb.c +++ b/lib/tdb/common/tdb.c @@ -1000,6 +1000,17 @@ bool tdb_write_all(int fd, const void *buf, size_t count) return true; } +bool tdb_add_off_t(tdb_off_t a, tdb_off_t b, tdb_off_t *pret) +{ + tdb_off_t ret = a + b; + + if ((ret < a) || (ret < b)) { + return false; + } + *pret = ret; + return true; +} + #ifdef TDB_TRACE static void tdb_trace_write(struct tdb_context *tdb, const char *str) { diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h index 406fc5f7f2..c37246f150 100644 --- a/lib/tdb/common/tdb_private.h +++ b/lib/tdb/common/tdb_private.h @@ -282,4 +282,5 @@ void tdb_header_hash(struct tdb_context *tdb, uint32_t *magic1_hash, uint32_t *magic2_hash); unsigned int tdb_old_hash(TDB_DATA *key); size_t tdb_dead_space(struct tdb_context *tdb, tdb_off_t off); +bool tdb_add_off_t(tdb_off_t a, tdb_off_t b, tdb_off_t *pret); #endif /* TDB_PRIVATE_H */ |