This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT 75082: recv() with MSG_TRUNC flag SEGV
authorDavid Mitchell <davem@iabyn.com>
Sun, 31 Oct 2010 12:44:39 +0000 (12:44 +0000)
committerDavid Mitchell <davem@iabyn.com>
Sun, 31 Oct 2010 13:04:03 +0000 (13:04 +0000)
The recv() system call, with the MSG_TRUNC flag, returns the
true size of the packet, even if it is larger than the supplied buffer.
Since perl's equivalent recv() function doesn't return the size
(apart from what's implied as the returned length of the buffer), there
doesn't seem to to be any way to return this value to the caller. So
silently ignore it.

Before, we were setting SvCUR to the size, even if it was larger than
the buffer. Which was Bad.

pp_sys.c

index 2497ec2..c3d0505 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1655,6 +1655,9 @@ PP(pp_sysread)
                                  (struct sockaddr *)namebuf, &bufsize);
        if (count < 0)
            RETPUSHUNDEF;
+       /* MSG_TRUNC can give oversized count; quietly lose it */
+       if (count > length)
+           count = length;
 #ifdef EPOC
         /* Bogus return without padding */
        bufsize = sizeof (struct sockaddr_in);