about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-07-03 16:30:32 +0000
committerEric Wong <normalperson@yhbt.net>2013-07-10 00:55:35 +0000
commitf56b866f92e195ffd24a2f8f80e8e2cef226c775 (patch)
treec7bf4db205273aadc4721e8234c7a1864af03a24
parent5027df50b5072d964f551414e259c2903778ea36 (diff)
downloadcmogstored-f56b866f92e195ffd24a2f8f80e8e2cef226c775.tar.gz
mgmt: fix case where rbuf->rsize may be uninitialized
Detachers MUST set rsize properly.  This API is unfortunately fragile
and will eventually be fixed to be more difficult to misuse.
-rw-r--r--alloc.c5
-rw-r--r--mgmt.c7
2 files changed, 10 insertions, 2 deletions
diff --git a/alloc.c b/alloc.c
index f5ce8bc..a51407f 100644
--- a/alloc.c
+++ b/alloc.c
@@ -102,6 +102,11 @@ struct mog_rbuf *mog_rbuf_new(size_t size)
         else
                 rbuf = xmalloc(bytes);
         rbuf->rcapa = size;
+        /*
+         * do not initialize rsize here, we only need rsize when we detach
+         * a TLS rbuf and associate it with a mog_fd, not in the common
+         * case where the rbuf remains thread-local
+         */
 
         return rbuf;
 }
diff --git a/mgmt.c b/mgmt.c
index 3468e24..a6a1ff5 100644
--- a/mgmt.c
+++ b/mgmt.c
@@ -221,8 +221,11 @@ parse:
         } else {
                 switch (errno) {
                 case_EAGAIN:
-                        if ((buf_len > 0) && (mgmt->rbuf == NULL))
-                                mgmt->rbuf = mog_rbuf_detach(rbuf);
+                        if (buf_len > 0) {
+                                if (mgmt->rbuf == NULL)
+                                        mgmt->rbuf = mog_rbuf_detach(rbuf);
+                                mgmt->rbuf->rsize = buf_len;
+                        }
                         return MOG_NEXT_WAIT_RD;
                 case EINTR: goto reread;
                 case ECONNRESET: