This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #134035) ensure sv_gets() handles a signal handler modifying sv
authorTony Cook <tony@develop-help.com>
Wed, 17 Apr 2019 05:45:15 +0000 (15:45 +1000)
committerTony Cook <tony@develop-help.com>
Thu, 13 Jun 2019 05:43:25 +0000 (15:43 +1000)
At a very basic level at least.

In the ticket cases, a signal handler is modifying (and reallocating
PVX) the sv, while sv_gets() retained a pointer to the inside of the
SV.

This still has some problems, like if the signal handler ends up
shortening SV, there may be old data left between the old position
and the new position, but I think that's a case of user error.

sv.c

diff --git a/sv.c b/sv.c
index 8bc0af0..83de536 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -8755,7 +8755,10 @@ Perl_sv_gets(pTHX_ SV *const sv, PerlIO *const fp, I32 append)
 
             Note we have to deal with the char in 'i' if we are not at EOF
         */
+        bpx = bp - (STDCHAR*)SvPVX_const(sv);
+        /* signals might be called here, possibly modifying sv */
        i   = PerlIO_getc(fp);          /* get more characters */
+        bp = (STDCHAR*)SvPVX_const(sv) + bpx;
 
        DEBUG_Pv(PerlIO_printf(Perl_debug_log,
           "Screamer: post: FILE * thinks ptr=%" UVuf ", cnt=%" IVdf ", base=%" UVuf "\n",