[svn:parrot] r49246 - in trunk: src t/run

chromatic at svn.parrot.org chromatic at svn.parrot.org
Wed Sep 22 15:02:40 UTC 2010


Author: chromatic
Date: Wed Sep 22 15:02:39 2010
New Revision: 49246
URL: https://trac.parrot.org/parrot/changeset/49246

Log:
[main] Fixed --gc-threshold args segfault TT #1797.

Because parseflags_minimal() performs minimal options processing, it has to
check the length of the arguments before the getopts processor does so.  The
good news is that fixing this here avoids other potential crashes and memory
infelicities.

Modified:
   trunk/src/main.c
   trunk/t/run/options.t

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	Wed Sep 22 12:53:50 2010	(r49245)
+++ trunk/src/main.c	Wed Sep 22 15:02:39 2010	(r49246)
@@ -398,7 +398,9 @@
             }
             break;
         }
-        else if (!strncmp(arg, "--gc-threshold", 14)) {
+        /* don't overflow argv; check length first */
+        else if (argc > arg + 14
+             && !strncmp(arg, "--gc-threshold", 14)) {
 
             if ((arg = strrchr(arg, '=')))
                 ++arg;

Modified: trunk/t/run/options.t
==============================================================================
--- trunk/t/run/options.t	Wed Sep 22 12:53:50 2010	(r49245)
+++ trunk/t/run/options.t	Wed Sep 22 15:02:39 2010	(r49246)
@@ -20,7 +20,7 @@
 use warnings;
 use lib qw( lib . ../lib ../../lib );
 
-use Test::More tests => 28;
+use Test::More tests => 30;
 use Parrot::Config;
 use File::Temp 0.13 qw/tempfile/;
 use File::Spec;
@@ -96,6 +96,13 @@
 # Test --runtime-prefix
 like( qx{$PARROT --runtime-prefix}, qr/^.+$/, "--runtime-prefix" );
 
+# TT #1797: check for warning error and mask off "did it crash?" bits
+my $output = qx{$PARROT --gc-threshold 2>&1 };
+my $exit   = $? & 127;
+like( $output, qr/--gc-threshold needs an argument/,
+                 '--gc-threshold needs argument warning' );
+is( $exit, 0, '... and should not crash' );
+
 # clean up temporary files
 unlink $first_pir_file;
 unlink $second_pir_file;


More information about the parrot-commits mailing list