Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 89747
Status: resolved
Priority: 0/
Queue: CGI

People
Owner: Nobody in particular
Requestors: cpan [...] c-dot.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Subprocess created using safe pipes wipes out temp files
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <rt-4.0.16-19499-1382622393-300.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1690
Download (untitled) / with headers
text/plain 1.6k
perl 5.14.2, CGI 3.52 If a short-lived subprocess is created using safe pipes after a CGI instance has already been created, the cleanup of the subprocess will demolish the tempfiles used by the parent. Here's a short script (arghno.pl) that demonstrates the problem: #!/usr/bin/perl use strict; use CGI; use CGI::Carp ('fatalsToBrowser'); my $q = new CGI; print CGI::header(); my $fn = $q->param('filepath'); my $f = $q->tmpFileName($fn); my $handle; my $pid = open($handle, "-|"); if ($pid) { print "This is the parent"; die "Parent: Tmpfile has gone before reading!" unless -e $f; my $data = <$handle>; die "Parent: Tmpfile has gone after reading!" unless -e $f; } else { # This is the child print "This is the child"; } Invoke with the following HTML: <html> <body> <form enctype="multipart/form-data" action="arghno.pl" method="post"> <input type="file" name="filepath" value="" /> <input type="submit" value='Upload file' /> </form> </body> </html> The temp files are removed in the CGITempFile::DESTROY method, when it is invoked during subprocess cleanup. Curiously enough the problem is not seen when using fork() to create the subprocess. I was able to work around this problem by monkey-patching CGITempFile::DESTROY so that it was only invoked when called from the parent process, thus: our $CONSTRUCTOR_PID = $$; our $SAVE_DESTROY = \&CGITempFile::DESTROY; if ( defined $SAVE_DESTROY ) { no warnings 'redefine'; *CGITempFile::DESTROY = sub { if ( $$ == $CONSTRUCTOR_PID ) { # Parent process, unlink the temp file &$SAVE_DESTROY(@_); } }; } my $query - new CGI(); etc.
X-RT-Interface: REST
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
RT-Message-ID: <rt-4.0.18-6007-1400761202-1189.89747-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 241
Download (untitled) / with headers
text/plain 241b
This issue has been copied to: https://github.com/leejo/CGI.pm/issues/125 please take all future correspondence there. This ticket will remain open but please do not reply here. This ticket will be closed when the github issue is dealt with.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.16-19499-1382622393-300.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.16-19499-1382622393-300.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-22233-1411934093-986.89747-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1491
Download (untitled) / with headers
text/plain 1.4k
commit 1aa4cb0262103d7d0f657099bb54a557ce1b237b Author: Lee Johnson <lee@givengain.ch> Date: Sun Sep 28 20:46:46 2014 +0100 resolve #125, #131 - refactor temp file handling the CGITempFile and Fh packages are gone and have been replaced by CGI::File::Temp, which is a compatibility wrapper around the File::Temp package. File::Temp behaves as a filehandle, and isa IO::Handle and isa IO::Seekable so behaves as we want it to bump version to 4.04_02 for cpantesters dev release testing Squashed commit of the following: commit 3af477dacef09d7d01086a6fb3984471e6892c9e Author: Lee Johnson <lee@givengain.ch> Date: Sun Sep 28 20:45:32 2014 +0100 temp files done commit 982fc37665a8754d09e7f5952bc04a736ebcfc26 Author: Lee Johnson <lee@givengain.ch> Date: Thu Sep 25 10:55:33 2014 +0100 WIP - refactor CGITempFile and Fh to File::Temp Changes | 8 ++-- MANIFEST | 1 - Makefile.PL | 19 ++++----- lib/CGI.pm | 328 ++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------- lib/CGI/Carp.pm | 2 +- lib/CGI/Cookie.pm | 2 +- lib/CGI/Pretty.pm | 2 +- lib/CGI/Push.pm | 2 +- lib/CGI/Util.pm | 2 +- t/rt-31107.t | 12 +++++- t/tmpdir.t | 51 ------------------------ t/upload.t | 2 +- 12 files changed, 103 insertions(+), 328 deletions(-)
MIME-Version: 1.0
In-Reply-To: <rt-4.0.16-19499-1382622393-300.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.16-19499-1382622393-300.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-22233-1411934102-776.89747-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1491
Download (untitled) / with headers
text/plain 1.4k
commit 1aa4cb0262103d7d0f657099bb54a557ce1b237b Author: Lee Johnson <lee@givengain.ch> Date: Sun Sep 28 20:46:46 2014 +0100 resolve #125, #131 - refactor temp file handling the CGITempFile and Fh packages are gone and have been replaced by CGI::File::Temp, which is a compatibility wrapper around the File::Temp package. File::Temp behaves as a filehandle, and isa IO::Handle and isa IO::Seekable so behaves as we want it to bump version to 4.04_02 for cpantesters dev release testing Squashed commit of the following: commit 3af477dacef09d7d01086a6fb3984471e6892c9e Author: Lee Johnson <lee@givengain.ch> Date: Sun Sep 28 20:45:32 2014 +0100 temp files done commit 982fc37665a8754d09e7f5952bc04a736ebcfc26 Author: Lee Johnson <lee@givengain.ch> Date: Thu Sep 25 10:55:33 2014 +0100 WIP - refactor CGITempFile and Fh to File::Temp Changes | 8 ++-- MANIFEST | 1 - Makefile.PL | 19 ++++----- lib/CGI.pm | 328 ++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------- lib/CGI/Carp.pm | 2 +- lib/CGI/Cookie.pm | 2 +- lib/CGI/Pretty.pm | 2 +- lib/CGI/Push.pm | 2 +- lib/CGI/Util.pm | 2 +- t/rt-31107.t | 12 +++++- t/tmpdir.t | 51 ------------------------ t/upload.t | 2 +- 12 files changed, 103 insertions(+), 328 deletions(-)
MIME-Version: 1.0
X-Spam-Status: No, score=-5.292 tagged_above=-99.9 required=10 tests=[AWL=1.308, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FROM_OUR_RT=-4, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham
In-Reply-To: <rt-4.0.18-22233-1411934102-274.89747-5-0 [...] rt.cpan.org>
X-Mailer: MessagingEngine.com Webmail Interface - ajax-cad53418
X-Spam-Flag: NO
X-RT-Interface: API
References: <RT-Ticket-89747 [...] rt.cpan.org> <rt-4.0.16-19499-1382622393-300.89747-5-0 [...] rt.cpan.org> <rt-4.0.18-22233-1411934102-274.89747-5-0 [...] rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
Message-ID: <1411941005.2514672.172715965.0253DEDE [...] webmail.messagingengine.com>
content-type: text/plain; charset="utf-8"
X-Sasl-Enc: KhbOl34xesWEu37BpRZkPfoaX3XxMHwgJhSlgKFoyqG8 1411941005
X-RT-Original-Encoding: utf-8
X-Spam-Score: -5.292
Authentication-Results: hipster.bestpractical.com (amavisd-new); dkim=pass header.i= [...] messagingengine.com
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id D1FC1240516 for <cpan-bug+CGI [...] hipster.bestpractical.com>; Sun, 28 Sep 2014 17:50:20 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id riL8+sfjLxfy for <cpan-bug+CGI [...] hipster.bestpractical.com>; Sun, 28 Sep 2014 17:50:19 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id E36AA2404FB for <bug-CGI [...] rt.cpan.org>; Sun, 28 Sep 2014 17:50:18 -0400 (EDT)
Received: (qmail 6066 invoked by alias); 28 Sep 2014 21:50:17 -0000
Received: from out3-smtp.messagingengine.com (HELO out3-smtp.messagingengine.com) (66.111.4.27) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Sun, 28 Sep 2014 14:50:15 -0700
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by gateway2.nyi.internal (Postfix) with ESMTP id 9DBC520DE0 for <bug-CGI [...] rt.cpan.org>; Sun, 28 Sep 2014 17:50:05 -0400 (EDT)
Received: from web1 ([10.202.2.211]) by compute1.internal (MEProxy); Sun, 28 Sep 2014 17:50:05 -0400
Received: by web1.nyi.internal (Postfix, from userid 99) id 7678FF0012A; Sun, 28 Sep 2014 17:50:05 -0400 (EDT)
Delivered-To: cpan-bug+CGI [...] hipster.bestpractical.com
Subject: Re: [rt.cpan.org #89747] Subprocess created using safe pipes wipes out temp files
Return-Path: <mark [...] stosberg.com>
Dkim-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:x-sasl-enc:from:to :mime-version:content-transfer-encoding:content-type:in-reply-to :references:subject:date; s=smtpout; bh=3XvAemeOY1Ba73HL53fuzMgz GMM=; b=p8/PUIxK8F4853lsr00DaFYaaNWVah/JC0SzYolpg1Aa4by3LVPmOyHo 6M8RfnsyYem910HSMGu2JnaBOc7fDhdltgQtyQWmmfxoiechUEKreDFqSeHLwpig IpIuO98cD4Lm+CIpFVWyOsC1dv/VjLWNsHJHLjec2yhCiDg9kQI=
X-Spam-Check-BY: la.mx.develooper.com
X-Original-To: cpan-bug+CGI [...] hipster.bestpractical.com
X-RT-Mail-Extension: cgi
Date: Sun, 28 Sep 2014 14:50:05 -0700
X-Spam-Level:
To: Lee Johnson via RT <bug-CGI [...] rt.cpan.org>
Content-Transfer-Encoding: 7bit
From: Mark Stosberg <mark [...] stosberg.com>
RT-Message-ID: <rt-4.0.18-26226-1411941021-1714.89747-0-0 [...] rt.cpan.org>
Content-Length: 1866
Download (untitled) / with headers
text/plain 1.8k
I recommend keeping Fh as an empty subclass of the new package. I have seen code that explicitly checks for the Fh class. Mark On Sun, Sep 28, 2014, at 12:55 PM, Lee Johnson via RT wrote: Show quoted text
> Queue: CGI > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=89747 > > > commit 1aa4cb0262103d7d0f657099bb54a557ce1b237b > Author: Lee Johnson <lee@givengain.ch> > Date: Sun Sep 28 20:46:46 2014 +0100 > > resolve #125, #131 - refactor temp file handling > > the CGITempFile and Fh packages are gone and have been replaced by > CGI::File::Temp, which is a compatibility wrapper around the > File::Temp > package. File::Temp behaves as a filehandle, and isa IO::Handle and > isa IO::Seekable so behaves as we want it to > > bump version to 4.04_02 for cpantesters dev release testing > > Squashed commit of the following: > > commit 3af477dacef09d7d01086a6fb3984471e6892c9e > Author: Lee Johnson <lee@givengain.ch> > Date: Sun Sep 28 20:45:32 2014 +0100 > > temp files done > > commit 982fc37665a8754d09e7f5952bc04a736ebcfc26 > Author: Lee Johnson <lee@givengain.ch> > Date: Thu Sep 25 10:55:33 2014 +0100 > > WIP - refactor CGITempFile and Fh to File::Temp > > Changes | 8 ++-- > MANIFEST | 1 - > Makefile.PL | 19 ++++----- > lib/CGI.pm | 328 > ++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------- > lib/CGI/Carp.pm | 2 +- > lib/CGI/Cookie.pm | 2 +- > lib/CGI/Pretty.pm | 2 +- > lib/CGI/Push.pm | 2 +- > lib/CGI/Util.pm | 2 +- > t/rt-31107.t | 12 +++++- > t/tmpdir.t | 51 ------------------------ > t/upload.t | 2 +- > 12 files changed, 103 insertions(+), 328 deletions(-)
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-26226-1411941021-1714.89747-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <RT-Ticket-89747 [...] rt.cpan.org> <rt-4.0.16-19499-1382622393-300.89747-5-0 [...] rt.cpan.org> <rt-4.0.18-22233-1411934102-274.89747-5-0 [...] rt.cpan.org> <1411941005.2514672.172715965.0253DEDE [...] webmail.messagingengine.com> <rt-4.0.18-26226-1411941021-1714.89747-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-23167-1411982579-990.89747-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 212
Download (untitled) / with headers
text/plain 212b
On Sun Sep 28 17:50:21 2014, mark@stosberg.com wrote: Show quoted text
> I recommend keeping Fh as an empty subclass of the new package. I have > seen code that explicitly checks for the Fh class. > > Mark
Thanks Mark, will do.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.