summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2017-06-25 06:37:19 -0700
committerFather Chrysostomos <sprout@cpan.org>2017-07-02 12:34:47 -0700
commite26c6904d9f9f5ea818e590331b14038279332d1 (patch)
tree5e824a520ebe328f8f63611e204ef655ca63125f /pp_sys.c
parent7600a9e5585cdade08986d507c3de5ea3b678bc3 (diff)
downloadperl-e26c6904d9f9f5ea818e590331b14038279332d1.tar.gz
[perl #131645] Fix assert fail in pp_sselect
pp_sselect (4-arg select) process its first three bitfield arguments first, making sure each one has a valid PV, and then it moves on to the final, timeout argument. SvGETMAGIC() on the timeout argument will wipe out any values the SV holds, so if the same scalar is used as a bitfield argument *and* as the timeout, it will no longer hold a valid PV. Assertions later in pp_sselect make sure there is a valid PV. This commit solves the assertion failure by making a temporary copy of any gmagical or overloaded argument. When the temporary copy is made, the values written to the temporary copies of the bitfield arguments are then copied back to the original magical arguments.
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 65900faf5a..100762c1b7 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1149,6 +1149,7 @@ PP(pp_sselect)
struct timeval *tbuf = &timebuf;
I32 growsize;
char *fd_sets[4];
+ SV *svs[4];
#if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
I32 masksize;
I32 offset;
@@ -1164,7 +1165,7 @@ PP(pp_sselect)
SP -= 4;
for (i = 1; i <= 3; i++) {
- SV * const sv = SP[i];
+ SV * const sv = svs[i] = SP[i];
SvGETMAGIC(sv);
if (!SvOK(sv))
continue;
@@ -1177,9 +1178,14 @@ PP(pp_sselect)
if (!SvPOKp(sv))
Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
"Non-string passed as bitmask");
- SvPV_force_nomg_nolen(sv); /* force string conversion */
+ if (SvGAMAGIC(sv)) {
+ svs[i] = sv_newmortal();
+ sv_copypv_nomg(svs[i], sv);
+ }
+ else
+ SvPV_force_nomg_nolen(sv); /* force string conversion */
}
- j = SvCUR(sv);
+ j = SvCUR(svs[i]);
if (maxlen < j)
maxlen = j;
}
@@ -1228,7 +1234,7 @@ PP(pp_sselect)
tbuf = NULL;
for (i = 1; i <= 3; i++) {
- sv = SP[i];
+ sv = svs[i];
if (!SvOK(sv) || SvCUR(sv) == 0) {
fd_sets[i] = 0;
continue;
@@ -1275,7 +1281,7 @@ PP(pp_sselect)
#endif
for (i = 1; i <= 3; i++) {
if (fd_sets[i]) {
- sv = SP[i];
+ sv = svs[i];
#if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
s = SvPVX(sv);
for (offset = 0; offset < growsize; offset += masksize) {
@@ -1284,7 +1290,10 @@ PP(pp_sselect)
}
Safefree(fd_sets[i]);
#endif
- SvSETMAGIC(sv);
+ if (sv != SP[i])
+ SvSetMagicSV(SP[i], sv);
+ else
+ SvSETMAGIC(sv);
}
}