This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
doio.c: Change strchr to memchr
authorKarl Williamson <khw@cpan.org>
Sat, 25 Mar 2017 20:51:19 +0000 (14:51 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 6 Nov 2017 21:31:45 +0000 (14:31 -0700)
This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

doio.c

diff --git a/doio.c b/doio.c
index 02a5164..9aba9dc 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -261,7 +261,7 @@ Perl_do_open6(pTHX_ GV *gv, const char *oname, STRLEN len,
             STRLEN nlen = 0;
            /* New style explicit name, type is just mode and layer info */
 #ifdef USE_STDIO
-           if (SvROK(*svp) && !strchr(oname,'&')) {
+           if (SvROK(*svp) && !memchr(oname, '&', len)) {
                if (ckWARN(WARN_IO))
                    Perl_warner(aTHX_ packWARN(WARN_IO),
                            "Can't open a reference");
@@ -1630,7 +1630,7 @@ Perl_mode_from_discipline(pTHX_ const char *s, STRLEN len)
            else {
                const char *end;
   fail_discipline:
-               end = strchr(s+1, ':');
+               end = (char *) memchr(s+1, ':', len);
                if (!end)
                    end = s+len;
 #ifndef PERLIO_LAYERS