Bug 2845

Summary: Perl cgi-bin bug
Product: [Retired] Red Hat Linux Reporter: aftab
Component: perlAssignee: Crutcher Dunnavant <crutcher>
Status: CLOSED WORKSFORME QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 5.2CC: aftab
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 1999-08-30 02:33:54 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description aftab 1999-05-15 21:15:04 UTC
I have recently installed Redhat Linux, and when I copied
my web page from my PC to linux, it did not execute the
scripts properly. I have also updated my perl version with
the latest update on you web site (14/05/99)and still had
the same problem. After some debugging I have found what
the problem is: I pass a reference to an associate array to
a subroutine. This subroutine then fills in this array. But
the items this subroutine enters into the array are not
visable outside this array as they should be as I passed
the array by reference. These scripts have been working on
my PC and on ISP unix machine. The contenets of the script
are below.

#!/usr/bin/perl

&parse_input(*login_form);

#the login_form is empty it does not get filled as it should

$userid = $login_form{'userid'};
$pass = $login_form{'pass'};

#the subroutine
sub parse_input {
	if (defined(@_)) {
		local(*input)=@_;
	}
	else {
		local(*input)="*cgiinput";
	}
	local ($temp,@pairs);
	if (&form_method eq 'POST') {
		read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
	}
	else {
		$temp=$ENV{'QUERY_STRING'};
	}
	if ($temp ne '') {
		@pairs=split(/&/,$temp);
		foreach $item(@pairs) {
			($key,$content)=split (/=/,$item,2);
			$content=~tr/+/ /;
			$content=~ s/%(..)/pack("c",hex
($1))/ge;
			if (!defined($input{$key})) {
				$input{$key}=$content;
			}
			else {
				$input{$key} .= "\0
$content";
			}
		}
		return 1;
	}
	else {
		return 0;
	}
}

Comment 1 Cristian Gafton 1999-08-30 02:33:59 UTC
You can change the perl fucntion to return the actual array instead
of 	playing the by-refreence game, whcih is totally evil. At a first
fast glance I got scaried by things like
	$input{$key} .= "\0$content";
I'd suggest you rather use the CGI module if you want to parse this
kind of free form variables.