This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Module-Build wasn't listed as DEPRECATED
[perl5.git] / perlio.c
index 097bc49..963c3e8 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -310,6 +310,9 @@ PerlIO_openn(pTHX_ const char *layers, const char *mode, int fd,
            return PerlIO_tmpfile();
        else {
            const char *name = SvPV_nolen_const(*args);
+            if (!IS_SAFE_PATHNAME(*args, "open"))
+                return NULL;
+
            if (*mode == IoTYPE_NUMERIC) {
                fd = PerlLIO_open3(name, imode, perm);
                if (fd >= 0)
@@ -811,7 +814,8 @@ PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load)
        len = strlen(name);
     for (i = 0; i < PL_known_layers->cur; i++) {
        PerlIO_funcs * const f = PL_known_layers->array[i].funcs;
-       if (memEQ(f->name, name, len) && f->name[len] == 0) {
+        const STRLEN this_len = strlen(f->name);
+        if (this_len == len && memEQ(f->name, name, len)) {
            PerlIO_debug("%.*s => %p\n", (int) len, name, (void*)f);
            return f;
        }
@@ -2610,10 +2614,15 @@ PerlIOUnix_oflags(const char *mode)
        oflags &= ~O_BINARY;
        mode++;
     }
-    /*
-     * Always open in binary mode
-     */
-    oflags |= O_BINARY;
+    else {
+#ifdef PERLIO_USING_CRLF
+       /*
+        * If neither "t" nor "b" was specified, open the file
+        * in O_BINARY mode.
+        */
+       oflags |= O_BINARY;
+#endif
+    }
     if (*mode || oflags == -1) {
        SETERRNO(EINVAL, LIB_INVARG);
        oflags = -1;
@@ -2713,6 +2722,8 @@ PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
        }
        if (imode != -1) {
            const char *path = SvPV_nolen_const(*args);
+           if (!IS_SAFE_PATHNAME(*args, "open"))
+                return NULL;
            fd = PerlLIO_open3(path, imode, perm);
        }
     }
@@ -3027,6 +3038,8 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
        const char * const path = SvPV_nolen_const(*args);
        PerlIOStdio * const s = PerlIOSelf(f, PerlIOStdio);
        FILE *stdio;
+       if (!IS_SAFE_PATHNAME(*args, "open"))
+            return NULL;
        PerlIOUnix_refcnt_dec(fileno(s->stdio));
        stdio = PerlSIO_freopen(path, (mode = PerlIOStdio_mode(mode, tmode)),
                            s->stdio);
@@ -3039,6 +3052,8 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
     else {
        if (narg > 0) {
            const char * const path = SvPV_nolen_const(*args);
+            if (!IS_SAFE_PATHNAME(*args, "open"))
+                return NULL;
            if (*mode == IoTYPE_NUMERIC) {
                mode++;
                fd = PerlLIO_open3(path, imode, perm);