tdb: Add overflow-checking tdb_add_off_t
authorVolker Lendecke <vl@samba.org>
Thu, 30 May 2013 12:52:59 +0000 (14:52 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 3 Jun 2013 08:21:20 +0000 (10:21 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
lib/tdb/common/tdb.c
lib/tdb/common/tdb_private.h

index a2ae187f57720f477877d258739d008cf1d3dc65..6256a05d04ebf53f7cd9913abaf713802fe95530 100644 (file)
@@ -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)
 {
index 406fc5f7f2052eb3d457b60d098efa5b84e1dbdb..c37246f1503f779761251881fa27000156286a69 100644 (file)
@@ -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 */