This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
*ctl: test we handle the buffer as bytes
authorTony Cook <tony@develop-help.com>
Tue, 17 Nov 2020 03:20:41 +0000 (14:20 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 24 Nov 2020 02:35:21 +0000 (13:35 +1100)
Previously this had the "unicode bug", an upgraded string would
be treated as the encoding of that string, rather than the raw
bytes.

doio.c
t/io/sem.t

diff --git a/doio.c b/doio.c
index 11c9ed1..29a431d 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -2999,13 +2999,13 @@ Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp)
     {
        if (getinfo)
        {
-           SvPV_force_nolen(astr);
+            SvPV_force_nolen(astr);
            a = SvGROW(astr, infosize+1);
        }
        else
        {
            STRLEN len;
-           a = SvPV(astr, len);
+           a = SvPVbyte(astr, len);
            if (len != infosize)
                Perl_croak(aTHX_ "Bad arg length for %s, is %lu, should be %ld",
                      PL_op_desc[optype],
index 8d2c7bb..ff3df5f 100644 (file)
@@ -76,5 +76,16 @@ else {
     @semvals = unpack("s!*", $semvals);
     is($semvals[$sem2set], $semval,
        "Checking value of semaphore $sem2set after fetch into originally UTF-8 buffer");
+
+    # second that we treat it as bytes on input
+    @semvals = ( 0 ) x $nsem;
+    $semvals[$sem2set] = $semval + 1;
+    $semvals = pack "s!*", @semvals;
+    utf8::upgrade($semvals);
+    # eval{} since it would crash due to the UTF-8 form being longer
+    ok(eval { semctl($id, "ignored", SETALL, $semvals) },
+       "set all semaphores from an upgraded string");
+    is(semctl($id, $sem2set, GETVAL, $ignored), $semval+1,
+       "test value set from UTF-8");
 }