[PATCH] gitweb: Fixes error handling when reading configuration
- From
Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com>
- Date
- Jan 10, 2024, 22:05 UTC
- Message-ID
- <20240110220506.27491-1-marcelo.jimenez@gmail.com>
- In-Reply-To
- <CACjc_5pdijCZrrXQWHswsxYrGUzZ7pZq+nj3SzY1z+Xxop64Ww@mail.gmail.com>
This patch fixes a possibility of a permission to access error go unnoticed.
Perl uses two different variables to manage errors from a do. One is $@, which is set in this case when do is unable to compile the file. The other is $!, which is set in case do cannot read the file. By printing the value of $! I found out that it was set to Permission denied. Since the script does not currently test for $!, the error goes unnoticed.
Perl do block documentation: https://perldoc.perl.org/functions/do
Signed-off-by: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com> --- gitweb/gitweb.perl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index e66eb3d9ba..47577ec566 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -728,9 +728,11 @@ sub filter_and_validate_refs { sub read_config_file { my $filename = shift; return unless defined $filename; - # die if there are errors parsing config file if (-e $filename) { do $filename; + #die if there is a problem accessing the file + die $! if $!; + # die if there are errors parsing config file die $@ if $@; return 1; }
-- 2.43.0