Fix sv_vcatpvfn %s with precision on non-NUL-terminated strings
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Sun, 15 Oct 2017 07:33:22 +0000 (09:33 +0200)
committerDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Sat, 21 Oct 2017 19:08:39 +0000 (20:08 +0100)
The precision parameter to %s can be used to print non-NUL-terminated
strings, so use my_strnlen() to limit the length checking to the
specified length.

sv.c

diff --git a/sv.c b/sv.c
index 070a0c1..ac1fb4d 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12376,7 +12376,10 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
            if (args) {
                eptr = va_arg(*args, char*);
                if (eptr)
-                   elen = strlen(eptr);
+                    if (has_precis)
+                        elen = my_strnlen(eptr, precis);
+                    else
+                        elen = strlen(eptr);
                else {
                    eptr = (char *)nullstr;
                    elen = sizeof nullstr - 1;