Commits

oberpapr  committed 83c486e

gendesc/genhtml/geninfo/genpng/lcov: handle '<' in filenames

Use 3-arg open mode to prevent that a special character (e.g. '<')
found in a user-specified filename interfers with the required open
mode for that file.

  • Participants
  • Parent commits e69c057

Comments (0)

Files changed (5)

 	local *OUTPUT_HANDLE;
 	my $empty_line = "ignore";
 
-	open(INPUT_HANDLE, $input_filename)
+	open(INPUT_HANDLE, "<", $input_filename)
 		or die("ERROR: cannot open $input_filename!\n");
 
 	# Open output file for writing
 	if ($output_filename)
 	{
-		open(OUTPUT_HANDLE, ">$output_filename")
+		open(OUTPUT_HANDLE, ">", $output_filename)
 			or die("ERROR: cannot create $output_filename!\n");
 	}
 	else
 
 	if ($html_gzip)
 	{
-		open($handle, "|gzip -c >$filename")
+		open($handle, "|-", "gzip -c >'$filename'")
 			or die("ERROR: cannot open $filename for writing ".
 			       "(gzip)!\n");
 	}
 	else
 	{
-		open($handle, ">$filename")
+		open($handle, ">", $filename)
 			or die("ERROR: cannot open $filename for writing!\n");
 	}
 }
 				"compressed file $_[0]!\n");
 
 		# Open compressed file
-		open(INFO_HANDLE, "gunzip -c $_[0]|")
+		open(INFO_HANDLE, "-|", "gunzip -c '$_[0]'")
 			or die("ERROR: cannot start gunzip to decompress ".
 			       "file $_[0]!\n");
 	}
 	else
 	{
 		# Open decompressed file
-		open(INFO_HANDLE, $_[0])
+		open(INFO_HANDLE, "<", $_[0])
 			or die("ERROR: cannot read file $_[0]!\n");
 	}
 
 	my $changed_testname;
 	local *TEST_HANDLE;
 
-	open(TEST_HANDLE, "<".$_[0])
+	open(TEST_HANDLE, "<", $_[0])
 		or die("ERROR: cannot open $_[0]!\n");
 
 	while (<TEST_HANDLE>)
 		 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82] if ($sort);
 	foreach (keys(%data))
 	{
-		open(PNG_HANDLE, ">".$_)
+		open(PNG_HANDLE, ">", $_)
 			or die("ERROR: cannot create $_!\n");
 		binmode(PNG_HANDLE);
 		print(PNG_HANDLE map(chr,@{$data{$_}}));
 	local *HTACCESS_HANDLE;
 	my $htaccess_data;
 
-	open(*HTACCESS_HANDLE, ">.htaccess")
+	open(*HTACCESS_HANDLE, ">", ".htaccess")
 		or die("ERROR: cannot open .htaccess for writing!\n");
 
 	$htaccess_data = (<<"END_OF_HTACCESS")
 		return;
 	}
 
-	open(CSS_HANDLE, ">gcov.css")
+	open(CSS_HANDLE, ">", "gcov.css")
 		or die ("ERROR: cannot open gcov.css for writing!\n");
 
 
 		%count_data = %{$_[2]};
 	}
 
-	if (!open(SOURCE_HANDLE, "<".$source_filename)) {
+	if (!open(SOURCE_HANDLE, "<", $source_filename)) {
 		my @lines;
 		my $last_line = 0;
 
 	local *OLD_STDOUT;
 
 	# Save old stdout and stderr handles
-	($mode & 1) && open(OLD_STDOUT, ">>&STDOUT");
-	($mode & 2) && open(OLD_STDERR, ">>&STDERR");
+	($mode & 1) && open(OLD_STDOUT, ">>&", "STDOUT");
+	($mode & 2) && open(OLD_STDERR, ">>&", "STDERR");
 
 	# Redirect to /dev/null
-	($mode & 1) && open(STDOUT, ">/dev/null");
-	($mode & 2) && open(STDERR, ">/dev/null");
+	($mode & 1) && open(STDOUT, ">", "/dev/null");
+	($mode & 2) && open(STDERR, ">", "/dev/null");
 
 	system(@_);
 	$result = $?;
 	($mode & 2) && close(STDERR);
 
 	# Restore old handles
-	($mode & 1) && open(STDOUT, ">>&OLD_STDOUT");
-	($mode & 2) && open(STDERR, ">>&OLD_STDERR");
+	($mode & 1) && open(STDOUT, ">>&", "OLD_STDOUT");
+	($mode & 2) && open(STDERR, ">>&", "OLD_STDERR");
 
 	return $result;
 }
 	my $value;
 	local *HANDLE;
 
-	if (!open(HANDLE, "<$filename"))
+	if (!open(HANDLE, "<", $filename))
 	{
 		warn("WARNING: cannot read configuration file $filename\n");
 		return undef;
 	{
 		local *HANDLE;
 
-		open(HANDLE, "<".$filename)
+		open(HANDLE, "<", $filename)
 			or die("ERROR: cannot open html prolog $filename!\n");
 		while (<HANDLE>)
 		{
 	{
 		local *HANDLE;
 
-		open(HANDLE, "<".$filename)
+		open(HANDLE, "<", $filename)
 			or die("ERROR: cannot open html epilog $filename!\n");
 		while (<HANDLE>)
 		{
 	# Initially create output filename, data is appended
 	# for each data file processed
 	local *DUMMY_HANDLE;
-	open(DUMMY_HANDLE, ">$output_filename")
+	open(DUMMY_HANDLE, ">", $output_filename)
 		or die("ERROR: cannot create $output_filename!\n");
 	close(DUMMY_HANDLE);
 
 		else
 		{
 			# Append to output file
-			open(INFO_HANDLE, ">>$output_filename")
+			open(INFO_HANDLE, ">>", $output_filename)
 				or die("ERROR: cannot write to ".
 				       "$output_filename!\n");
 		}
 	else
 	{
 		# Open .info file for output
-		open(INFO_HANDLE, ">$da_filename.info")
+		open(INFO_HANDLE, ">", "$da_filename.info")
 			or die("ERROR: cannot create $da_filename.info!\n");
 	}
 
 	{
 
 		# Compare file contents
-		open(SOURCE, $filename)
+		open(SOURCE, "<", $filename)
 			or die("ERROR: cannot read $filename!\n");
 
 		$no_match = 0;
 	my $object;
 	local *INPUT;
 
-	if (!open(INPUT, $_[0]))
+	if (!open(INPUT, "<", $_[0]))
 	{
 		if ($ignore_errors[$ERROR_GCOV])
 		{
 	my $last_line = 0;
 	local *INPUT;
 
-	if (!open(INPUT, $filename)) {
+	if (!open(INPUT, "<", $filename)) {
 		if ($ignore_errors[$ERROR_GCOV])
 		{
 			warn("WARNING: cannot read $filename!\n");
 	my $version_string;
 	my $result;
 
-	open(GCOV_PIPE, "$gcov_tool -v |")
+	open(GCOV_PIPE, "-|", "$gcov_tool -v")
 		or die("ERROR: cannot retrieve gcov version!\n");
 	$version_string = <GCOV_PIPE>;
 	close(GCOV_PIPE);
 	local *OLD_STDOUT;
 
 	# Save old stdout and stderr handles
-	($mode & 1) && open(OLD_STDOUT, ">>&STDOUT");
-	($mode & 2) && open(OLD_STDERR, ">>&STDERR");
+	($mode & 1) && open(OLD_STDOUT, ">>&", "STDOUT");
+	($mode & 2) && open(OLD_STDERR, ">>&", "STDERR");
 
 	# Redirect to /dev/null
-	($mode & 1) && open(STDOUT, ">/dev/null");
-	($mode & 2) && open(STDERR, ">/dev/null");
+	($mode & 1) && open(STDOUT, ">", "/dev/null");
+	($mode & 2) && open(STDERR, ">", "/dev/null");
  
 	debug("system(".join(' ', @_).")\n");
 	system(@_);
 	($mode & 2) && close(STDERR);
 
 	# Restore old handles
-	($mode & 1) && open(STDOUT, ">>&OLD_STDOUT");
-	($mode & 2) && open(STDERR, ">>&OLD_STDERR");
+	($mode & 1) && open(STDOUT, ">>&", "OLD_STDOUT");
+	($mode & 2) && open(STDERR, ">>&", "OLD_STDERR");
  
 	return $result;
 }
 	my $value;
 	local *HANDLE;
 
-	if (!open(HANDLE, "<$filename"))
+	if (!open(HANDLE, "<", $filename))
 	{
 		warn("WARNING: cannot read configuration file $filename\n");
 		return undef;
 	my $flag = 0;
 	local *HANDLE;
 
-	if (!open(HANDLE, "<$filename")) {
+	if (!open(HANDLE, "<", $filename)) {
 		warn("WARNING: could not open $filename\n");
 		return undef;
 	}
 		else
 		{
 			# Append to output file
-			open(INFO_HANDLE, ">>$output_filename")
+			open(INFO_HANDLE, ">>", $output_filename)
 				or die("ERROR: cannot write to ".
 				       "$output_filename!\n");
 		}
 	else
 	{
 		# Open .info file for output
-		open(INFO_HANDLE, ">$graph_filename.info")
+		open(INFO_HANDLE, ">", "$graph_filename.info")
 			or die("ERROR: cannot create $graph_filename.info!\n");
 	}
 
 	my $graph;
 	local *HANDLE;
 
-	open(HANDLE, "<$bb_filename") or goto open_error;
+	open(HANDLE, "<", $bb_filename) or goto open_error;
 	binmode(HANDLE);
 	while (!eof(HANDLE)) {
 		$value = read_bb_value(*HANDLE, "data word");
 	my $graph;
 	local *HANDLE;
 
-	open(HANDLE, "<$bbg_filename") or goto open_error;
+	open(HANDLE, "<", $bbg_filename) or goto open_error;
 	binmode(HANDLE);
 	# Read magic
 	$word = read_bbg_value(*HANDLE, "file magic");
 	my $graph;
 	local *HANDLE;
 
-	open(HANDLE, "<$gcno_filename") or goto open_error;
+	open(HANDLE, "<", $gcno_filename) or goto open_error;
 	binmode(HANDLE);
 	# Read magic
 	$word = read_gcno_word(*HANDLE, "file magic");
 	local *HANDLE;
 	my @source;
 
-	open(HANDLE, "<$filename")
+	open(HANDLE, "<", $filename)
 		or die("ERROR: cannot open $filename!\n");
 
 	# Check for .gcov filename extension
 	}
 
 	# Write PNG file
-	open (PNG_HANDLE, ">$filename")
+	open (PNG_HANDLE, ">", $filename)
 		or die("ERROR: cannot write png file $filename!\n");
 	binmode(*PNG_HANDLE);
 	print(PNG_HANDLE $overview->png());
 	} else {
 		die("ERROR: no reset control found in $gcov_dir\n");
 	}
-	open(HANDLE, ">$reset_file") or
+	open(HANDLE, ">", $reset_file) or
 		die("ERROR: cannot write to $reset_file!\n");
 	print(HANDLE "0");
 	close(HANDLE);
 	local $/;
 	local *HANDLE;
 
-	open(HANDLE, "<$from") or die("ERROR: cannot read $from: $!\n");
+	open(HANDLE, "<", $from) or die("ERROR: cannot read $from: $!\n");
 	$content = <HANDLE>;
 	close(HANDLE);
-	open(HANDLE, ">$to") or die("ERROR: cannot write $from: $!\n");
+	open(HANDLE, ">", $to) or die("ERROR: cannot write $from: $!\n");
 	if (defined($content)) {
 		print(HANDLE $content);
 	}
 	local $\;
 	local *HANDLE;
 
-	open(HANDLE, "<$filename") || return undef;
+	open(HANDLE, "<", $filename) || return undef;
 	$content = <HANDLE>;
 	close(HANDLE);
 
 	info("  data directory .......: $dir\n");
 	$file = abs_path($file);
 	chdir($dir);
-	open(HANDLE, "tar xvfz $file 2>/dev/null|")
+	open(HANDLE, "-|", "tar xvfz '$file' 2>/dev/null")
 		or die("ERROR: could not process package $file\n");
 	while (<HANDLE>) {
 		if (/\.da$/ || /\.gcda$/) {
 	my ($filename, $content) = @_;
 	local *HANDLE;
 
-	open(HANDLE, ">$filename") || return 0;
+	open(HANDLE, ">", $filename) || return 0;
 	print(HANDLE $content);
 	close(HANDLE) || return 0;
 
 	local *HANDLE;
 	my $count = 0;
 
-	open(HANDLE, "tar tfz $filename|") or return undef;
+	open(HANDLE, "-|", "tar tfz '$filename'") or return undef;
 	while (<HANDLE>) {
 		if (/\.da$/ || /\.gcda$/) {
 			$count++;
 				"compressed file $_[0]!\n");
 
 		# Open compressed file
-		open(INFO_HANDLE, "gunzip -c $_[0]|")
+		open(INFO_HANDLE, "-|", "gunzip -c '$_[0]'")
 			or die("ERROR: cannot start gunzip to decompress ".
 			       "file $_[0]!\n");
 	}
 	else
 	{
 		# Open decompressed file
-		open(INFO_HANDLE, $_[0])
+		open(INFO_HANDLE, "<", $_[0])
 			or die("ERROR: cannot read file $_[0]!\n");
 	}
 
 	if ($to_file)
 	{
 		info("Writing data to $output_filename\n");
-		open(INFO_HANDLE, ">$output_filename")
+		open(INFO_HANDLE, ">", $output_filename)
 			or die("ERROR: cannot write to $output_filename!\n");
 		@result = write_info_file(*INFO_HANDLE, $total_trace);
 		close(*INFO_HANDLE);
 	{
 		info("Extracted $extracted files\n");
 		info("Writing data to $output_filename\n");
-		open(INFO_HANDLE, ">$output_filename")
+		open(INFO_HANDLE, ">", $output_filename)
 			or die("ERROR: cannot write to $output_filename!\n");
 		@result = write_info_file(*INFO_HANDLE, $data);
 		close(*INFO_HANDLE);
 	{
 		info("Deleted $removed files\n");
 		info("Writing data to $output_filename\n");
-		open(INFO_HANDLE, ">$output_filename")
+		open(INFO_HANDLE, ">", $output_filename)
 			or die("ERROR: cannot write to $output_filename!\n");
 		@result = write_info_file(*INFO_HANDLE, $data);
 		close(*INFO_HANDLE);
 				"compressed file $diff_file!\n");
 
 		# Open compressed file
-		open(HANDLE, "gunzip -c $diff_file|")
+		open(HANDLE, "-|", "gunzip -c '$diff_file'")
 			or die("ERROR: cannot start gunzip to decompress ".
 			       "file $_[0]!\n");
 	}
 	else
 	{
 		# Open decompressed file
-		open(HANDLE, $diff_file)
+		open(HANDLE, "<", $diff_file)
 			or die("ERROR: cannot read file $_[0]!\n");
 	}
 
 	if ($to_file)
 	{
 		info("Writing data to $output_filename\n");
-		open(INFO_HANDLE, ">$output_filename")
+		open(INFO_HANDLE, ">", $output_filename)
 			or die("ERROR: cannot write to $output_filename!\n");
 		@result = write_info_file(*INFO_HANDLE, $trace_data);
 		close(*INFO_HANDLE);
 	local *OLD_STDOUT;
 
 	# Save old stdout and stderr handles
-	($mode & 1) && open(OLD_STDOUT, ">>&STDOUT");
-	($mode & 2) && open(OLD_STDERR, ">>&STDERR");
+	($mode & 1) && open(OLD_STDOUT, ">>&", "STDOUT");
+	($mode & 2) && open(OLD_STDERR, ">>&", "STDERR");
 
 	# Redirect to /dev/null
-	($mode & 1) && open(STDOUT, ">/dev/null");
-	($mode & 2) && open(STDERR, ">/dev/null");
+	($mode & 1) && open(STDOUT, ">", "/dev/null");
+	($mode & 2) && open(STDERR, ">", "/dev/null");
  
 	system(@_);
 	$result = $?;
 	($mode & 2) && close(STDERR);
 
 	# Restore old handles
-	($mode & 1) && open(STDOUT, ">>&OLD_STDOUT");
-	($mode & 2) && open(STDERR, ">>&OLD_STDERR");
+	($mode & 1) && open(STDOUT, ">>&", "OLD_STDOUT");
+	($mode & 2) && open(STDERR, ">>&", "OLD_STDERR");
  
 	return $result;
 }
 	my $value;
 	local *HANDLE;
 
-	if (!open(HANDLE, "<$filename"))
+	if (!open(HANDLE, "<", $filename))
 	{
 		warn("WARNING: cannot read configuration file $filename\n");
 		return undef;