| 1 | package App::CVSS; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use feature ':5.10'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray :config gnu_compat); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Pod::Usage qw(pod2usage); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use JSON::PP (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Data::Dumper (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | ▶ | use CVSS (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | our $VERSION = $CVSS::VERSION; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | my %options = (format => 'json'); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub _print { print(($_[0] || '') . (defined $options{null} ? "\0" : "\n")) } | ||||||||||||||||||
|
Subroutine
_print: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/2
$_[0] || ''
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table0%0/2
A
A= $_[0]
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | sub cli_error { | ||||||||||||||||||
|
Subroutine
cli_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 23 | 0 | my ($error) = @_; | |||||||||||||||||||
| 24 | 0 | $error =~ s/ at .* line \d+.*//; | |||||||||||||||||||
| 25 | 0 | print STDERR "ERROR: $error\n"; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 2 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: called CC=23 SCAR=42.4
Pod
documented
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 2 | my ($class, @args) = @_; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | ▶ | GetOptionsFromArray( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | \@args, \%options, qw( | ||||||||||||||||||||
| 34 | help|h | ||||||||||||||||||||
| 35 | man | ||||||||||||||||||||
| 36 | v | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | vector-string=s | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | severity | ||||||||||||||||||||
| 41 | score | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | base-score | ||||||||||||||||||||
| 44 | base-severity | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | temporal-score | ||||||||||||||||||||
| 47 | temporal-severity | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | environmental-score | ||||||||||||||||||||
| 50 | environmental-severity | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | exploitability-score | ||||||||||||||||||||
| 53 | impact-score | ||||||||||||||||||||
| 54 | modified-impact-score | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | null|0 | ||||||||||||||||||||
| 57 | format=s | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | json | ||||||||||||||||||||
| 60 | xml | ||||||||||||||||||||
| 61 | ) | ||||||||||||||||||||
| 62 | ) or pod2usage(-verbose => 0); | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 2 | ▶ | pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 2 | ▶ | pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 2 | ▶ | if (defined $options{v}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | (my $progname = $0) =~ s/.*\///; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | say <<"VERSION"; | |||||||||||||||||||
| 72 | $progname version $VERSION | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Copyright 2023-2025, Giuseppe Di Terlizzi <gdt\@cpan.org> | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | This program is part of the "CVSS" distribution and is free software; | ||||||||||||||||||||
| 77 | you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Complete documentation for $progname can be found using 'man $progname' | ||||||||||||||||||||
| 80 | or on the internet at <https://metacpan.org/dist/CVSS>. | ||||||||||||||||||||
| 81 | VERSION | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | return 0; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 2 | my ($vector_string) = @args; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 2 | ▶ | pod2usage(-verbose => 1) if !$vector_string; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 2 | ▶ | $options{format} = 'json' if defined $options{json}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 2 | ▶ | $options{format} = 'xml' if defined $options{xml}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 2 | ▶ | $options{'base-severity'} = 1 if defined $options{severity}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 2 | ▶ | $options{'base-score'} = 1 if defined $options{score}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 2 | my $cvss = eval { CVSS->from_vector_string($vector_string) }; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 2 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | cli_error($@); | |||||||||||||||||||
| 101 | 0 | return 1; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 2 | ▶ | if ($options{'base-severity'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 0 | _print $cvss->base_severity; | |||||||||||||||||||
| 106 | 0 | return 0; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 2 | ▶ | if ($options{'base-score'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | _print $cvss->base_score; | |||||||||||||||||||
| 111 | 0 | return 0; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 2 | ▶ | if ($cvss->version <= 3.1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 2 | ▶ | if ($options{'environmental-score'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | 0 | _print $cvss->environmental_score; | |||||||||||||||||||
| 118 | 0 | return 0; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 2 | ▶ | if ($options{'environmental-severity'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 0 | _print $cvss->environmental_severity; | |||||||||||||||||||
| 123 | 0 | return 0; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 2 | ▶ | if ($options{'temporal-score'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | 0 | _print $cvss->temporal_score; | |||||||||||||||||||
| 128 | 0 | return 0; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 2 | ▶ | if ($options{'temporal-severity'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 0 | _print $cvss->temporal_severity; | |||||||||||||||||||
| 133 | 0 | return 0; | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 2 | ▶ | if ($options{'impact-score'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | 0 | _print $cvss->impact_score; | |||||||||||||||||||
| 138 | 0 | return 0; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 2 | ▶ | if ($options{'exploitability-score'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 142 | 0 | _print $cvss->exploitability_score; | |||||||||||||||||||
| 143 | 0 | return 0; | |||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 2 | ▶ | if ($options{'modified-impact-score'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | 0 | _print $cvss->modified_impact_score; | |||||||||||||||||||
| 148 | 0 | return 0; | |||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 2 | ▶ | if ($options{format} eq 'json') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 1 | print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($cvss); | |||||||||||||||||||
| 155 | 1 | return 0; | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | 1 | ▶ | if ($options{format} eq 'xml') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | 1 | print $cvss->to_xml; | |||||||||||||||||||
| 160 | 1 | return 0; | |||||||||||||||||||
| 161 | } | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 1 | 1; | |||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||