Skip to content

Commit dff2b6d

Browse files
jnarebgitster
authored andcommitted
gitweb: Always use three argument form of open
In most cases (except insert_file() subroutine) we used old two argument form of 'open' to open files for reading. This can cause subtle bugs when $projectroot or $projects_list file starts with mode characters ('>', '<', '+<', '|', etc.) or with leading whitespace; and also when $projects_list file or $mimetypes_file or ctags files end with trailing whitespace or '|'. Additionally it is also more clear to explicitly state that we open those files for reading. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad87e4f commit dff2b6d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

gitweb/gitweb.perl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ sub git_get_project_description {
20502050
my $path = shift;
20512051

20522052
$git_dir = "$projectroot/$path";
2053-
open my $fd, "$git_dir/description"
2053+
open my $fd, '<', "$git_dir/description"
20542054
or return git_get_project_config('description');
20552055
my $descr = <$fd>;
20562056
close $fd;
@@ -2068,7 +2068,7 @@ sub git_get_project_ctags {
20682068
opendir my $dh, "$git_dir/ctags"
20692069
or return $ctags;
20702070
foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2071-
open my $ct, $_ or next;
2071+
open my $ct, '<', $_ or next;
20722072
my $val = <$ct>;
20732073
chomp $val;
20742074
close $ct;
@@ -2128,7 +2128,7 @@ sub git_get_project_url_list {
21282128
my $path = shift;
21292129

21302130
$git_dir = "$projectroot/$path";
2131-
open my $fd, "$git_dir/cloneurl"
2131+
open my $fd, '<', "$git_dir/cloneurl"
21322132
or return wantarray ?
21332133
@{ config_to_multi(git_get_project_config('url')) } :
21342134
config_to_multi(git_get_project_config('url'));
@@ -2186,7 +2186,7 @@ sub git_get_projects_list {
21862186
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
21872187
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
21882188
my %paths;
2189-
open my ($fd), $projects_list or return;
2189+
open my $fd, '<', $projects_list or return;
21902190
PROJECT:
21912191
while (my $line = <$fd>) {
21922192
chomp $line;
@@ -2249,7 +2249,7 @@ sub git_get_project_list_from_file {
22492249
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
22502250
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
22512251
if (-f $projects_list) {
2252-
open (my $fd , $projects_list);
2252+
open(my $fd, '<', $projects_list);
22532253
while (my $line = <$fd>) {
22542254
chomp $line;
22552255
my ($pr, $ow) = split ' ', $line;
@@ -2803,7 +2803,7 @@ sub mimetype_guess_file {
28032803
-r $mimemap or return undef;
28042804

28052805
my %mimemap;
2806-
open(my $mh, $mimemap) or return undef;
2806+
open(my $mh, '<', $mimemap) or return undef;
28072807
while (<$mh>) {
28082808
next if m/^#/; # skip comments
28092809
my ($mimetype, $exts) = split(/\t+/);

0 commit comments

Comments
 (0)