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