]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/diagnostic-manager.h
analyzer: fix dedupe issue seen with CVE-2005-1689
[thirdparty/gcc.git] / gcc / analyzer / diagnostic-manager.h
1 /* Classes for saving, deduplicating, and emitting analyzer diagnostics.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #ifndef GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
22 #define GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
23
24 /* A to-be-emitted diagnostic stored within diagnostic_manager. */
25
26 class saved_diagnostic
27 {
28 public:
29 saved_diagnostic (const state_machine *sm,
30 const exploded_node *enode,
31 const supernode *snode, const gimple *stmt,
32 stmt_finder *stmt_finder,
33 tree var, state_machine::state_t state,
34 pending_diagnostic *d);
35 ~saved_diagnostic ();
36
37 bool operator== (const saved_diagnostic &other) const;
38
39 //private:
40 const state_machine *m_sm;
41 const exploded_node *m_enode;
42 const supernode *m_snode;
43 const gimple *m_stmt;
44 stmt_finder *m_stmt_finder;
45 tree m_var;
46 state_machine::state_t m_state;
47 pending_diagnostic *m_d;
48 exploded_edge *m_trailing_eedge;
49
50 private:
51 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
52 };
53
54 /* A class with responsibility for saving pending diagnostics, so that
55 they can be emitted after the exploded_graph is complete.
56 This lets us de-duplicate diagnostics, and find the shortest path
57 for each similar diagnostic, potentially using edges that might
58 not have been found when each diagnostic was first saved.
59
60 This also lets us compute shortest_paths once, rather than
61 per-diagnostic. */
62
63 class diagnostic_manager : public log_user
64 {
65 public:
66 diagnostic_manager (logger *logger, int verbosity);
67
68 void add_diagnostic (const state_machine *sm,
69 const exploded_node *enode,
70 const supernode *snode, const gimple *stmt,
71 stmt_finder *finder,
72 tree var, state_machine::state_t state,
73 pending_diagnostic *d);
74
75 void add_diagnostic (const exploded_node *enode,
76 const supernode *snode, const gimple *stmt,
77 stmt_finder *finder,
78 pending_diagnostic *d);
79
80 void emit_saved_diagnostics (const exploded_graph &eg);
81
82 void emit_saved_diagnostic (const exploded_graph &eg,
83 const saved_diagnostic &sd,
84 const exploded_path &epath,
85 const gimple *stmt,
86 int num_dupes);
87
88 unsigned get_num_diagnostics () const
89 {
90 return m_saved_diagnostics.length ();
91 }
92 saved_diagnostic *get_saved_diagnostic (unsigned idx)
93 {
94 return m_saved_diagnostics[idx];
95 }
96
97 private:
98 void build_emission_path (const exploded_graph &eg,
99 const exploded_path &epath,
100 checker_path *emission_path) const;
101
102 void add_events_for_eedge (const exploded_edge &eedge,
103 const extrinsic_state &ext_state,
104 checker_path *emission_path) const;
105
106 void add_events_for_superedge (const exploded_edge &eedge,
107 checker_path *emission_path) const;
108
109 void prune_path (checker_path *path,
110 const state_machine *sm,
111 tree var, state_machine::state_t state) const;
112
113 void prune_for_sm_diagnostic (checker_path *path,
114 const state_machine *sm,
115 tree var,
116 state_machine::state_t state) const;
117 void prune_interproc_events (checker_path *path) const;
118 void finish_pruning (checker_path *path) const;
119
120 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
121 const int m_verbosity;
122 };
123
124 #endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */