The branch, master has been updated
       via  d7e60bc tdb: Do not allow to pass NULL as the buffer to 
transaction_write()
       via  47bb276 tdb: Write zero data using 8k buffer in 
transaction_expand_file()
       via  f6a382f tdb: Avoid NULL tdb_write
       via  5c55c25 tdb: Consistency check for tdb_storev
      from  d55c27a vfs_fruit: factor out common code from ad_get() and 
ad_fget()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d7e60bc17e1f5428e5459e6d60a7c8b1f146a3aa
Author: Andreas Schneider <a...@samba.org>
Date:   Wed Aug 9 09:58:35 2017 +0200

    tdb: Do not allow to pass NULL as the buffer to transaction_write()
    
    This fixes a GCC warning.
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>
    
    Autobuild-User(master): Andreas Schneider <a...@cryptomilk.org>
    Autobuild-Date(master): Thu Aug 10 02:26:09 CEST 2017 on sn-devel-144

commit 47bb27652e909ff411bea9000fd1a9f186458f3b
Author: Andreas Schneider <a...@samba.org>
Date:   Wed Aug 9 10:53:12 2017 +0200

    tdb: Write zero data using 8k buffer in transaction_expand_file()
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit f6a382fff822a0e01be8d8689328ef98dab47873
Author: Volker Lendecke <v...@samba.org>
Date:   Wed Aug 9 10:16:36 2017 +0200

    tdb: Avoid NULL tdb_write
    
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

commit 5c55c2563d04b563a7fd7027cf3128cb05b34fad
Author: Volker Lendecke <v...@samba.org>
Date:   Wed Aug 9 10:15:27 2017 +0200

    tdb: Consistency check for tdb_storev
    
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Andreas Schneider <a...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/tdb/common/tdb.c         |  9 +++++++++
 lib/tdb/common/transaction.c | 32 ++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c
index a67d8fb..04f7f97 100644
--- a/lib/tdb/common/tdb.c
+++ b/lib/tdb/common/tdb.c
@@ -541,6 +541,11 @@ static int _tdb_storev(struct tdb_context *tdb, TDB_DATA 
key,
        for (i=0; i<num_dbufs; i++) {
                size_t dsize = dbufs[i].dsize;
 
+               if ((dsize != 0) && (dbufs[i].dptr == NULL)) {
+                       tdb->ecode = TDB_ERR_EINVAL;
+                       goto fail;
+               }
+
                dbufs_len += dsize;
                if (dbufs_len < dsize) {
                        tdb->ecode = TDB_ERR_OOM;
@@ -614,6 +619,10 @@ static int _tdb_storev(struct tdb_context *tdb, TDB_DATA 
key,
        ofs += key.dsize;
 
        for (i=0; i<num_dbufs; i++) {
+               if (dbufs[i].dsize == 0) {
+                       continue;
+               }
+
                ret = tdb->methods->tdb_write(tdb, ofs, dbufs[i].dptr,
                                              dbufs[i].dsize);
                if (ret == -1) {
diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c
index 9b975ea..8ec0025 100644
--- a/lib/tdb/common/transaction.c
+++ b/lib/tdb/common/transaction.c
@@ -210,6 +210,10 @@ static int transaction_write(struct tdb_context *tdb, 
tdb_off_t off,
 {
        uint32_t blk;
 
+       if (buf == NULL) {
+               return -1;
+       }
+
        /* Only a commit is allowed on a prepared transaction */
        if (tdb->transaction->prepared) {
                tdb->ecode = TDB_ERR_EINVAL;
@@ -234,9 +238,7 @@ static int transaction_write(struct tdb_context *tdb, 
tdb_off_t off,
                }
                len -= len2;
                off += len2;
-               if (buf != NULL) {
-                       buf = (const void *)(len2 + (const char *)buf);
-               }
+               buf = (const void *)(len2 + (const char *)buf);
        }
 
        if (len == 0) {
@@ -289,11 +291,7 @@ static int transaction_write(struct tdb_context *tdb, 
tdb_off_t off,
        }
 
        /* overwrite part of an existing block */
-       if (buf == NULL) {
-               memset(tdb->transaction->blocks[blk] + off, 0, len);
-       } else {
-               memcpy(tdb->transaction->blocks[blk] + off, buf, len);
-       }
+       memcpy(tdb->transaction->blocks[blk] + off, buf, len);
        if (blk == tdb->transaction->num_blocks-1) {
                if (len + off > tdb->transaction->last_block_size) {
                        tdb->transaction->last_block_size = len + off;
@@ -393,10 +391,20 @@ static int transaction_oob(struct tdb_context *tdb, 
tdb_off_t off,
 static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size,
                                   tdb_off_t addition)
 {
-       /* add a write to the transaction elements, so subsequent
-          reads see the zero data */
-       if (transaction_write(tdb, size, NULL, addition) != 0) {
-               return -1;
+       const char buf_zero[8192] = {0};
+       size_t buf_len = sizeof(buf_zero);
+
+       while (addition > 0) {
+               size_t n = MIN(addition, buf_len);
+               int ret;
+
+               ret = transaction_write(tdb, size, buf_zero, n);
+               if (ret != 0) {
+                       return ret;
+               }
+
+               addition -= n;
+               size += n;
        }
 
        tdb->transaction->expanded = true;


-- 
Samba Shared Repository

Reply via email to