threads / patch / 20301

patchgitweb: suppress 'Use of uninitialized value' error

Subject: [PATCH] gitweb: suppress 'Use of uninitialized value' error

## tl;dr

9 messages between Jul 30, 2009 and Aug 4, 2009. Diffs are folded; open one to read it.

replies: 8people: 3as markdown or json

Giuseppe Bilotta· Jul 30, 2009, 21:15 UTC · lore
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 gitweb/gitweb.perl |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

The patch could have been a one-liner by adding the defined check at line 943, but that pushed the line to 120 char, so I decided for this slightly more complex form.

Show changes to gitweb/gitweb.perl +7 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7fbd5ff..c7f257e 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 ($params{'file_parent'} eq $params{'file_name'}) {
+						delete $params{'file_parent'};
+					} else if ($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· Jul 30, 2009, 23:00 UTC · re: Giuseppe Bilotta · lore

Re: [PATCH] gitweb: suppress 'Use of uninitialized value' error

On Thu, 30 July 2009, Giuseppe Bilotta wrote:
Thanks for catching this.

However... First, the subject should be more specific and less generic. At least provide where 'Use of uninitialized' value was generated, e.g.:

  Subject: [PATCH] gitweb: Fix 'Use of uninitialized value' error in href()
or a bit shorter
  Subject: [PATCH] gitweb: Fix 'Use of uninitialized value' in href()

Second, it would be nice to have more detailed description in the body of a commit message, in this case stating when mentioned error occur:

  This warning was generated when 'hash_parent_base' parameter was
  defined, and either 'file_name' or 'file_parent' was not defined.

Note that from above description you can notice that you protect against 'file_parent' being not defined, but not against 'file_name', so you should I think write why it is not a problem:

  In gitweb code 'file_parent' is used only if 'file_name' is filled.

Well... almost. This does not cover href(..., -replay=>1) with hand crafted broken/invalid gitweb URL. BTW. a question for you: how did you detect/found this breakage? I don't think gitweb generates such broken links (with 'hash_parent_base' but not 'file_parent') normally, but I might be mistaken.

Third, we would probably want to have additional case in t/t9500 test to protect against regression here. But that is not as important, I think.

> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Otherwise, for what it is worth:
Acked-by: Jakub Narebski <jnareb@gmail.com>
Show 7 quoted lines
> ---
>  gitweb/gitweb.perl |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
> 
> The patch could have been a one-liner by adding the defined check at
> line 943, but that pushed the line to 120 char, so I decided for this
> slightly more complex form.
That is IMHO a good solution.  Better not abuse 'if' modifier form.
Show 27 quoted lines
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 7fbd5ff..c7f257e 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 ($params{'file_parent'} eq $params{'file_name'}) {
> +						delete $params{'file_parent'};
> +					} else if ($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
Giuseppe Bilotta· Jul 31, 2009, 06:06 UTC · re: Jakub Narebski · lore

Re: [PATCH] gitweb: suppress 'Use of uninitialized value' error

2009/7/31 Jakub Narebski <jnareb@gmail.com>:
Show 12 quoted lines
> On Thu, 30 July 2009, Giuseppe Bilotta wrote:
>
> Thanks for catching this.
>
> However... First, the subject should be more specific and less generic.
> At least provide where 'Use of uninitialized' value was generated, e.g.:
>
>  Subject: [PATCH] gitweb: Fix 'Use of uninitialized value' error in href()
>
> or a bit shorter
>
>  Subject: [PATCH] gitweb: Fix 'Use of uninitialized value' in href()
Agreed.
Show 15 quoted lines
> Second, it would be nice to have more detailed description in the body
> of a commit message, in this case stating when mentioned error occur:
>
>  This warning was generated when 'hash_parent_base' parameter was
>  defined, and either 'file_name' or 'file_parent' was not defined.
>
> Note that from above description you can notice that you protect against
> 'file_parent' being not defined, but not against 'file_name', so you
> should I think write why it is not a problem:
>
>  In gitweb code 'file_parent' is used only if 'file_name' is filled.
>
> Well... almost.  This does not cover href(..., -replay=>1) with hand
> crafted broken/invalid gitweb URL.  BTW. a question for you: how did
> you detect/found this breakage?

I was looking at the error log of my webserver and spotted the lines, coming from a spider indexing my git pages. An URL that caused it is http://git.oblomov.eu/git/commit/32ae83194b0f287a9b6644cdad175c56417c31f3 (the tree link, I suspect).

> I don't think gitweb generates such
> broken links (with 'hash_parent_base' but not 'file_parent') normally,
> but I might be mistaken.
Do you think it would be worth to protect against this case?
> Third, we would probably want to have additional case in t/t9500 test
> to protect against regression here.  But that is not as important,
> I think.
I'll see if I can cook that up.
Show 26 quoted lines
>>  gitweb/gitweb.perl |   11 +++++++----
>>  1 files changed, 7 insertions(+), 4 deletions(-)
>>
>> The patch could have been a one-liner by adding the defined check at
>> line 943, but that pushed the line to 120 char, so I decided for this
>> slightly more complex form.
>
> That is IMHO a good solution.  Better not abuse 'if' modifier form.
>
>>
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index 7fbd5ff..c7f257e 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 ($params{'file_parent'} eq $params{'file_name'}) {
>> +                                             delete $params{'file_parent'};
>> +                                     } else if ($params{'file_parent'} !~ /\.\./) {
And I'm an idiot 'cause this should be 'elsif'.
Resend coming soon.
-- 
Giuseppe "Oblomov" Bilotta
Jakub Narebski· Jul 31, 2009, 06:24 UTC · re: Giuseppe Bilotta · lore

Re: [PATCH] gitweb: suppress 'Use of uninitialized value' error

Giuseppe Bilotta wrote:
> 2009/7/31 Jakub Narebski <jnareb@gmail.com>:
Show 5 quoted lines
> > I don't think gitweb generates such
> > broken links (with 'hash_parent_base' but not 'file_parent') normally,
> > but I might be mistaken.
> 
> Do you think it would be worth to protect against this case?

Yes, of course it is worth protecting against this case (better checking if both sides of 'eq' comparison are defined). We want to return error message from gitweb if URL is borked, not have Perl error in logs.

-- 
Jakub Narebski
Poland
Giuseppe Bilotta· Jul 31, 2009, 06:48 UTC · re: Jakub Narebski · lore

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

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 <giuseppe.bilotta@gmail.com>
---
 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.

Show changes to gitweb/gitweb.perl +7 −4
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'}) {
+						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· Jul 31, 2009, 08:30 UTC · re: Giuseppe Bilotta · lore

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

On Fri, 31 July 2009, Giuseppe Bilotta wrote:
Show 7 quoted lines
> 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 <giuseppe.bilotta@gmail.com>
For what it is worth:
Acked-by: Jakub Narebski <jnareb@gmail.com>
Show 7 quoted lines
> ---
>  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.
Show 15 quoted lines
> 
> 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'}) {
Show 12 quoted lines
> +						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
Giuseppe Bilotta· Jul 31, 2009, 08:37 UTC · re: Jakub Narebski · lore

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

2009/7/31 Jakub Narebski <jnareb@gmail.com>:
Show 7 quoted lines
> On Fri, 31 July 2009, Giuseppe Bilotta wrote:
>>
>> 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, I can reproduce it consistently on the gitweb repository, with any shortlog or commit view. I also think I understand why it happens (i.e. in some cases the check for file_parent eq file_name is done before calling href). The question, of course, is why wouldn't it happen in the test repository.

Show 7 quoted lines
>> +                             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'}) {
Oh right ... should I resend?
-- 
Giuseppe "Oblomov" Bilotta
Junio C Hamano· Jul 31, 2009, 14:51 UTC · re: Giuseppe Bilotta · lore

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

Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:
Show 14 quoted lines
> 2009/7/31 Jakub Narebski <jnareb@gmail.com>:
>> On Fri, 31 July 2009, Giuseppe Bilotta wrote:
>>>
>>> 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, I can reproduce it consistently on the gitweb repository, with
> any shortlog or commit view. I also think I understand why it happens
> (i.e. in some cases the check for file_parent eq file_name is done
> before calling href). The question, of course, is why wouldn't it
> happen in the test repository.

That sounds like something worth figuring out, independent of the issue this patch addresses.

← back to recent threads