tdb: Introduce tdb_oob()
authorVolker Lendecke <vl@samba.org>
Sun, 4 Aug 2019 10:15:14 +0000 (12:15 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 6 Aug 2019 21:49:27 +0000 (21:49 +0000)
Initially just encapsulate the pointer dereferences

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tdb/common/check.c
lib/tdb/common/freelist.c
lib/tdb/common/io.c
lib/tdb/common/open.c
lib/tdb/common/rescue.c
lib/tdb/common/tdb_private.h
lib/tdb/common/transaction.c
lib/tdb/common/traverse.c

index 3a5c8b8ba94952019500926466eb1b05922ffedd..d7741f6b2f9d7dfe4a836aeb3439bcb3b3d6d518 100644 (file)
@@ -94,7 +94,7 @@ static bool tdb_check_record(struct tdb_context *tdb,
                         off, rec->next));
                goto corrupt;
        }
-       if (tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 0))
+       if (tdb_oob(tdb, rec->next, sizeof(*rec), 0))
                goto corrupt;
 
        /* Check rec_len: similar to rec->next, implies next record. */
@@ -112,7 +112,7 @@ static bool tdb_check_record(struct tdb_context *tdb,
                goto corrupt;
        }
        /* OOB allows "right at the end" access, so this works for last rec. */
-       if (tdb->methods->tdb_oob(tdb, off, sizeof(*rec)+rec->rec_len, 0))
+       if (tdb_oob(tdb, off, sizeof(*rec)+rec->rec_len, 0))
                goto corrupt;
 
        /* Check tailer. */
@@ -362,7 +362,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
        }
 
        /* Make sure we know true size of the underlying file. */
-       tdb->methods->tdb_oob(tdb, tdb->map_size, 1, 1);
+       tdb_oob(tdb, tdb->map_size, 1, 1);
 
        /* Header must be OK: also gets us the recovery ptr, if any. */
        if (!tdb_check_header(tdb, &recovery_start))
index 37a4c168533b52e8f91d2aae8b6af974162d4784..046c747cf9b3f58033ae587e473119b4fd2bca27 100644 (file)
@@ -50,7 +50,7 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record
                           rec->magic, off));
                return -1;
        }
-       if (tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 0) != 0)
+       if (tdb_oob(tdb, rec->next, sizeof(*rec), 0) != 0)
                return -1;
        return 0;
 }
index 06492b1407d70d89912ef36083af01e7351c9d0e..f3ea7bf9856c7a094f57f5253ac3e65d36b1278b 100644 (file)
@@ -216,7 +216,7 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
                return -1;
        }
 
-       if (tdb->methods->tdb_oob(tdb, off, len, 0) != 0)
+       if (tdb_oob(tdb, off, len, 0) != 0)
                return -1;
 
        if (tdb->map_ptr) {
@@ -271,7 +271,7 @@ void *tdb_convert(void *buf, uint32_t size)
 static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
                    tdb_len_t len, int cv)
 {
-       if (tdb->methods->tdb_oob(tdb, off, len, 0) != 0) {
+       if (tdb_oob(tdb, off, len, 0) != 0) {
                return -1;
        }
 
@@ -596,7 +596,7 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
        }
 
        /* must know about any previous expansions by another process */
-       tdb->methods->tdb_oob(tdb, tdb->map_size, 1, 1);
+       tdb_oob(tdb, tdb->map_size, 1, 1);
 
        /*
         * Note: that we don't care about tdb->hdr_ofs != 0 here
@@ -662,6 +662,12 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
        return -1;
 }
 
+int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len, int probe)
+{
+       int ret = tdb->methods->tdb_oob(tdb, off, len, probe);
+       return ret;
+}
+
 /* read/write a tdb_off_t */
 int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d)
 {
@@ -714,7 +720,7 @@ int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
                 * Optimize by avoiding the malloc/memcpy/free, point the
                 * parser directly at the mmap area.
                 */
-               if (tdb->methods->tdb_oob(tdb, offset, len, 0) != 0) {
+               if (tdb_oob(tdb, offset, len, 0) != 0) {
                        return -1;
                }
                data.dptr = offset + (unsigned char *)tdb->map_ptr;
@@ -756,20 +762,20 @@ int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *r
                return -1;
        }
 
-       ret = tdb->methods->tdb_oob(tdb, offset, rec->key_len, 1);
+       ret = tdb_oob(tdb, offset, rec->key_len, 1);
        if (ret == -1) {
                return -1;
        }
-       ret = tdb->methods->tdb_oob(tdb, offset, rec->data_len, 1);
+       ret = tdb_oob(tdb, offset, rec->data_len, 1);
        if (ret == -1) {
                return -1;
        }
-       ret = tdb->methods->tdb_oob(tdb, offset, rec->rec_len, 1);
+       ret = tdb_oob(tdb, offset, rec->rec_len, 1);
        if (ret == -1) {
                return -1;
        }
 
-       return tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 0);
+       return tdb_oob(tdb, rec->next, sizeof(*rec), 0);
 }
 
 int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
index dd5783ef8bc959409a962d56ad50b0b24490bd8f..f7f65b0e2379048a58f280775e28831f5d9eb316 100644 (file)
@@ -655,7 +655,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
         * As this skips tdb->hdr_ofs.
         */
        tdb->map_size = 0;
-       ret = tdb->methods->tdb_oob(tdb, 0, 1, 0);
+       ret = tdb_oob(tdb, 0, 1, 0);
        if (ret == -1) {
                errno = EIO;
                goto fail;
@@ -677,7 +677,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
                goto fail;
        }
 
-       ret = tdb->methods->tdb_oob(tdb, FREELIST_TOP, 4*tdb->hash_size, 1);
+       ret = tdb_oob(tdb, FREELIST_TOP, 4*tdb->hash_size, 1);
        if (ret == -1) {
                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
                         "hash size %"PRIu32" does not fit\n", tdb->hash_size));
@@ -895,7 +895,7 @@ static int tdb_reopen_internal(struct tdb_context *tdb, bool active_lock)
         * As this skips tdb->hdr_ofs.
         */
        tdb->map_size = 0;
-       if (tdb->methods->tdb_oob(tdb, 0, 1, 0) != 0) {
+       if (tdb_oob(tdb, 0, 1, 0) != 0) {
                goto fail;
        }
 #endif /* fake pread or pwrite */
index e608db41deab4061b00fa469b8b5704ee993e8c8..7a85ebc9311cde1d76b6bf4fca0102b572c013f3 100644 (file)
@@ -60,7 +60,7 @@ static bool looks_like_valid_record(struct tdb_context *tdb,
        if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->hash_size))
                return false;
 
-       if (tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 1))
+       if (tdb_oob(tdb, rec->next, sizeof(*rec), 1))
                return false;
 
        key->dsize = rec->key_len;
@@ -228,7 +228,7 @@ _PUBLIC_ int tdb_rescue(struct tdb_context *tdb,
        }
 
        /* Make sure we know true size of the underlying file. */
-       tdb->methods->tdb_oob(tdb, tdb->map_size, 1, 1);
+       tdb_oob(tdb, tdb->map_size, 1, 1);
 
        /* Suppress logging, since we anticipate errors. */
        tdb->log.log_fn = logging_suppressed;
index 42aaac62f59c33895aef0188fb7df6c79238db9a..2bed8200f94aa651a55f0e63625db90277519380 100644 (file)
@@ -304,6 +304,7 @@ void *tdb_convert(void *buf, uint32_t size);
 int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
 tdb_off_t tdb_allocate(struct tdb_context *tdb, int hash, tdb_len_t length,
                       struct tdb_record *rec);
+int tdb_oob(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len, int probe);
 int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
 int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
 int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off);
index e9b0b26ea59b22fed948c74b9e96bc2dd221b647..b22624820d7e59964f9c349254c99be1c2e87e80 100644 (file)
@@ -524,7 +524,7 @@ static int _tdb_transaction_start(struct tdb_context *tdb,
 
        /* make sure we know about any file expansions already done by
           anyone else */
-       tdb->methods->tdb_oob(tdb, tdb->map_size, 1, 1);
+       tdb_oob(tdb, tdb->map_size, 1, 1);
        tdb->transaction->old_map_size = tdb->map_size;
 
        /* finally hook the io methods, replacing them with
index 54a69dc8d03f43ad4db7275c5bee98736aea413d..d69e7dff2854eb55163fa81e44d11672b2eb16ff 100644 (file)
@@ -453,8 +453,7 @@ _PUBLIC_ int tdb_traverse_chain(struct tdb_context *tdb,
 
                        if ((tdb->transaction == NULL) &&
                            (tdb->map_ptr != NULL)) {
-                               ret = tdb->methods->tdb_oob(
-                                       tdb, key_ofs, full_len, 0);
+                               ret = tdb_oob(tdb, key_ofs, full_len, 0);
                                if (ret == -1) {
                                        goto fail;
                                }