From: Junio C Hamano <gitster@pobox.com>
To: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] gitweb: Fixes error handling when reading configuration
Date: Wed, 10 Jan 2024 16:17:54 -0800 [thread overview]
Message-ID: <xmqqzfxc7mfh.fsf@gitster.g> (raw)
In-Reply-To: <20240110225709.30168-1-marcelo.jimenez@gmail.com> (Marcelo Roberto Jimenez's message of "Wed, 10 Jan 2024 19:57:09 -0300")
Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com> writes:
> 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.
Well explained how the current code behaves and why.
With my devil's advocate hat on, I suspect that the current
behaviour comes from the wish to see "file exists but unreadable"
and "the named file does not exist" behave the same way. If you
pass the name of a configuration file that does not exist, however,
the codeblock to die does not trigger at all. If a file does exist
but unreadable, to gitweb, it is just as good as having no file to
read configuration data from---either way, it cannot use anything
useful from the named file. So returning silently, which is the
"bug" you are fixing, does not sound too bad.
I dunno. Let's queue and see what others would say.
Thanks.
> 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..5d0122020f 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;
> }
next prev parent reply other threads:[~2024-01-11 0:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-10 0:43 Problem in gitweb.cgi Marcelo Roberto Jimenez
2024-01-10 22:05 ` [PATCH] gitweb: Fixes error handling when reading configuration Marcelo Roberto Jimenez
2024-01-10 22:57 ` [PATCH v2] " Marcelo Roberto Jimenez
2024-01-11 0:17 ` Junio C Hamano [this message]
2024-01-11 2:14 ` Marcelo Roberto Jimenez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzfxc7mfh.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=marcelo.jimenez@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).