summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/socket.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index b161f038f66..098fd3a8c50 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -4328,6 +4328,11 @@ sock_s_unpack_sockaddr_in(VALUE self, VALUE addr)
VALUE host;
sockaddr = (struct sockaddr_in*)SockAddrStringValuePtr(addr);
+ if (RSTRING_LEN(addr) <
+ (char*)&((struct sockaddr *)sockaddr)->sa_family +
+ sizeof(((struct sockaddr *)sockaddr)->sa_family) -
+ (char*)sockaddr)
+ rb_raise(rb_eArgError, "too short sockaddr");
if (((struct sockaddr *)sockaddr)->sa_family != AF_INET
#ifdef INET6
&& ((struct sockaddr *)sockaddr)->sa_family != AF_INET6
@@ -4397,6 +4402,11 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
VALUE path;
sockaddr = (struct sockaddr_un*)SockAddrStringValuePtr(addr);
+ if (RSTRING_LEN(addr) <
+ (char*)&((struct sockaddr *)sockaddr)->sa_family +
+ sizeof(((struct sockaddr *)sockaddr)->sa_family) -
+ (char*)sockaddr)
+ rb_raise(rb_eArgError, "too short sockaddr");
if (((struct sockaddr *)sockaddr)->sa_family != AF_UNIX) {
rb_raise(rb_eArgError, "not an AF_UNIX sockaddr");
}