gitweb: suppress 'Use of uninitialized value' error
PATCH 1/1 gitweb: suppress 'Use of uninitialized value' error
--- 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.
gitweb/gitweb.perl +7 -4
@@ -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'};
Signature · 1 line
1.6.3.rc1.192.gdbfcb
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.
Quoted 1 line
Signed-off-by Giuseppe Bilotta <[email protected]>
Otherwise, for what it is worth:
Quoted 7 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.
Quoted 27 lines
gitweb/gitweb.perl +7
-4@@ -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'};Signature · 1 line
1.6.3.rc1.192.gdbfcb
Signature · 2 lines
Jakub Narebski Poland
2009/7/31 Jakub Narebski <[email protected]>:
Quoted 12 lines · Giuseppe Bilotta
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.
Quoted 10 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:
Quoted 5 lines
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).
Quoted 3 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?
Quoted 3 lines
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.
Quoted 10 lines
Quoted 6 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.
Quoted 1 line
Quoted 16 lines
Quoted 6 lines
gitweb/gitweb.perl +0
-0@@ -940,10 +940,13 @@ sub href { if (defined $params{'hash_parent_base'}) {gitweb/gitweb.perl sub href { · line 946
Quoted 10 lines
gitweb/gitweb.perl +4
-4$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.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 7 lines · Giuseppe Bilotta
2009/7/31 Jakub Narebski <[email protected]>:
Quoted 3 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.
Signature · 2 lines
Jakub Narebski Poland
PATCH 1/1 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.
--- 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.
gitweb/gitweb.perl +7 -4
@@ -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'};
Signature · 1 line
1.6.3.rc1.192.gdbfcb
Re: [PATCH] gitweb: fix 'Use of uninitialized value' error in href()
Quoted 7 lines · Giuseppe Bilotta
Equality between
file_parentandfile_namewas 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 protected]>
For what it is worth:
Quoted 7 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.
Quoted 6 lines
gitweb/gitweb.perl +0
-0
gitweb/gitweb.perl sub href { · line 944
Quoted 9 lines
gitweb/gitweb.perl +2
-4@@ -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'}) {Quoted 12 lines
gitweb/gitweb.perl +5
-0+ delete $params{'file_parent'}; + } elsif ($params{'file_parent'} !~ /\.\./) { + $href .= ":/".esc_url($params{'file_parent'}); + delete $params{'file_parent'}; + } } $href .= ".."; delete $params{'hash_parent'};Signature · 1 line
1.6.3.rc1.192.gdbfcb
Signature · 2 lines
Jakub Narebski Poland
Re: [PATCH] gitweb: fix 'Use of uninitialized value' error in href()
Quoted 1 line · Jakub Narebski
Acked-by Jakub Narebski <[email protected]>
Thanks, both.
Re: [PATCH] gitweb: fix 'Use of uninitialized value' error in href()
In reply to Jakub Narebski2009/7/31 Jakub Narebski <[email protected]>:
Quoted 7 lines · Giuseppe Bilotta
Quoted 4 lines
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.
Quoted 7 lines
Quoted 2 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?
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Re: [PATCH] gitweb: fix 'Use of uninitialized value' error in href()
Quoted 7 lines · Giuseppe Bilotta
2009/7/31 Jakub Narebski <[email protected]>:
Quoted 6 lines · Giuseppe Bilotta
Quoted 4 lines
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.
Quoted 7 lines
Quoted 1 line
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_parenteqfile_nameis 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.