The branch, master has been updated
       via  0f9b35d torture: NULL out after talloc_free
       via  3eda09d lib: Fix a comment
       via  2e43128 lib: Use iov_advance in write_data_iov
       via  475cfb8 lib: Use iov_advance in writev_handler
       via  8855c03 lib: Add iov_advance
       via  b4ceef0 lib: iov_buf does not need talloc.h anymore
      from  40a0a90 lib: Use talloc_memdup in messaging_rec_dup

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


- Log -----------------------------------------------------------------
commit 0f9b35d4d4d2df61c197d5392546f3c26c25e940
Author: Garming Sam <[email protected]>
Date:   Tue Dec 30 09:36:37 2014 +1300

    torture: NULL out after talloc_free
    
    This appeared as a segmentation fault in rpc.spoolss.printer.
    
    Signed-off-by: Garming Sam <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>
    
    Autobuild-User(master): Jeremy Allison <[email protected]>
    Autobuild-Date(master): Tue Dec 30 02:49:01 CET 2014 on sn-devel-104

commit 3eda09d7eb3fcfdfbe5fc436c774c8fbc82a016f
Author: Volker Lendecke <[email protected]>
Date:   Sat Dec 27 16:51:32 2014 +0000

    lib: Fix a comment
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 2e431289120681771e4791bdd7aae4397855e187
Author: Volker Lendecke <[email protected]>
Date:   Sat Dec 27 16:48:55 2014 +0000

    lib: Use iov_advance in write_data_iov
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 475cfb8dee6cdb5a89e8f15b32ad3886f949005f
Author: Volker Lendecke <[email protected]>
Date:   Sat Dec 27 16:39:08 2014 +0000

    lib: Use iov_advance in writev_handler
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 8855c0332a5ad2996873727074af6974f1238d5f
Author: Volker Lendecke <[email protected]>
Date:   Sat Dec 27 13:16:20 2014 +0000

    lib: Add iov_advance
    
    This chops off n bytes from an iovec array. Used for short writev's
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit b4ceef0230a13a66e91f33d831a5e77babaef0ed
Author: Volker Lendecke <[email protected]>
Date:   Sat Dec 27 12:24:13 2014 +0000

    lib: iov_buf does not need talloc.h anymore
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

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

Summary of changes:
 lib/async_req/async_sock.c  | 34 +++++++++-------------------------
 lib/async_req/wscript_build |  2 +-
 lib/torture/torture.c       |  1 +
 source3/lib/iov_buf.c       | 33 +++++++++++++++++++++++++++++++++
 source3/lib/iov_buf.h       |  3 ++-
 source3/lib/sys_rw_data.c   | 26 +++++++-------------------
 6 files changed, 53 insertions(+), 46 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c
index 74b2cb7..b986e45 100644
--- a/lib/async_req/async_sock.c
+++ b/lib/async_req/async_sock.c
@@ -27,6 +27,7 @@
 #include <talloc.h>
 #include <tevent.h>
 #include "lib/async_req/async_sock.h"
+#include "lib/iov_buf.h"
 
 /* Note: lib/util/ is currently GPL */
 #include "lib/util/tevent_unix.h"
@@ -470,10 +471,8 @@ static void writev_handler(struct tevent_context *ev, 
struct tevent_fd *fde,
                private_data, struct tevent_req);
        struct writev_state *state =
                tevent_req_data(req, struct writev_state);
-       size_t to_write, written;
-       int i;
-
-       to_write = 0;
+       size_t written;
+       bool ok;
 
        if ((state->flags & TEVENT_FD_READ) && (flags & TEVENT_FD_READ)) {
                int ret, value;
@@ -507,10 +506,6 @@ static void writev_handler(struct tevent_context *ev, 
struct tevent_fd *fde,
                }
        }
 
-       for (i=0; i<state->count; i++) {
-               to_write += state->iov[i].iov_len;
-       }
-
        written = writev(state->fd, state->iov, state->count);
        if ((written == -1) && (errno == EINTR)) {
                /* retry */
@@ -526,26 +521,15 @@ static void writev_handler(struct tevent_context *ev, 
struct tevent_fd *fde,
        }
        state->total_size += written;
 
-       if (written == to_write) {
-               tevent_req_done(req);
+       ok = iov_advance(&state->iov, &state->count, written);
+       if (!ok) {
+               tevent_req_error(req, EIO);
                return;
        }
 
-       /*
-        * We've written less than we were asked to, drop stuff from
-        * state->iov.
-        */
-
-       while (written > 0) {
-               if (written < state->iov[0].iov_len) {
-                       state->iov[0].iov_base =
-                               (char *)state->iov[0].iov_base + written;
-                       state->iov[0].iov_len -= written;
-                       break;
-               }
-               written -= state->iov[0].iov_len;
-               state->iov += 1;
-               state->count -= 1;
+       if (state->count == 0) {
+               tevent_req_done(req);
+               return;
        }
 }
 
diff --git a/lib/async_req/wscript_build b/lib/async_req/wscript_build
index 7802935..e8af569 100644
--- a/lib/async_req/wscript_build
+++ b/lib/async_req/wscript_build
@@ -3,7 +3,7 @@
 
 bld.SAMBA_SUBSYSTEM('LIBASYNC_REQ',
        source='async_sock.c',
-       public_deps='talloc tevent',
+       public_deps='talloc tevent iov_buf',
        deps='tevent-util socket-blocking'
        )
 
diff --git a/lib/torture/torture.c b/lib/torture/torture.c
index ff2f8c8..78d8261 100644
--- a/lib/torture/torture.c
+++ b/lib/torture/torture.c
@@ -460,6 +460,7 @@ static bool internal_torture_run_test(struct 
torture_context *context,
                               context->last_reason);
 
        talloc_free(context->last_reason);
+       context->last_reason = NULL;
 
        context->active_test = NULL;
        context->active_tcase = NULL;
diff --git a/source3/lib/iov_buf.c b/source3/lib/iov_buf.c
index e05dfc9..f0e05a6 100644
--- a/source3/lib/iov_buf.c
+++ b/source3/lib/iov_buf.c
@@ -53,3 +53,36 @@ ssize_t iov_buf(const struct iovec *iov, int iovcnt,
 
        return needed;
 }
+
+bool iov_advance(struct iovec **iov, int *iovcnt, size_t n)
+{
+       struct iovec *v = *iov;
+       int cnt = *iovcnt;
+
+       while (n > 0) {
+               if (cnt == 0) {
+                       return false;
+               }
+               if (n < v->iov_len) {
+                       v->iov_base = (char *)v->iov_base + n;
+                       v->iov_len -= n;
+                       break;
+               }
+               n -= v->iov_len;
+               v += 1;
+               cnt -= 1;
+       }
+
+       /*
+        * Skip 0-length iovec's
+        */
+
+       while ((cnt > 0) && (v->iov_len == 0)) {
+               v += 1;
+               cnt -= 1;
+       }
+
+       *iov = v;
+       *iovcnt = cnt;
+       return true;
+}
diff --git a/source3/lib/iov_buf.h b/source3/lib/iov_buf.h
index ec82909..8f0ca26 100644
--- a/source3/lib/iov_buf.h
+++ b/source3/lib/iov_buf.h
@@ -21,11 +21,12 @@
 #define __LIB_IOV_BUF_H__
 
 #include <unistd.h>
-#include <talloc.h>
 #include <stdint.h>
+#include <stdbool.h>
 
 ssize_t iov_buflen(const struct iovec *iov, int iovlen);
 ssize_t iov_buf(const struct iovec *iov, int iovcnt,
                uint8_t *buf, size_t buflen);
+bool iov_advance(struct iovec **iov, int *iovcnt, size_t n);
 
 #endif
diff --git a/source3/lib/sys_rw_data.c b/source3/lib/sys_rw_data.c
index 353dbe7..7198783 100644
--- a/source3/lib/sys_rw_data.c
+++ b/source3/lib/sys_rw_data.c
@@ -54,31 +54,19 @@ ssize_t write_data_iov(int fd, const struct iovec 
*orig_iov, int iovcnt)
 
        /*
         * We could not send everything in one call. Make a copy of iov that
-        * we can mess with. We keep a copy of the array start in iov_copy for
-        * the TALLOC_FREE, because we're going to modify iov later on,
-        * discarding elements.
+        * we can mess with.
         */
 
        memcpy(iov_copy, orig_iov, sizeof(struct iovec) * iovcnt);
        iov = iov_copy;
 
        while (sent < to_send) {
-               /*
-                * We have to discard "thistime" bytes from the beginning
-                * iov array, "thistime" contains the number of bytes sent
-                * via writev last.
-                */
-               while (thistime > 0) {
-                       if (thistime < iov[0].iov_len) {
-                               char *new_base =
-                                       (char *)iov[0].iov_base + thistime;
-                               iov[0].iov_base = (void *)new_base;
-                               iov[0].iov_len -= thistime;
-                               break;
-                       }
-                       thistime -= iov[0].iov_len;
-                       iov += 1;
-                       iovcnt -= 1;
+               bool ok;
+
+               ok = iov_advance(&iov, &iovcnt, thistime);
+               if (!ok) {
+                       errno = EIO;
+                       return -1;
                }
 
                thistime = sys_writev(fd, iov, iovcnt);


-- 
Samba Shared Repository

Reply via email to