summaryrefslogtreecommitdiff
path: root/pp_pack.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-07-01 22:39:47 -0600
committerKarl Williamson <khw@cpan.org>2019-03-08 12:41:03 -0700
commitfd879d933c2a2ee22ac6e2462acc016aa033854d (patch)
tree9d38a5e31c22c1eb84ee2d95d642a7026aa45da6 /pp_pack.c
parent56e36cbf2fdf9d90f61690c1c3fc35af0d65e0cd (diff)
downloadperl-fd879d933c2a2ee22ac6e2462acc016aa033854d.tar.gz
PATCH: [perl #131642] pack returning malformed UTF-8
This patch causes pack to die rather than return malformed UTF-8. This protects the rest of the core from unexpectedly getting malformed inputs.
Diffstat (limited to 'pp_pack.c')
-rw-r--r--pp_pack.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/pp_pack.c b/pp_pack.c
index 5f1a599eb4..726f7438a3 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -3149,6 +3149,21 @@ PP(pp_pack)
packlist(cat, pat, patend, MARK, SP + 1);
+ if (SvUTF8(cat)) {
+ STRLEN result_len;
+ const char * result = SvPV_nomg(cat, result_len);
+ const U8 * error_pos;
+
+ if (! is_utf8_string_loc((U8 *) result, result_len, &error_pos)) {
+ _force_out_malformed_utf8_message(error_pos,
+ (U8 *) result + result_len,
+ 0, /* no flags */
+ 1 /* Die */
+ );
+ NOT_REACHED; /* NOTREACHED */
+ }
+ }
+
SvSETMAGIC(cat);
SP = ORIGMARK;
PUSHs(cat);