| 1 | 19 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 19 | ▶ | use feature 'class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | no warnings 'experimental::class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | class Azure::SDK::Core::Error { | |||||||||||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 19 | field $message :param :reader = undef; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 19 | field $status :param :reader = undef; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | field $code :param :reader = undef; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 19 | field $body :param :reader = undef; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 19 | field $max_body_bytes :param = 16 * 1024; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 47 | ▶ | ADJUST { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 47 | ▶ | croak 'Azure::SDK::Core::Error requires a message' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $message and length $message
MC/DC50%1/2
defined $message and length $message
defined $message
length $message
Truth table66%2/3
A and B
A= defined $messageB= length $message
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | unless defined $message && length $message; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # CWE-770 defense-in-depth: cap the stored server body so a hostile or | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # runaway error response cannot balloon memory or log volume. The raw | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # bytes up to the cap are preserved (see log_safe for a log-safe view). | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 46 | ▶ | if (defined $body && $max_body_bytes > 0 && length $body > $max_body_bytes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $body and $max_body_bytes > 0 and length $body > $max_body_bytes
defined $body and $max_body_bytes > 0
MC/DC100%3/3
defined $body and $max_body_bytes > 0 and length $body > $max_body_bytes
defined $body
$max_body_bytes > 0
length $body > $max_body_bytes
Truth table100%4/4
A and B and C
A= defined $bodyB= $max_body_bytes > 0C= length $body > $max_body_bytes
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $body = substr($body, 0, $max_body_bytes) . '...[truncated]'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 41 | ▶ | method throw () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 41 | die $self; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 14 | ▶ | method to_string () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | # to_string is documented as single-line, so the (untrusted) message and | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # code are sanitized to neutralize embedded CR/LF and control characters. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 14 | my $detail = _sanitize_for_log($message); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | ▶ | $detail .= " (status $status)" if defined $status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | $detail .= ' [' . _sanitize_for_log($code) . ']' if defined $code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | return $detail; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | method as_hashref () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hashref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | message => $message, | |||||||||||||||||||||||||||||||||||||||||
| 43 | status => $status, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | body => $body, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 10 | ▶ | method log_safe () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_safe: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 10 | message => _sanitize_for_log($message), | |||||||||||||||||||||||||||||||||||||||||
| 52 | status => $status, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | code => _sanitize_for_log($code), | ||||||||||||||||||||||||||||||||||||||||||
| 54 | body => _sanitize_for_log($body), | ||||||||||||||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Collapse runs of control characters (including CR/LF and tab) to a single | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # space so untrusted server-supplied text cannot forge or split log lines | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # (CWE-117) when a caller logs the error. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 58 | ▶ | sub _sanitize_for_log ($value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sanitize_for_log: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 58 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 58 | $value =~ s/[\x00-\x1f\x7f]+/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 58 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||||||||||||||||