vmsplice: avoid referencing invalid stack address for strings
authorEric Wong <normalperson@yhbt.net>
Sat, 19 Jan 2013 03:08:06 +0000 (19 03:08 +0000)
committerEric Wong <normalperson@yhbt.net>
Sat, 19 Jan 2013 03:15:39 +0000 (19 03:15 +0000)
Newer GCC more aggressively optimizes stack allocations away,
so we need to avoid passing out-of-scope addresses to vmsplice.
Not that vmsplice is useful in Ruby...

ext/io_splice/io_splice_ext.c

index 32de838..876d07d 100644 (file)
@@ -492,19 +492,18 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
        ssize_t rv = 0;
        ssize_t left;
        struct vmsplice_args a;
+       struct iovec iov;
+
        VALUE io, data, flags;
 
        rb_scan_args(argc, argv, "21", &io, &data, &flags);
 
        switch (TYPE(data)) {
-       case T_STRING: {
-               struct iovec iov;
-
+       case T_STRING:
                iov.iov_base = RSTRING_PTR(data);
                iov.iov_len = (size_t)(left = (ssize_t)RSTRING_LEN(data));
                a.iov = &iov;
                a.nr_segs = 1;
-               }
                break;
        case T_ARRAY:
                ARY2IOVEC(a.iov, a.nr_segs, left, data);