]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: squelch "uninitialized value" warning
authorØyvind A. Holm <redacted>
Tue, 12 Jan 2016 03:31:56 +0000 (04:31 +0100)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:32 +0000 (00:51 -0400)
git_object() chomps $type that is read from "cat-file -t", but
it does so before checking if $type is defined, resulting in
a Perl warning in the server error log:

  gitweb.cgi: Use of uninitialized value $type in scalar chomp at
  [...]/gitweb.cgi line 7579., referer: [...]

when trying to access a non-existing commit, for example:

  http://HOST/?p=PROJECT.git;a=commit;h=NON_EXISTING_COMMIT

Check the value in $type before chomping.  This will cause us to
call href with its action parameter set to undef when formulating
the URL to redirect to, but that is harmless, as the function treats
a parameter that set to undef as if it does not exist.

Signed-off-by: Øyvind A. Holm <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index 9956e5991d009314fd0577b7f6ae10f3afc363a1c60de404b7b2d50bc28ca0d5..40730e11d815b9c4291ab516ee0bc24e43eac2b6a3d285a2c8360593b37c2e52 100755 (executable)
@@ -7577,7 +7577,7 @@ sub git_object {
                        git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
                        or die_error(404, "Object does not exist");
                $type = <$fd>;
                        git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
                        or die_error(404, "Object does not exist");
                $type = <$fd>;
-               chomp $type;
+               defined $type && chomp $type;
                close $fd
                        or die_error(404, "Object does not exist");
 
                close $fd
                        or die_error(404, "Object does not exist");
 
This page took 0.365541 seconds and 4 git commands to generate.