From: Nick Ing-Simmons Date: Tue, 9 Jul 2002 09:38:45 +0000 (+0000) Subject: Core-dump prevention for X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=439ba5457a8422144686c1df300aa1dde218dbfd;p=p5sagit%2Fp5-mst-13.2.git Core-dump prevention for open PIPE, "-|:stdio", "cat /etc/motd"; (root cause not yet fixed). p4raw-id: //depot/perlio@17432 --- diff --git a/perlio.c b/perlio.c index 7c06b5a..b4b23d4 100644 --- a/perlio.c +++ b/perlio.c @@ -2433,7 +2433,12 @@ typedef struct { IV PerlIOStdio_fileno(pTHX_ PerlIO *f) { - return PerlSIO_fileno(PerlIOSelf(f, PerlIOStdio)->stdio); + FILE *s; + if (PerlIOValid(f) && (s = PerlIOSelf(f, PerlIOStdio)->stdio)) { + return PerlSIO_fileno(s); + } + errno = EBADF; + return -1; } char * @@ -2631,6 +2636,10 @@ PerlIOStdio_close(pTHX_ PerlIO *f) Sock_size_t optlen = sizeof(int); #endif FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + if (!stdio) { + errno = EBADF; + return -1; + } if (PerlIOUnix_refcnt_dec(fileno(stdio)) > 0) { /* Do not close it but do flush any buffers */ return PerlIO_flush(f); @@ -4619,3 +4628,4 @@ PerlIO_sprintf(char *s, int n, const char *fmt, ...) +