From: Gurusamy Sarathy Date: Sun, 17 Jan 1999 12:00:23 +0000 (+0000) Subject: sanity check piped opens (tweaked version of patch suggested X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=06eaf0bc49fea082c8b8358680815d807a7a925e;p=p5sagit%2Fp5-mst-13.2.git sanity check piped opens (tweaked version of patch suggested by Mark-Jason Dominus) p4raw-id: //depot/perl@2629 --- diff --git a/doio.c b/doio.c index 641046b..48e6c62 100644 --- a/doio.c +++ b/doio.c @@ -188,6 +188,13 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe if (*name == '|') { /*SUPPRESS 530*/ for (name++; isSPACE(*name); name++) ; + if (*name == '\0') { /* command is missing 19990114 */ + dTHR; + if (ckWARN(WARN_PIPE)) + warner(WARN_PIPE, "Missing command in piped open"); + errno = EPIPE; + goto say_false; + } if (strNE(name,"-")) TAINT_ENV(); TAINT_PROPER("piped open"); @@ -285,6 +292,13 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe name[--len] = '\0'; /*SUPPRESS 530*/ for (; isSPACE(*name); name++) ; + if (*name == '\0') { /* command is missing 19990114 */ + dTHR; + if (ckWARN(WARN_PIPE)) + warner(WARN_PIPE, "Missing command in piped open"); + errno = EPIPE; + goto say_false; + } if (strNE(name,"-")) TAINT_ENV(); TAINT_PROPER("piped open"); diff --git a/pod/perldelta.pod b/pod/perldelta.pod index bd2b715..afe29e6 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -140,6 +140,11 @@ C<'>-delimited regular expression. (W) You used a backslash-character combination which is not recognized by Perl. +=item Missing command in piped open + +(W) You used the C or C +construction, but the command was missing or blank. + =head1 Obsolete Diagnostics Todo. diff --git a/pod/perldiag.pod b/pod/perldiag.pod index e0e9b12..211262c 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1546,6 +1546,11 @@ one line to the next. (F) While certain functions allow you to specify a filehandle or an "indirect object" before the argument list, this ain't one of them. +=item Missing command in piped open + +(W) You used the C or C +construction, but the command was missing or blank. + =item Missing operator before %s? (S) This is an educated guess made in conjunction with the message "%s diff --git a/t/io/pipe.t b/t/io/pipe.t index 08b312a..13db20b 100755 --- a/t/io/pipe.t +++ b/t/io/pipe.t @@ -13,7 +13,7 @@ BEGIN { } $| = 1; -print "1..12\n"; +print "1..14\n"; # External program 'tr' assumed. open(PIPE, "|-") || (exec 'tr', 'YX', 'ko'); @@ -151,3 +151,10 @@ if ($? == 37*256 && $wait == $zombie && ! $!) { } else { print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$? \$!=", $!+0, ":$!\n"; } + +# Test new semantics for missing command in piped open +# 19990114 M-J. Dominus mjd@plover.com +{ local *P; + print (((open P, "| " ) ? "not " : ""), "ok 13\n"); + print (((open P, " |" ) ? "not " : ""), "ok 14\n"); +} diff --git a/t/op/taint.t b/t/op/taint.t index 379093f..e77d5d1 100755 --- a/t/op/taint.t +++ b/t/op/taint.t @@ -383,10 +383,10 @@ else { for (76..79) { print "ok $_ # Skipped: open('|') is not available\n" } } else { - test 76, eval { open FOO, "| $foo" } eq '', 'popen to'; + test 76, eval { open FOO, "| x$foo" } eq '', 'popen to'; test 77, $@ =~ /^Insecure dependency/, $@; - test 78, eval { open FOO, "$foo |" } eq '', 'popen from'; + test 78, eval { open FOO, "x$foo |" } eq '', 'popen from'; test 79, $@ =~ /^Insecure dependency/, $@; } diff --git a/t/pragma/warn/doio b/t/pragma/warn/doio index 5e15c8c..41ac89a 100644 --- a/t/pragma/warn/doio +++ b/t/pragma/warn/doio @@ -3,6 +3,12 @@ Can't do bidirectional pipe open(F, "| true |"); + Missing command in piped open + open(F, "| "); + + Missing command in piped open + open(F, " |"); + warn(warn_nl, "open"); open(F, "true\ncd") @@ -44,6 +50,18 @@ Can't do bidirectional pipe at - line 3. ######## # doio.c use warning 'io' ; +open(F, "| ") +EXPECT +Missing command in piped open at - line 3. +######## +# doio.c +use warning 'io' ; +open(F, " |") +EXPECT +Missing command in piped open at - line 3. +######## +# doio.c +use warning 'io' ; open(F, "