1 //===-- asan_scariness_score.h ----------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
10 // Compute the level of scariness of the error message.
11 // Don't expect any deep science here, just a set of heuristics that suggest
12 // that e.g. 1-byte-read-global-buffer-overflow is less scary than
13 // 8-byte-write-stack-use-after-return.
15 // Every error report has one or more features, such as memory access size,
16 // type (read or write), type of accessed memory (e.g. free-d heap, or a global
17 // redzone), etc. Every such feature has an int score and a string description.
18 // The overall score is the sum of all feature scores and the description
19 // is a concatenation of feature descriptions.
21 // 17 (4-byte-read-heap-buffer-overflow)
22 // 65 (multi-byte-write-stack-use-after-return)
25 //===----------------------------------------------------------------------===//
27 #ifndef ASAN_SCARINESS_SCORE_H
28 #define ASAN_SCARINESS_SCORE_H
30 #include "asan_flags.h"
31 #include "sanitizer_common/sanitizer_common.h"
32 #include "sanitizer_common/sanitizer_libc.h"
35 struct ScarinessScoreBase
{
40 void Scare(int add_to_score
, const char *reason
) {
42 internal_strlcat(descr
, "-", sizeof(descr
));
43 internal_strlcat(descr
, reason
, sizeof(descr
));
44 score
+= add_to_score
;
46 int GetScore() const { return score
; }
47 const char *GetDescription() const { return descr
; }
49 if (score
&& flags()->print_scariness
)
50 Printf("SCARINESS: %d (%s)\n", score
, descr
);
52 static void PrintSimple(int score
, const char *descr
) {
53 ScarinessScoreBase SSB
;
55 SSB
.Scare(score
, descr
);
64 struct ScarinessScore
: ScarinessScoreBase
{
72 #endif // ASAN_SCARINESS_SCORE_H