git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cvsserver: Determinize output to combat Perl 5.18 hash randomization
@ 2013-10-30  8:44 Anders Kaseorg
  2013-10-30 17:30 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Anders Kaseorg @ 2013-10-30  8:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, 727226

Perl 5.18 randomizes the seed used by its hash function, so iterating
through hashes results in different orders from run to run:
  http://perldoc.perl.org/perl5180delta.html#Hash-overhaul

This usually broke t9400 (gitcvs.dbname, gitcvs.ext.dbname, when
running cmp on two .sqlite files) and t9402 (check [cvswork3] diff,
when running test_cmp on two diffs).

To fix this, hide the internal order of hashes with sort when sending
output or running database queries.

(An alternative workaround is PERL_HASH_SEED=0, but this seems nicer.)

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 git-cvsserver.perl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 67b1e7b..6177f4a 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -430,10 +430,10 @@ sub req_validrequests
 
     $log->debug("req_validrequests");
 
-    $log->debug("SEND : Valid-requests " . join(" ",keys %$methods));
+    $log->debug("SEND : Valid-requests " . join(" ",sort keys %$methods));
     $log->debug("SEND : ok");
 
-    print "Valid-requests " . join(" ",keys %$methods) . "\n";
+    print "Valid-requests " . join(" ",sort keys %$methods) . "\n";
     print "ok\n";
 }
 
@@ -2124,7 +2124,7 @@ sub req_diff
             print "M retrieving revision $meta2->{revision}\n"
         }
         print "M diff ";
-        foreach my $opt ( keys %{$state->{opt}} )
+        foreach my $opt ( sort keys %{$state->{opt}} )
         {
             if ( ref $state->{opt}{$opt} eq "ARRAY" )
             {
@@ -4050,7 +4050,7 @@ sub update
             close FILELIST;
 
             # Detect deleted files
-            foreach my $file ( keys %$head )
+            foreach my $file ( sort keys %$head )
             {
                 unless ( exists $seen_files->{$file} or $head->{$file}{filehash} eq "deleted" )
                 {
@@ -4078,7 +4078,7 @@ sub update
     }
 
     $self->delete_head();
-    foreach my $file ( keys %$head )
+    foreach my $file ( sort keys %$head )
     {
         $self->insert_head(
             $file,
-- 
1.8.4.1

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

* Re: [PATCH] cvsserver: Determinize output to combat Perl 5.18 hash randomization
  2013-10-30  8:44 [PATCH] cvsserver: Determinize output to combat Perl 5.18 hash randomization Anders Kaseorg
@ 2013-10-30 17:30 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2013-10-30 17:30 UTC (permalink / raw)
  To: Anders Kaseorg; +Cc: git, 727226

Anders Kaseorg <andersk@MIT.EDU> writes:

> Perl 5.18 randomizes the seed used by its hash function, so iterating
> through hashes results in different orders from run to run:
>   http://perldoc.perl.org/perl5180delta.html#Hash-overhaul
>
> This usually broke t9400 (gitcvs.dbname, gitcvs.ext.dbname, when
> running cmp on two .sqlite files) and t9402 (check [cvswork3] diff,
> when running test_cmp on two diffs).
>
> To fix this, hide the internal order of hashes with sort when sending
> output or running database queries.
>
> (An alternative workaround is PERL_HASH_SEED=0, but this seems nicer.)
>
> Signed-off-by: Anders Kaseorg <andersk@mit.edu>

Thanks, will queue.

> ---
>  git-cvsserver.perl | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/git-cvsserver.perl b/git-cvsserver.perl
> index 67b1e7b..6177f4a 100755
> --- a/git-cvsserver.perl
> +++ b/git-cvsserver.perl
> @@ -430,10 +430,10 @@ sub req_validrequests
>  
>      $log->debug("req_validrequests");
>  
> -    $log->debug("SEND : Valid-requests " . join(" ",keys %$methods));
> +    $log->debug("SEND : Valid-requests " . join(" ",sort keys %$methods));
>      $log->debug("SEND : ok");
>  
> -    print "Valid-requests " . join(" ",keys %$methods) . "\n";
> +    print "Valid-requests " . join(" ",sort keys %$methods) . "\n";
>      print "ok\n";
>  }
>  
> @@ -2124,7 +2124,7 @@ sub req_diff
>              print "M retrieving revision $meta2->{revision}\n"
>          }
>          print "M diff ";
> -        foreach my $opt ( keys %{$state->{opt}} )
> +        foreach my $opt ( sort keys %{$state->{opt}} )
>          {
>              if ( ref $state->{opt}{$opt} eq "ARRAY" )
>              {
> @@ -4050,7 +4050,7 @@ sub update
>              close FILELIST;
>  
>              # Detect deleted files
> -            foreach my $file ( keys %$head )
> +            foreach my $file ( sort keys %$head )
>              {
>                  unless ( exists $seen_files->{$file} or $head->{$file}{filehash} eq "deleted" )
>                  {
> @@ -4078,7 +4078,7 @@ sub update
>      }
>  
>      $self->delete_head();
> -    foreach my $file ( keys %$head )
> +    foreach my $file ( sort keys %$head )
>      {
>          $self->insert_head(
>              $file,

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

end of thread, other threads:[~2013-10-30 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-30  8:44 [PATCH] cvsserver: Determinize output to combat Perl 5.18 hash randomization Anders Kaseorg
2013-10-30 17:30 ` Junio C Hamano

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 NNTP newsgroup(s).