]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Request body is 8 byte aligned
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 5 Oct 2008 23:51:40 +0000 (01:51 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 5 Oct 2008 23:51:40 +0000 (01:51 +0200)
This is due to copying the body to exec_req, where we need the same
alignment as in the receiving buffer.

cdr.c
cdr.h
iop.c

diff --git a/cdr.c b/cdr.c
index 29a5aed9eed44f5373d6fab2f8a712071a29e0ca..85999d2f549f2ed2fa5db6e0bbdbbbc420da2ed9 100644 (file)
--- a/cdr.c
+++ b/cdr.c
@@ -204,6 +204,29 @@ CDR_buffer_putn(CDR_Codec *codec, void *datum, int bsize)
        return CORBA_TRUE;
 }
 
+CORBA_boolean CDR_put_align(CDR_Codec *codec, unsigned bsize)
+{
+        unsigned long forward,i;
+       
+       forward = (unsigned long)ALIGN_ADDRESS(codec->wptr, bsize);
+       if (forward+bsize > codec->wptr_max) {
+               return CORBA_FALSE;
+       }       
+
+       i = codec->wptr;
+        while(forward > i)
+               codec->buffer[i++] = '\0';
+
+       codec->wptr = forward;
+       return CORBA_TRUE;
+}
+
+CORBA_boolean CDR_get_align(CDR_Codec *codec, unsigned bsize)
+{
+       codec->rptr = (unsigned long)ALIGN_ADDRESS(codec->rptr, bsize);
+       return codec->rptr <= codec->wptr_max;
+}
+
 #define CDR_swap2(d,s) forb_byteswap((d), (s), 2)
 #define CDR_swap4(d,s) forb_byteswap((d), (s), 4)
 #define CDR_swap8(d,s) forb_byteswap((d), (s), 8)
diff --git a/cdr.h b/cdr.h
index 142ff1ac1b9223409779c1920171e15cb8ddac41..f37bf026e1ced2e9450c68d13e7b733dc5c5d508 100644 (file)
--- a/cdr.h
+++ b/cdr.h
@@ -137,6 +137,9 @@ extern CORBA_boolean CDR_get_seq_begin(CDR_Codec *codec, CORBA_unsigned_long *ul
 extern CORBA_boolean CDR_get_float(CDR_Codec *codec, CORBA_float *f);
 extern CORBA_boolean CDR_get_double(CDR_Codec *codec, CORBA_double *d);
 
+extern CORBA_boolean CDR_put_align(CDR_Codec *codec, unsigned bsize);
+extern CORBA_boolean CDR_get_align(CDR_Codec *codec, unsigned bsize);
+
 
 /* serialization functions */
 #define CORBA_short_serialize(x,y)             CDR_put_short((x),*(y))
diff --git a/iop.c b/iop.c
index f9e025cb3d7c0ec58af15f72e91e7b6a7859a696..a9a987f6fa481722904fdc623c26538412c7bdb8 100644 (file)
--- a/iop.c
+++ b/iop.c
@@ -55,6 +55,10 @@ forb_iop_prepare_request(forb_request_t *req,
        rh.method_index = method_ind;
        rh.source = forb_object_to_forb(req->obj)->server_id;
        ret = forb_iop_request_header_serialize(&req->cdr_request, &rh);
+       if (ret) {
+               /* Request body is 8 byte aligned */
+               ret = CDR_put_align(&req->cdr_request, 8);
+       }
        return ret;
 }
 
@@ -176,6 +180,13 @@ process_request(forb_port_t *port, CDR_Codec *codec, uint32_t message_size)
                env.major = FORB_EX_COMM_FAILURE;
                goto out;
        }
+       ret = CDR_get_align(codec, 8);
+       if (!ret) {
+               ul_logerr("Malformed request recevied\n");
+               env.major = FORB_EX_COMM_FAILURE;
+               goto out;
+       }
+
        header_size = data_size - CDR_data_size(codec);
        req_size = message_size - header_size;