threads / discuss / 10450

git-remote: Use of uninitialized value in string ne, line 248

Subject: git-remote: Use of uninitialized value in string ne, line 248

## tl;dr

8 messages between Oct 24, 2007 and Oct 25, 2007.

replies: 7people: 5as markdown or json

martin f krafft· Oct 24, 2007, 11:08 UTC · lore

I am useless at Perl, otherwise I'd fix this, but I don't know what's going on, so best I can do is report it. This is against current tip of master.

piper:~> git remote show origin
* remote origin
  URL: ssh://git.madduck.net/~/git/etc/mailplate.git
Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Tracked remote branches
    master
piper:~> git branch
* master
-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"... and so he killed Miguel in a rit of fealous jage."
                                               -- inspector clouseau
 
spamtraps: madduck.bogus@madduck.net
Junio C Hamano· Oct 24, 2007, 11:49 UTC · re: martin f krafft · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

martin f krafft <madduck@madduck.net> writes:
Show 5 quoted lines
> piper:~> git remote show origin
> * remote origin
>   URL: ssh://git.madduck.net/~/git/etc/mailplate.git
> Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Perhaps....
 git-remote.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/git-remote.perl b/git-remote.perl
index 9ca3e7e..4cee044 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -244,7 +244,8 @@ sub show_remote {
 	print "* remote $name\n";
 	print "  URL: $info->{'URL'}\n";
 	for my $branchname (sort keys %$branch) {
-		next if ($branch->{$branchname}{'REMOTE'} ne $name);
+		next if (!$branch->{$branchname}{'REMOTE'} ||
+			 $branch->{$branchname}{'REMOTE'} ne $name);
 		my @merged = map {
 			s|^refs/heads/||;
 			$_;
martin f krafft· Oct 24, 2007, 11:59 UTC · re: Junio C Hamano · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

also sprach Junio C Hamano <gitster@pobox.com> [2007.10.24.1349 +0200]:
> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
> +		next if (!$branch->{$branchname}{'REMOTE'} ||
> +			 $branch->{$branchname}{'REMOTE'} ne $name);
Confirmed: this fixes the issue. Thanks.
-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"convictions are more dangerous enemies of truth than lies."
                                                 - friedrich nietzsche
 
spamtraps: madduck.bogus@madduck.net
Alex Riesen· Oct 24, 2007, 19:39 UTC · re: Junio C Hamano · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

Junio C Hamano, Wed, Oct 24, 2007 13:49:51 +0200:
Show 15 quoted lines
> Perhaps....
> 
>  git-remote.perl |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/git-remote.perl b/git-remote.perl
> index 9ca3e7e..4cee044 100755
> --- a/git-remote.perl
> +++ b/git-remote.perl
> @@ -244,7 +244,8 @@ sub show_remote {
>  	print "* remote $name\n";
>  	print "  URL: $info->{'URL'}\n";
>  	for my $branchname (sort keys %$branch) {
> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
> +		next if (!$branch->{$branchname}{'REMOTE'} ||
just you never call yor branches "0".
martin f krafft· Oct 24, 2007, 20:27 UTC · re: Alex Riesen · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

also sprach Alex Riesen <raa.lkml@gmail.com> [2007.10.24.2139 +0200]:
> just you never call yor branches "0".
Wow, Perl is weird. :)
perl -e 'print "The earth is a disk!\n" if ( "earth" == "flat" );'

Is there a way to make it explicit that you're checking for a value being defined, where a "false" value would count as true, just as long as there is a value?

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
micro$oft dns service terminates abnormally
when it receives a response
to a dns query that was never made.
fix information: run your dns service on a different platform.
                                                            -- bugtraq
 
spamtraps: madduck.bogus@madduck.net
Ralf Wildenhues· Oct 24, 2007, 20:40 UTC · re: martin f krafft · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

* martin f krafft wrote on Wed, Oct 24, 2007 at 10:27:24PM CEST:
> 
> perl -e 'print "The earth is a disk!\n" if ( "earth" == "flat" );'

Well, numerical equality and string equality are two different things, try eq instead (see: perldoc perlop).

> Is there a way to make it explicit that you're checking for a value
> being defined, where a "false" value would count as true, just as
> long as there is a value?
Yes.  It's called "defined".
  perl -e 'my $a=0; print "yes\n" if defined $a;'
It should be used here, to allow "0" branches.

Cheers, Ralf

Junio C Hamano· Oct 25, 2007, 01:48 UTC · re: Alex Riesen · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

Alex Riesen <raa.lkml@gmail.com> writes:
Show 18 quoted lines
> Junio C Hamano, Wed, Oct 24, 2007 13:49:51 +0200:
>> Perhaps....
>> 
>>  git-remote.perl |    3 ++-
>>  1 files changed, 2 insertions(+), 1 deletions(-)
>> 
>> diff --git a/git-remote.perl b/git-remote.perl
>> index 9ca3e7e..4cee044 100755
>> --- a/git-remote.perl
>> +++ b/git-remote.perl
>> @@ -244,7 +244,8 @@ sub show_remote {
>>  	print "* remote $name\n";
>>  	print "  URL: $info->{'URL'}\n";
>>  	for my $branchname (sort keys %$branch) {
>> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
>> +		next if (!$branch->{$branchname}{'REMOTE'} ||
>
> just you never call yor branches "0".
Ok, that is about remote name '0' but whatever...

-- >8 -- [PATCH] git-remote: fix "Use of uninitialized value in string ne"

martin f krafft <madduck@madduck.net> writes:
> piper:~> git remote show origin
> * remote origin
>   URL: ssh://git.madduck.net/~/git/etc/mailplate.git
> Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.

This is because there might not be branch.<name>.remote defined but the code unconditionally dereferences $branch->{$name}{'REMOTE'} and compares with another string.

Tested-by: Martin F Krafft <madduck@madduck.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-remote.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/git-remote.perl b/git-remote.perl
index 8e2dc4d..11630b1 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -244,7 +244,8 @@ sub show_remote {
 	print "* remote $name\n";
 	print "  URL: $info->{'URL'}\n";
 	for my $branchname (sort keys %$branch) {
-		next if ($branch->{$branchname}{'REMOTE'} ne $name);
+		next unless (defined $branch->{$branchname}{'REMOTE'} &&
+			     $branch->{$branchname}{'REMOTE'} eq $name);
 		my @merged = map {
 			s|^refs/heads/||;
 			$_;
-- 
1.5.3.4.1324.ga7925
Pierre Habouzit· Oct 24, 2007, 20:39 UTC · re: Junio C Hamano · lore

Re: git-remote: Use of uninitialized value in string ne, line 248

On Wed, Oct 24, 2007 at 11:49:51AM +0000, Junio C Hamano wrote:
Show 24 quoted lines
> martin f krafft <madduck@madduck.net> writes:
> 
> > piper:~> git remote show origin
> > * remote origin
> >   URL: ssh://git.madduck.net/~/git/etc/mailplate.git
> > Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Perhaps....
> 
>  git-remote.perl |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/git-remote.perl b/git-remote.perl
> index 9ca3e7e..4cee044 100755
> --- a/git-remote.perl
> +++ b/git-remote.perl
> @@ -244,7 +244,8 @@ sub show_remote {
>  	print "* remote $name\n";
>  	print "  URL: $info->{'URL'}\n";
>  	for my $branchname (sort keys %$branch) {
> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
> +		next if (!$branch->{$branchname}{'REMOTE'} ||
> +			 $branch->{$branchname}{'REMOTE'} ne $name);
  This looks better (wrt the "0" issue raised earlier):

+ next unless (defined($branch->{$branchname}{'REMOTE'}) && + $branch->{$branchname}{'REMOTE'} eq $name);

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

← back to recent threads