This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
msgrcv: properly downgrade the receive buffer
authorTony Cook <tony@develop-help.com>
Wed, 18 Nov 2020 03:26:38 +0000 (14:26 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 24 Nov 2020 02:35:21 +0000 (13:35 +1100)
If the receive buffer started with SVf_UTF8 on, the received message
SV would stay flagged, corrupting the result.

doio.c
t/io/msg.t

diff --git a/doio.c b/doio.c
index aa6c35b..df6e62c 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -3141,6 +3141,7 @@ Perl_do_msgrcv(pTHX_ SV **mark, SV **sp)
     }
     if (ret >= 0) {
        SvCUR_set(mstr, sizeof(long)+ret);
+        SvPOK_only(mstr);
        *SvEND(mstr) = '\0';
        /* who knows who has been playing with this message? */
        SvTAINTED_on(mstr);
index c31a20b..2c3f75b 100644 (file)
@@ -64,6 +64,13 @@ else {
         ok(msgrcv($id, $rcvbuf, 1024, 0, IPC_NOWAIT), "receive it");
         is($rcvbuf, $msg, "received should match sent");
     }
+
+    # try a receive buffer that starts upgraded
+    if (ok(msgsnd($id, $msg, IPC_NOWAIT), "send a message (upgraded receiver)")) {
+        my $rcvbuf = "\x{101}";
+        ok(msgrcv($id, $rcvbuf, 1024, 0, IPC_NOWAIT), "receive it (upgraded receiver)");
+        is($rcvbuf, $msg, "received should match sent (upgraded receiver)");
+    }
 }
 
 done_testing();