1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-02-18 12:35:22 +00:00
parent d89e09b308
commit 34152d654a
2 changed files with 18 additions and 11 deletions

View file

@ -1,4 +1,8 @@
Wed Feb 18 12:09:43 2009 Tanaka Akira <akr@fsij.org> Wed Feb 18 21:34:30 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/ancdata.c (bsock_sendmsg_internal): avoid misalignment.
Wed Feb 18 21:09:43 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/ancdata.c (bsock_recvmsg_internal): reduce code on * ext/socket/ancdata.c (bsock_recvmsg_internal): reduce code on
environments which have no control message. environments which have no control message.

View file

@ -899,7 +899,8 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
int level, type; int level, type;
VALUE cdata; VALUE cdata;
long oldlen; long oldlen;
struct cmsghdr *cmh; struct cmsghdr cmh;
char *cmsg;
size_t cspace; size_t cspace;
v = rb_check_convert_type(elt, T_ARRAY, "Array", "to_ary"); v = rb_check_convert_type(elt, T_ARRAY, "Array", "to_ary");
if (!NIL_P(v)) { if (!NIL_P(v)) {
@ -921,15 +922,17 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
oldlen = RSTRING_LEN(controls_str); oldlen = RSTRING_LEN(controls_str);
cspace = CMSG_SPACE(RSTRING_LEN(cdata)); cspace = CMSG_SPACE(RSTRING_LEN(cdata));
rb_str_resize(controls_str, oldlen + cspace); rb_str_resize(controls_str, oldlen + cspace);
cmh = (struct cmsghdr *)(RSTRING_PTR(controls_str)+oldlen); cmsg = RSTRING_PTR(controls_str)+oldlen;
memset((char *)cmh, 0, cspace); memset((char *)cmsg, 0, cspace);
cmh->cmsg_level = level; memset((char *)&cmh, 0, sizeof(cmh));
cmh->cmsg_type = type; cmh.cmsg_level = level;
cmh->cmsg_len = CMSG_LEN(RSTRING_LEN(cdata)); cmh.cmsg_type = type;
MEMCPY(CMSG_DATA(cmh), RSTRING_PTR(cdata), char, RSTRING_LEN(cdata)); cmh.cmsg_len = CMSG_LEN(RSTRING_LEN(cdata));
last_level = cmh->cmsg_level; MEMCPY(cmsg, &cmh, char, sizeof(cmh));
last_type = cmh->cmsg_type; MEMCPY(cmsg+((char*)CMSG_DATA(&cmh)-(char*)&cmh), RSTRING_PTR(cdata), char, RSTRING_LEN(cdata));
last_pad = cspace - cmh->cmsg_len; last_level = cmh.cmsg_level;
last_type = cmh.cmsg_type;
last_pad = cspace - cmh.cmsg_len;
} }
if (last_pad) { if (last_pad) {
/* /*