gluster-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gluster-devel] [PATCH BUG:393 10/10] transport/encryption: fix encrypti


From: Corentin Chary
Subject: [Gluster-devel] [PATCH BUG:393 10/10] transport/encryption: fix encryption when used with afr
Date: Wed, 18 Nov 2009 12:14:02 +0100

afr (and others) use the same vector for each write,
this resulted in double encrypted messages, because the original
vector was modified.

Signed-off-by: Corentin Chary <address@hidden>
---
 libglusterfs/src/transport.c |   40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/libglusterfs/src/transport.c b/libglusterfs/src/transport.c
index b88de9f..ad557b4 100644
--- a/libglusterfs/src/transport.c
+++ b/libglusterfs/src/transport.c
@@ -319,7 +319,8 @@ transport_submit (transport_t *this, char *buf, int32_t len,
 {
        int32_t               ret = -1;
         transport_t          *peer_trans = NULL;
-        struct iobuf         *iobuf = NULL;
+        struct iobuf         *iobuf  = NULL;
+        struct iobuf         *iobufc = NULL;
         struct transport_msg *msg = NULL;
        gf_hdr_common_t      *hdr;
 
@@ -327,6 +328,21 @@ transport_submit (transport_t *this, char *buf, int32_t 
len,
        hdr->crypto = hton32 (this->crypto.magic);
 
        if (this->crypto.ops && this->crypto.ops->encrypt) {
+               if (vector) {
+                       iobufc = iobuf_get (this->xl->ctx->iobuf_pool);
+                       if (!iobufc)
+                               return -ENOMEM;
+
+                       vector = iov_dup (vector, count);
+                       if (!vector) {
+                               ret = -ENOMEM;
+                               goto fail;
+                       }
+
+                       iov_unload (iobufc->ptr, vector, count);
+                       iov_link (vector, count, iobufc->ptr);
+               }
+
                ret = this->crypto.ops->encrypt (&this->crypto, buf,
                                                 len, vector, count);
                if (ret)
@@ -338,7 +354,8 @@ transport_submit (transport_t *this, char *buf, int32_t len,
 
                 msg = CALLOC (1, sizeof (*msg));
                 if (!msg) {
-                        return -ENOMEM;
+                        ret = -ENOMEM;
+                       goto fail;
                 }
 
                 msg->hdr = buf;
@@ -349,7 +366,8 @@ transport_submit (transport_t *this, char *buf, int32_t len,
                         if (!iobuf) {
                                 FREE (msg->hdr);
                                 FREE (msg);
-                                return -ENOMEM;
+                                ret = -ENOMEM;
+                               goto fail;
                         }
 
                         iov_unload (iobuf->ptr, vector, count);
@@ -364,14 +382,18 @@ transport_submit (transport_t *this, char *buf, int32_t 
len,
                 }
                 pthread_mutex_unlock (&peer_trans->handover.mutex);
 
-                return 0;
-        }
-
-       GF_VALIDATE_OR_GOTO("transport", this, fail);
-       GF_VALIDATE_OR_GOTO("transport", this->ops, fail);
+               ret = 0;
+        } else {
+               GF_VALIDATE_OR_GOTO("transport", this, fail);
+               GF_VALIDATE_OR_GOTO("transport", this->ops, fail);
 
-       ret = this->ops->submit (this, buf, len, vector, count, iobref);
+               ret = this->ops->submit (this, buf, len, vector, count, iobref);
+       }
 fail:
+       if (iobufc) {
+               iobuf_unref (iobufc);
+               FREE (vector);
+       }
        return ret;
 }
 
-- 
1.6.4.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]