summaryrefslogtreecommitdiffstats
path: root/bin/updatelist
blob: b103d8b872c1958ba2f1b565eb11d299b3c78505 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/perl
my $html=shift;
my $dsa_list=shift;
my $dtsa_list=shift;
my $our_list=shift;

my %cves;

sub read_dsa {
	my $list=shift;
	
	open (DSA, "<$list") || die "$list: $!\n";
	my $dsa;
	while (<DSA>) {
		if (/^\[/) {
			($dsa)=m/(DT?SA-.*?) /;
		}
		if (/\{\s*(CVE)/) {
			my ($cvelist)=m/\{(.*)\}/;
			foreach my $cve (split ' ', $cvelist) {
				next unless $cve=~/^CVE-\d+/;
				$cves{$cve}{cve}=$cve;
				push @{$cves{$cve}{xref}}, $dsa;
			}
		}
	}
	close DSA;
}
read_dsa($dsa_list);
read_dsa($dtsa_list);

my %listedcves;

open (HTML, "<$html") || die "$html: $!\n";
my $cve;
while (<HTML>) {
	if (m!<b>Name:\s+(CVE-\d+-\d+)</b>!) {
		$cve=$1;
		$cves{$cve}{cve}=$cve;
		$listedcves{$cve}=1;
	}
	if (m!\*\*\s+RESERVED\s+\*\*!) {
		$cves{$cve}{reserved}=1;
			
	}
	if (m!\*\*\s+REJECT\s+\*\*!) {
		$cves{$cve}{rejected}=1;
	}
	if (m!Description:\s*</b><br>\s*(.*)! &&
		! m!\*\*\s+RESERVED\s+\*\*! && ! m!\*\*\s+REJECT\s+\*\*!) {
		my $desc;
		$desc=$1;
		if (! length $desc) {
			$desc=<HTML>;
			chomp $desc;
		}
		$cves{$cve}{description}="($desc ...)";
	}
}
close HTML;

my $stopped=0;
my @out;

sub docve {
	my $cve=shift;	
	
	push @out, "$cve".(length $cves{$cve}{description} ? " ".$cves{$cve}{description} : "")."\n";
	if ($cves{$cve}{reserved}) {
		push @out, "\tRESERVED\n";
	}
	if ($cves{$cve}{rejected}) {
		push @out, "\tREJECTED\n";
	}
	if (scalar @{$cves{$cve}{xref}} > 0) {
		push @out, "\t{".join(" ", @{$cves{$cve}{xref}})."}\n";
	}
	if ($cves{$cve}{notes}) {
		foreach (@{$cves{$cve}{notes}}) {
			push @out, "\t$_\n";
		}
	}
	if (! $cves{$cve}{reserved} && ! $cves{$cve}{rejected} &&
	    ! $cves{$cve}{notes} &&
	    ! $stopped) {
	    	if ($cve =~ /^CVE-199|^CVE-200[012]/) {
		    push @out, "\tNOT-FOR-US: Data pre-dating the Security Tracker\n";
		}
		else {
		    push @out, "\tTODO: check\n";
		}
	}
		
	delete $cves{$cve};
}

open (IN, "<$our_list") || die "$our_list: $!\n";
my $cve;
while (<IN>) {
	chomp;
	if (/^(CVE-(?:[0-9]+|[A-Z]+)-(?:[0-9]+|[A-Z]+))\s*(.*)/) {
		my $desc=$2;
		docve($cve) if $cve;
		$cve=$1;
		if (length $desc && $desc !~ /^\(.*\)$/ &&
		    (! exists $cves{$cve}{description} ||
		     ! length $cves{$cve}{description})) {
			$cves{$cve}{description}=$desc;
		}
	}
	elsif (/^\s+(RESERVED|REJECTED)\s*$/) {
		# skip it
	}
	elsif (/^\s+NOTE: covered by DT?SA.*/) {
		# skip it (old form)
	}
	elsif (/^\s+{\s*(.+?)\s*}/) {
		my @xrefs=split('\s+', $1);
		push @{$cves{$cve}{xref}}, grep(!/^DT?SA/, @xrefs);
	}
	elsif (/^\s+(.*)/ && $cve) {
		push @{$cves{$cve}{notes}}, $1;
	}
	elsif (/^STOP/) {
		docve($cve) if $cve;
		push @out, "$_\n";
		$stopped=1;
		$cve='';
	}
	else {
		docve($cve) if $cve;
		push @out, "$_\n" if length $_;
		$cve='';
	}
}
close IN;
docve($cve) if $cve;

foreach my $cve (reverse sort { $cves{$a}{cve} cmp $cves{$b}{cve} } keys %cves) {
	next unless $listedcves{$cve};
	print $cve.(length $cves{$cve}{description} ? " ".$cves{$cve}{description} : "")."\n";
	if ($cves{$cve}{reserved}) {
		print "\tRESERVED\n";
	}
	if ($cves{$cve}{rejected}) {
		print "\tREJECTED\n";
	}
	if (scalar @{$cves{$cve}{xref}} > 0) {
		print "\t{".join(" ", @{$cves{$cve}{xref}})."}\n";
	}
	if (!$cves{$cve}{reserved} || $cves{$cve}{rejected} ) {
		print "\tTODO: check\n";
	}
}

print @out;

© 2014-2024 Faster IT GmbH | imprint | privacy policy