1 //===-- asan_scariness_score.h ----------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of AddressSanitizer, an address sanity checker.
11 // Compute the level of scariness of the error message.
12 // Don't expect any deep science here, just a set of heuristics that suggest
13 // that e.g. 1-byte-read-global-buffer-overflow is less scary than
14 // 8-byte-write-stack-use-after-return.
16 // Every error report has one or more features, such as memory access size,
17 // type (read or write), type of accessed memory (e.g. free-d heap, or a global
18 // redzone), etc. Every such feature has an int score and a string description.
19 // The overall score is the sum of all feature scores and the description
20 // is a concatenation of feature descriptions.
22 // 17 (4-byte-read-heap-buffer-overflow)
23 // 65 (multi-byte-write-stack-use-after-return)
26 //===----------------------------------------------------------------------===//
28 #ifndef ASAN_SCARINESS_SCORE_H
29 #define ASAN_SCARINESS_SCORE_H
31 #include "asan_flags.h"
32 #include "sanitizer_common/sanitizer_common.h"
33 #include "sanitizer_common/sanitizer_libc.h"
36 struct ScarinessScoreBase
{
41 void Scare(int add_to_score
, const char *reason
) {
43 internal_strlcat(descr
, "-", sizeof(descr
));
44 internal_strlcat(descr
, reason
, sizeof(descr
));
45 score
+= add_to_score
;
47 int GetScore() const { return score
; }
48 const char *GetDescription() const { return descr
; }
50 if (score
&& flags()->print_scariness
)
51 Printf("SCARINESS: %d (%s)\n", score
, descr
);
53 static void PrintSimple(int score
, const char *descr
) {
54 ScarinessScoreBase SSB
;
56 SSB
.Scare(score
, descr
);
65 struct ScarinessScore
: ScarinessScoreBase
{
73 #endif // ASAN_SCARINESS_SCORE_H