git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557
@ 2018-04-06 12:01 Joseph Mingrone
  2018-04-06 12:21 ` Johannes Schindelin
  2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 11+ messages in thread
From: Joseph Mingrone @ 2018-04-06 12:01 UTC (permalink / raw)
  To: git; +Cc: garga

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]

Hello,

After upgrading to version 2.17.0, this message appears repeatedly when
running `git svn rebase`:

Use of uninitialized value $rec in scalar chomp at /usr/local/lib/perl5/site_perl/Git.pm line 557, <$fh> chunk 1.

The value of chunk varies.  For example the message above may end with
'...<$fh> chunk 5.'  This is with the FreeBSD packages git-2.17.0 and
perl 5.26.1.

Regards,

J.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 962 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557
  2018-04-06 12:01 git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557 Joseph Mingrone
@ 2018-04-06 12:21 ` Johannes Schindelin
  2018-04-06 12:32   ` Joseph Mingrone
  2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
  1 sibling, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2018-04-06 12:21 UTC (permalink / raw)
  To: Joseph Mingrone; +Cc: git, garga

Hi Joseph,

On Fri, 6 Apr 2018, Joseph Mingrone wrote:

> After upgrading to version 2.17.0, this message appears repeatedly when
> running `git svn rebase`:
> 
> Use of uninitialized value $rec in scalar chomp at /usr/local/lib/perl5/site_perl/Git.pm line 557, <$fh> chunk 1.
> 
> The value of chunk varies.  For example the message above may end with
> '...<$fh> chunk 5.'  This is with the FreeBSD packages git-2.17.0 and
> perl 5.26.1.

Does this stop the `rebase`?

Also: could you publish the unrebased branch so that others can reproduce
the error? (I am not claiming that I have enough time; I don't...)

Thanks,
Johannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557
  2018-04-06 12:21 ` Johannes Schindelin
@ 2018-04-06 12:32   ` Joseph Mingrone
  0 siblings, 0 replies; 11+ messages in thread
From: Joseph Mingrone @ 2018-04-06 12:32 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, garga

[-- Attachment #1: Type: text/plain, Size: 904 bytes --]

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi Joseph,

> On Fri, 6 Apr 2018, Joseph Mingrone wrote:

>> After upgrading to version 2.17.0, this message appears repeatedly when
>> running `git svn rebase`:

>> Use of uninitialized value $rec in scalar chomp at /usr/local/lib/perl5/site_perl/Git.pm line 557, <$fh> chunk 1.

>> The value of chunk varies.  For example the message above may end with
>> '...<$fh> chunk 5.'  This is with the FreeBSD packages git-2.17.0 and
>> perl 5.26.1.

> Does this stop the `rebase`?

> Also: could you publish the unrebased branch so that others can reproduce
> the error? (I am not claiming that I have enough time; I don't...)

> Thanks,
> Johannes

Hi Johannes,

No, this does not stop the `svn rebase`.  This is with the FreeBSD ports tree, svn.freebsd.org/ports, following the setup described at https://wiki.freebsd.org/GitWorkflow/GitSvn .

J.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 962 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 12:01 git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557 Joseph Mingrone
  2018-04-06 12:21 ` Johannes Schindelin
@ 2018-04-06 13:15 ` Ævar Arnfjörð Bjarmason
  2018-04-06 14:30   ` Johannes Schindelin
                     ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-04-06 13:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Joseph Mingrone, garga, Johannes Schindelin,
	Eric Wong, Ævar Arnfjörð Bjarmason

Change code in Git.pm that sometimes calls chomp() on undef to only do
so the value is defined.

This code has been chomping undef values ever since it was added in
b26098fc2f ("git-svn: reduce scope of input record separator change",
2016-10-14), but started warning due to the introduction of "use
warnings" to Git.pm in my f0e19cb7ce ("Git.pm: add the "use warnings"
pragma", 2018-02-25) released with 2.17.0.

Since this function will return undef in those cases it's still
possible that the code using it will warn if it does a chomp of its
own, as the code added in b26098fc2f ("git-svn: reduce scope of input
record separator change", 2016-10-14) might do, but since git-svn has
"use warnings" already that's clearly not a codepath that's going to
warn.

See https://public-inbox.org/git/86h8oobl36.fsf@phe.ftfl.ca/ for the
original report.

Reported-by: Joseph Mingrone <jrm@ftfl.ca>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 16ebcc612c..6b6079c456 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -554,7 +554,7 @@ sub get_record {
 	my ($fh, $rs) = @_;
 	local $/ = $rs;
 	my $rec = <$fh>;
-	chomp $rec if defined $rs;
+	chomp $rec if defined $rs and defined $rec;
 	$rec;
 }
 
-- 
2.17.0.rc1.321.gba9d0f2565


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
@ 2018-04-06 14:30   ` Johannes Schindelin
  2018-04-06 16:56   ` Eric Wong
  2018-04-07 19:20   ` brian m. carlson
  2 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2018-04-06 14:30 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Joseph Mingrone, garga, Eric Wong

[-- Attachment #1: Type: text/plain, Size: 1586 bytes --]

Hi Ævar,

On Fri, 6 Apr 2018, Ævar Arnfjörð Bjarmason wrote:

> Change code in Git.pm that sometimes calls chomp() on undef to only do
> so the value is defined.
> 
> This code has been chomping undef values ever since it was added in
> b26098fc2f ("git-svn: reduce scope of input record separator change",
> 2016-10-14), but started warning due to the introduction of "use
> warnings" to Git.pm in my f0e19cb7ce ("Git.pm: add the "use warnings"
> pragma", 2018-02-25) released with 2.17.0.
> 
> Since this function will return undef in those cases it's still
> possible that the code using it will warn if it does a chomp of its
> own, as the code added in b26098fc2f ("git-svn: reduce scope of input
> record separator change", 2016-10-14) might do, but since git-svn has
> "use warnings" already that's clearly not a codepath that's going to
> warn.
> 
> See https://public-inbox.org/git/86h8oobl36.fsf@phe.ftfl.ca/ for the
> original report.
> 
> Reported-by: Joseph Mingrone <jrm@ftfl.ca>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  perl/Git.pm | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/perl/Git.pm b/perl/Git.pm
> index 16ebcc612c..6b6079c456 100644
> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -554,7 +554,7 @@ sub get_record {
>  	my ($fh, $rs) = @_;
>  	local $/ = $rs;
>  	my $rec = <$fh>;
> -	chomp $rec if defined $rs;
> +	chomp $rec if defined $rs and defined $rec;
>  	$rec;
>  }

The explanation as well as the patch make a total lot of sense to me.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
  2018-04-06 14:30   ` Johannes Schindelin
@ 2018-04-06 16:56   ` Eric Wong
  2018-04-06 18:23     ` Ævar Arnfjörð Bjarmason
  2018-04-09  2:09     ` Junio C Hamano
  2018-04-07 19:20   ` brian m. carlson
  2 siblings, 2 replies; 11+ messages in thread
From: Eric Wong @ 2018-04-06 16:56 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Joseph Mingrone, garga, Johannes Schindelin,
	Ben Caradoc-Davies, 894997

Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> See https://public-inbox.org/git/86h8oobl36.fsf@phe.ftfl.ca/ for the
> original report.

Thanks for taking a look at this.  Also https://bugs.debian.org/894997

> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -554,7 +554,7 @@ sub get_record {
>  	my ($fh, $rs) = @_;
>  	local $/ = $rs;
>  	my $rec = <$fh>;
> -	chomp $rec if defined $rs;
> +	chomp $rec if defined $rs and defined $rec;

I'm struggling to understand the reason for the "defined $rs"
check.  I think it was a braino on my part and meant to use:

	chomp $rec if defined $rec;

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 16:56   ` Eric Wong
@ 2018-04-06 18:23     ` Ævar Arnfjörð Bjarmason
  2018-04-06 20:49       ` Eric Wong
  2018-04-09  2:09     ` Junio C Hamano
  1 sibling, 1 reply; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-04-06 18:23 UTC (permalink / raw)
  To: Eric Wong
  Cc: git, Junio C Hamano, Joseph Mingrone, garga, Johannes Schindelin,
	Ben Caradoc-Davies, 894997


On Fri, Apr 06 2018, Eric Wong wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> See https://public-inbox.org/git/86h8oobl36.fsf@phe.ftfl.ca/ for the
>> original report.
>
> Thanks for taking a look at this.  Also https://bugs.debian.org/894997
>
>> --- a/perl/Git.pm
>> +++ b/perl/Git.pm
>> @@ -554,7 +554,7 @@ sub get_record {
>>  	my ($fh, $rs) = @_;
>>  	local $/ = $rs;
>>  	my $rec = <$fh>;
>> -	chomp $rec if defined $rs;
>> +	chomp $rec if defined $rs and defined $rec;
>
> I'm struggling to understand the reason for the "defined $rs"
> check.  I think it was a braino on my part and meant to use:
>
> 	chomp $rec if defined $rec;

Whether this makes any sense is another question, but you seem to have
explicitly meant this at the time. The full function definition with
documentation:

    =item get_record ( FILEHANDLE, INPUT_RECORD_SEPARATOR )

    Read one record from FILEHANDLE delimited by INPUT_RECORD_SEPARATOR,
    removing any trailing INPUT_RECORD_SEPARATOR.

    =cut

    sub get_record {
    	my ($fh, $rs) = @_;
    	local $/ = $rs;
    	my $rec = <$fh>;
    	chomp $rec if defined $rs;
    	$rec;
    }

It doesn't make to remove the trailing record separator if it's not
defined, otherwise we'd be coercing undef to "\n" while at the same time
returning multiple records. But then of course the only user of this
with an "undef" argument just does:

    chomp($log_entry{log} = get_record($log_fh, undef));

So we could also remove that chomp(), adn not check defined $rs, but IMO
it's cleaner & more consistent this way.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 18:23     ` Ævar Arnfjörð Bjarmason
@ 2018-04-06 20:49       ` Eric Wong
  2018-04-06 21:05         ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 11+ messages in thread
From: Eric Wong @ 2018-04-06 20:49 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Joseph Mingrone, garga, Johannes Schindelin,
	Ben Caradoc-Davies, 894997

Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> On Fri, Apr 06 2018, Eric Wong wrote:
> > Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> >
> >> --- a/perl/Git.pm
> >> +++ b/perl/Git.pm
> >> @@ -554,7 +554,7 @@ sub get_record {
> >>  	my ($fh, $rs) = @_;
> >>  	local $/ = $rs;
> >>  	my $rec = <$fh>;
> >> -	chomp $rec if defined $rs;
> >> +	chomp $rec if defined $rs and defined $rec;
> >
> > I'm struggling to understand the reason for the "defined $rs"
> > check.  I think it was a braino on my part and meant to use:
> >
> > 	chomp $rec if defined $rec;
> 
> Whether this makes any sense is another question, but you seem to have
> explicitly meant this at the time. The full function definition with
> documentation:
> 
>     =item get_record ( FILEHANDLE, INPUT_RECORD_SEPARATOR )
> 
>     Read one record from FILEHANDLE delimited by INPUT_RECORD_SEPARATOR,
>     removing any trailing INPUT_RECORD_SEPARATOR.

I've always known chomp to respect the value of $/; so chomp($rec)
whould only cut out whatever $rs is, and be a no-op if $rs is undef.

> It doesn't make to remove the trailing record separator if it's not
> defined, otherwise we'd be coercing undef to "\n" while at the same time
> returning multiple records. But then of course the only user of this
> with an "undef" argument just does:
> 
>     chomp($log_entry{log} = get_record($log_fh, undef));

Subtle difference, that chomp() still sees $/ as "\n".
$/ is only undef inside get_record.

> So we could also remove that chomp(), adn not check defined $rs, but IMO
> it's cleaner & more consistent this way.

I think the chomp is necessary. In git-svn.perl /^sub get_commit_entry {:

	# <snip>
	open my $log_fh, '>', $commit_editmsg or croak $!;

	# <snip>
		$msgbuf =~ s/\s+$//s;

	# <snip>

		print $log_fh $msgbuf or croak $!;

	# <snip>
	close $log_fh or croak $!;

# Above, we ensured the contents of $commit_editmsg has no trailing newline

	if ($_edit || ($type eq 'tree')) {
		chomp(my $editor = command_oneline(qw(var GIT_EDITOR)));
		system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
	}

# However, $editor is likely to introduce a trailing newline

	rename $commit_editmsg, $commit_msg or croak $!;
	{
		require Encode;
		# SVN requires messages to be UTF-8 when entering the repo
		open $log_fh, '<', $commit_msg or croak $!;
		binmode $log_fh;

# chomp trailing newline introduced by $editor:

		chomp($log_entry{log} = get_record($log_fh, undef));

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 20:49       ` Eric Wong
@ 2018-04-06 21:05         ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-04-06 21:05 UTC (permalink / raw)
  To: Eric Wong
  Cc: git, Junio C Hamano, Joseph Mingrone, garga, Johannes Schindelin,
	Ben Caradoc-Davies, 894997


On Fri, Apr 06 2018, Eric Wong wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> On Fri, Apr 06 2018, Eric Wong wrote:
>> > Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> >
>> >> --- a/perl/Git.pm
>> >> +++ b/perl/Git.pm
>> >> @@ -554,7 +554,7 @@ sub get_record {
>> >>  	my ($fh, $rs) = @_;
>> >>  	local $/ = $rs;
>> >>  	my $rec = <$fh>;
>> >> -	chomp $rec if defined $rs;
>> >> +	chomp $rec if defined $rs and defined $rec;
>> >
>> > I'm struggling to understand the reason for the "defined $rs"
>> > check.  I think it was a braino on my part and meant to use:
>> >
>> > 	chomp $rec if defined $rec;
>>
>> Whether this makes any sense is another question, but you seem to have
>> explicitly meant this at the time. The full function definition with
>> documentation:
>>
>>     =item get_record ( FILEHANDLE, INPUT_RECORD_SEPARATOR )
>>
>>     Read one record from FILEHANDLE delimited by INPUT_RECORD_SEPARATOR,
>>     removing any trailing INPUT_RECORD_SEPARATOR.
>
> I've always known chomp to respect the value of $/; so chomp($rec)
> whould only cut out whatever $rs is, and be a no-op if $rs is undef.

Yup, you're right. I missed that.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
  2018-04-06 14:30   ` Johannes Schindelin
  2018-04-06 16:56   ` Eric Wong
@ 2018-04-07 19:20   ` brian m. carlson
  2 siblings, 0 replies; 11+ messages in thread
From: brian m. carlson @ 2018-04-07 19:20 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Joseph Mingrone, garga, Johannes Schindelin,
	Eric Wong

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

On Fri, Apr 06, 2018 at 01:15:14PM +0000, Ævar Arnfjörð Bjarmason wrote:
> Change code in Git.pm that sometimes calls chomp() on undef to only do
> so the value is defined.
> 
> This code has been chomping undef values ever since it was added in
> b26098fc2f ("git-svn: reduce scope of input record separator change",
> 2016-10-14), but started warning due to the introduction of "use
> warnings" to Git.pm in my f0e19cb7ce ("Git.pm: add the "use warnings"
> pragma", 2018-02-25) released with 2.17.0.
> 
> Since this function will return undef in those cases it's still
> possible that the code using it will warn if it does a chomp of its
> own, as the code added in b26098fc2f ("git-svn: reduce scope of input
> record separator change", 2016-10-14) might do, but since git-svn has
> "use warnings" already that's clearly not a codepath that's going to
> warn.

Thanks for this patch.  I ran into this earlier this week (with git svn
fetch) and had intended to send a patch, but you clearly got to it
before I did.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 867 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] git-svn: avoid warning on undef readline()
  2018-04-06 16:56   ` Eric Wong
  2018-04-06 18:23     ` Ævar Arnfjörð Bjarmason
@ 2018-04-09  2:09     ` Junio C Hamano
  1 sibling, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2018-04-09  2:09 UTC (permalink / raw)
  To: Eric Wong
  Cc: Ævar Arnfjörð Bjarmason, git, Joseph Mingrone,
	garga, Johannes Schindelin, Ben Caradoc-Davies, 894997

Eric Wong <e@80x24.org> writes:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> See https://public-inbox.org/git/86h8oobl36.fsf@phe.ftfl.ca/ for the
>> original report.
>
> Thanks for taking a look at this.  Also https://bugs.debian.org/894997
>
>> --- a/perl/Git.pm
>> +++ b/perl/Git.pm
>> @@ -554,7 +554,7 @@ sub get_record {
>>  	my ($fh, $rs) = @_;
>>  	local $/ = $rs;
>>  	my $rec = <$fh>;
>> -	chomp $rec if defined $rs;
>> +	chomp $rec if defined $rs and defined $rec;
>
> I'm struggling to understand the reason for the "defined $rs"
> check.  I think it was a braino on my part and meant to use:
>
> 	chomp $rec if defined $rec;

That sounds quite plausible, so if there is no further discussion,
let me queue a version that does s/rs/rec/ on that line myself
(bypassing a pull from your repository at bogomips.org/).

Thanks.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-04-09  2:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06 12:01 git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557 Joseph Mingrone
2018-04-06 12:21 ` Johannes Schindelin
2018-04-06 12:32   ` Joseph Mingrone
2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
2018-04-06 14:30   ` Johannes Schindelin
2018-04-06 16:56   ` Eric Wong
2018-04-06 18:23     ` Ævar Arnfjörð Bjarmason
2018-04-06 20:49       ` Eric Wong
2018-04-06 21:05         ` Ævar Arnfjörð Bjarmason
2018-04-09  2:09     ` Junio C Hamano
2018-04-07 19:20   ` brian m. carlson

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).