@matheusbsbs / matheus-bagliano / commits / dff2b6d484
Fork 0

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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed May 10, 2009 at 02:38 UTC dff2b6d4842eef0a03a3c8b3761f72e2b55b609e
1 file changed +6 -6
gitweb/gitweb.perl
+6 -6
@@ -2050,7 +2050,7 @@ sub git_get_project_description {
2050 my $path = shift;
2051
2052 $git_dir = "$projectroot/$path";
2053 - open my $fd, "$git_dir/description"
2053 + open my $fd, '<', "$git_dir/description"
2054 or return git_get_project_config('description');
2055 my $descr = <$fd>;
2056 close $fd;
@@ -2068,7 +2068,7 @@ sub git_get_project_ctags {
2068 opendir my $dh, "$git_dir/ctags"
2069 or return $ctags;
2070 foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2071 - open my $ct, $_ or next;
2071 + open my $ct, '<', $_ or next;
2072 my $val = <$ct>;
2073 chomp $val;
2074 close $ct;
@@ -2128,7 +2128,7 @@ sub git_get_project_url_list {
2128 my $path = shift;
2129
2130 $git_dir = "$projectroot/$path";
2131 - open my $fd, "$git_dir/cloneurl"
2131 + open my $fd, '<', "$git_dir/cloneurl"
2132 or return wantarray ?
2133 @{ config_to_multi(git_get_project_config('url')) } :
2134 config_to_multi(git_get_project_config('url'));
@@ -2186,7 +2186,7 @@ sub git_get_projects_list {
2186 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2187 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2188 my %paths;
2189 - open my ($fd), $projects_list or return;
2189 + open my $fd, '<', $projects_list or return;
2190 PROJECT:
2191 while (my $line = <$fd>) {
2192 chomp $line;
@@ -2249,7 +2249,7 @@ sub git_get_project_list_from_file {
2249 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2250 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2251 if (-f $projects_list) {
2252 - open (my $fd , $projects_list);
2252 + open(my $fd, '<', $projects_list);
2253 while (my $line = <$fd>) {
2254 chomp $line;
2255 my ($pr, $ow) = split ' ', $line;
@@ -2803,7 +2803,7 @@ sub mimetype_guess_file {
2803 -r $mimemap or return undef;
2804
2805 my %mimemap;
2806 - open(my $mh, $mimemap) or return undef;
2806 + open(my $mh, '<', $mimemap) or return undef;
2807 while (<$mh>) {
2808 next if m/^#/; # skip comments
2809 my ($mimetype, $exts) = split(/\t+/);