+#!/usr/bin/perl
+
use strict;
use warnings;
use Digest::SHA;
{
return { a => 'inglobal', b => 'inglobalfunc' };
}
+ if($op =~ /^INVALID#/)
+ {
+ return { isinvalid => 1 };
+ }
return { a => 'inglobal', b => 'inglobal', c => 'outglobal' };
}
}
}
+ if($c->{isinvalid})
+ {
+ ++$warned{$ip}{''}{"Invalid opcode"};
+ }
for(qw(a b c))
{
my $type = $c->{$_};
use constant GLOBALFLAG_U => 64; # unused
use constant GLOBALFLAG_P => 128; # possibly parameter passing
use constant GLOBALFLAG_D => 256; # has a def
- my @globalflags = (GLOBALFLAG_Q | GLOBALFLAG_U) x @{$progs->{globals}};
+ my @globalflags = (GLOBALFLAG_Q | GLOBALFLAG_U) x (@{$progs->{globals}} + 2);
for(@{$progs->{functions}})
{
die "Out of range name in globaldef $_"
if $g->{s_name} < 0 || $g->{s_name} >= length $p{strings};
my $name = $p{getstring}->($g->{s_name});
- die "Out of range ofs in globaldef $_ (name: \"$name\")"
+ die "Out of range ofs $g->{ofs} in globaldef $_ (name: \"$name\")"
if $g->{ofs} >= $p{globals};
}
die "Out of range name in fielddef $_"
if $g->{s_name} < 0 || $g->{s_name} >= length $p{strings};
my $name = $p{getstring}->($g->{s_name});
- die "Out of range ofs in globaldef $_ (name: \"$name\")"
+ die "Out of range ofs $g->{ofs} in fielddef $_ (name: \"$name\")"
if $g->{ofs} >= $p{header}{entityfields};
}
my $file = $p{getstring}->($f->{s_file});
die "Out of range first_statement in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
if $f->{first_statement} >= @{$p{statements}};
- die "Out of range parm_start in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
- if $f->{parm_start} < 0 || $f->{parm_start} >= @{$p{globals}};
- die "Out of range locals in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
- if $f->{locals} < 0 || $f->{parm_start} + $f->{locals} >= @{$p{globals}};
if($f->{first_statement} >= 0)
{
+ die "Out of range parm_start in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
+ if $f->{parm_start} < 0 || $f->{parm_start} >= @{$p{globals}};
+ die "Out of range locals in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
+ if $f->{locals} < 0 || $f->{parm_start} + $f->{locals} > @{$p{globals}};
die "Out of range numparms $f->{numparms} in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
if $f->{numparms} < 0 || $f->{numparms} > 8;
my $totalparms = 0;
$totalparms += $f->{parm_size}[$_];
}
die "Out of range parms in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
- if $f->{locals} < 0 || $f->{parm_start} + $totalparms >= @{$p{globals}};
+ if $f->{parm_start} + $totalparms > @{$p{globals}};
+ die "More parms than locals in function $_ (name: \"$name\", file: \"$file\", first statement: $f->{first_statement})"
+ if $totalparms > $f->{locals};
}
}
elsif($type eq 'inglobalvec')
{
$s->{$_} &= 0xFFFF;
- die "Out of range global offset in statement $ip - cannot continue"
- if $s->{$_} >= @{$p{globals}}-2;
+ if($c->{isreturn})
+ {
+ die "Out of range global offset in statement $ip - cannot continue"
+ if $s->{$_} >= @{$p{globals}};
+ print "Potentially out of range global offset in statement $ip - may crash engines"
+ if $s->{$_} >= @{$p{globals}}-2;
+ }
+ else
+ {
+ die "Out of range global offset in statement $ip - cannot continue"
+ if $s->{$_} >= @{$p{globals}}-2;
+ }
}
elsif($type eq 'outglobal')
{