Fix boot sectors; cleanup_hardware must preserve registers
[syslinux.git] / checkov.pl
blobc7f018c8a08a6a13be36e6b63fcf459414c8a17e
1 #!/usr/bin/perl
3 # checkov.pl
5 # Check NASM map output for overflow
7 # This assumes that a section for which start != vstart, both
8 # ranges need to be checked for overflow (true for SYSLINUX)
11 ($in, $target) = @ARGV;
13 sub overlap($$$$) {
14 my($s1,$e1,$s2,$e2) = @_;
16 return 1 if ( $s2 < $e1 && $e2 > $s1 );
17 return 1 if ( $s1 < $e2 && $e1 > $s2 );
19 return 0;
22 open(IN, '<', $in) or die "$0: Cannot open input file: $in\n";
24 $section = undef;
25 while ( $line = <IN> ) {
26 if ( $line =~ /^-/ ) {
27 if ( $line =~ /^\-\-\-\- Section (\S+) / ) {
28 $section = $1;
29 } else {
30 $section = undef;
32 } elsif ( defined($section) ) {
33 if ( $line =~ /^length\:\s*(\S+)/ ) {
34 $length{$section} = hex $1;
35 } elsif ( $line =~ /^start\:\s*(\S+)/ ) {
36 $start{$section} = hex $1;
37 } elsif ( $line =~ /^vstart\:\s*(\S+)/ ) {
38 $vstart{$section} = hex $1;
42 close(IN);
44 $err = 0;
46 foreach $s ( keys(%start) ) {
47 $sstart = $start{$s};
48 $svstart = $vstart{$s};
49 $send = $sstart + $length{$s};
50 $svend = $svstart + $length{$s};
52 if ( $send > 0x10000 || $svend > 0x10000 ) {
53 print STDERR "$target: 16-bit overflow on section $s\n";
54 $err++;
57 foreach $o ( keys(%start) ) {
58 next if ( $s ge $o );
60 $ostart = $start{$o};
61 $ovstart = $vstart{$o};
62 $oend = $ostart + $length{$o};
63 $ovend = $ovstart + $length{$o};
65 if ( overlap($sstart, $send, $ostart, $oend) ||
66 overlap($svstart, $svend, $ostart, $oend) ||
67 overlap($sstart, $send, $ovstart, $ovend) ||
68 overlap($svstart, $svend, $ovstart, $ovend) ) {
69 print STDERR "$target: section $s overlaps section $o\n";
70 $err++;
75 if ( $err ) {
76 unlink($target);
77 exit(1);
78 } else {
79 exit(0);