From f56b866f92e195ffd24a2f8f80e8e2cef226c775 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 3 Jul 2013 16:30:32 +0000 Subject: 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. --- alloc.c | 5 +++++ mgmt.c | 7 +++++-- 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: -- cgit v1.2.3-24-ge0c7