Subject: Re: [PATCH] gitweb: fix 'Use of uninitialized value' error in href()

From: Jakub Narebski <[email-masked]>
Date: Fri, 31 Jul 2009 10:30:50 +0200

On Fri, 31 July 2009, Giuseppe Bilotta wrote:

> Equality between file_parent and file_name was being checked without a
> preliminary check for existence of the parameters.
> 
> Fix by wrapping the equality check in appropriate if (defined ...),
> rearranging the lines to prevent excessive length.
> 
> Signed-off-by: Giuseppe Bilotta <[email-masked]>

For what it is worth:

Acked-by: Jakub Narebski <[email-masked]>

> ---
>  gitweb/gitweb.perl |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> The funny thing is that I seem to get the error for something as simple
> as a commit view (_any_ commit view, for the matter), but I wasn't able
> to reproduce it from the shell, which is why I'm not adding a testcase.

Gaaah! A Heisenbug! ;-)

Well, it worth fixing if it is real case scenario.

> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 7fbd5ff..37120a3 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -940,10 +940,13 @@ sub href {
>  			if (defined $params{'hash_parent_base'}) {
>  				$href .= esc_url($params{'hash_parent_base'});
>  				# skip the file_parent if it's the same as the file_name
> -				delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
> -				if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
> -					$href .= ":/".esc_url($params{'file_parent'});
> -					delete $params{'file_parent'};
> +				if (defined $params{'file_parent'}) {
> +					if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {

or, to reduce line length even more:

  +					if (defined $params{'file_name'} &&
  +					    $params{'file_parent'} eq $params{'file_name'}) {

> +						delete $params{'file_parent'};
> +					} elsif ($params{'file_parent'} !~ /\.\./) {
> +						$href .= ":/".esc_url($params{'file_parent'});
> +						delete $params{'file_parent'};
> +					}
>  				}
>  				$href .= "..";
>  				delete $params{'hash_parent'};
> -- 
> 1.6.3.rc1.192.gdbfcb
> 
> 

-- 
Jakub Narebski
Poland