Error check VMS's backticks stdin inheritance.
authorCraig A. Berry <craigberry@mac.com>
Sun, 8 Dec 2013 14:06:58 +0000 (08:06 -0600)
committerCraig A. Berry <craigberry@mac.com>
Sun, 8 Dec 2013 14:06:58 +0000 (08:06 -0600)
This is a follow-up to e2d6c6fbf5bb.  The use case I've seen is
that the translation of SYS$INPUT succeeds but the stat on the
resulting file/device fails, possibly due to object protections.
So we would be giving the child something it can't open.

Add error checking to the logic so in order to set up inheritance
of SYS$INPUT:

 1.) The translation of SYS$INPUT must succeed.
 2.) stat() on the resulting spec must succeed.
 3.) The resulting spec must not be a directory.

vms/vms.c

index cb20e3b..d1cb948 100644 (file)
--- a/vms/vms.c
+++ b/vms/vms.c
@@ -4338,9 +4338,10 @@ safe_popen(pTHX_ const char *cmd, const char *in_mode, int *psts)
     } else if (*mode == 'n') {       /* separate subprocess, no Perl i/o */
         /* Let the child inherit standard input, unless it's a directory. */
         Stat_t st;
-        (void)my_trnlnm("SYS$INPUT", in, 0);
-        if (!flex_stat(in, &st) && S_ISDIR(st.st_mode))
-            *in = '\0';
+        if (my_trnlnm("SYS$INPUT", in, 0)) {
+            if (flex_stat(in, &st) != 0 || S_ISDIR(st.st_mode))
+                *in = '\0';
+        }
 
         info->out = pipe_mbxtofd_setup(aTHX_ fileno(stdout), out);
         if (info->out) {