Static Value-Flow Analysis
Loading...
Searching...
No Matches
SaberCheckerAPI.cpp
Go to the documentation of this file.
1//===- SaberCheckerAPI.cpp -- API for checkers-------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * SaberCheckerAPI.cpp
25 *
26 * Created on: Apr 23, 2014
27 * Author: Yulei Sui
28 */
30#include <stdio.h>
31
32using namespace std;
33using namespace SVF;
34
36
37namespace
38{
39
41struct ei_pair
42{
43 const char *n;
45};
46
47} // End anonymous namespace
48
49//Each (name, type) pair will be inserted into the map.
50//All entries of the same type must occur together (for error detection).
51static const ei_pair ei_pairs[]=
52{
54 {"alloc_check", SaberCheckerAPI::CK_ALLOC},
55 {"alloc_clear", SaberCheckerAPI::CK_ALLOC},
56 {"calloc", SaberCheckerAPI::CK_ALLOC},
57 {"jpeg_alloc_huff_table", SaberCheckerAPI::CK_ALLOC},
58 {"jpeg_alloc_quant_table", SaberCheckerAPI::CK_ALLOC},
59 {"lalloc", SaberCheckerAPI::CK_ALLOC},
60 {"lalloc_clear", SaberCheckerAPI::CK_ALLOC},
61 {"malloc", SaberCheckerAPI::CK_ALLOC},
62 {"nhalloc", SaberCheckerAPI::CK_ALLOC},
63 {"oballoc", SaberCheckerAPI::CK_ALLOC},
64 {"permalloc", SaberCheckerAPI::CK_ALLOC},
65 {"png_create_info_struct", SaberCheckerAPI::CK_ALLOC},
66 {"png_create_write_struct", SaberCheckerAPI::CK_ALLOC},
67 {"safe_calloc", SaberCheckerAPI::CK_ALLOC},
68 {"safe_malloc", SaberCheckerAPI::CK_ALLOC},
69 {"safecalloc", SaberCheckerAPI::CK_ALLOC},
70 {"safemalloc", SaberCheckerAPI::CK_ALLOC},
71 {"safexcalloc", SaberCheckerAPI::CK_ALLOC},
72 {"safexmalloc", SaberCheckerAPI::CK_ALLOC},
73 {"savealloc", SaberCheckerAPI::CK_ALLOC},
74 {"xalloc", SaberCheckerAPI::CK_ALLOC},
75 {"xcalloc", SaberCheckerAPI::CK_ALLOC},
76 {"xmalloc", SaberCheckerAPI::CK_ALLOC},
77 {"SSL_CTX_new", SaberCheckerAPI::CK_ALLOC},
78 {"SSL_new", SaberCheckerAPI::CK_ALLOC},
79 {"VOS_MemAlloc", SaberCheckerAPI::CK_ALLOC},
80 {"HeapAlloc", SaberCheckerAPI::CK_ALLOC},
81 {"\01HeapAlloc", SaberCheckerAPI::CK_ALLOC},
82 {"LocalAlloc", SaberCheckerAPI::CK_ALLOC},
83 {"\01LocalAlloc", SaberCheckerAPI::CK_ALLOC},
84 {"GlobalAlloc", SaberCheckerAPI::CK_ALLOC},
85 {"\01GlobalAlloc", SaberCheckerAPI::CK_ALLOC},
86 {"_malloc_dbg", SaberCheckerAPI::CK_ALLOC},
87 {"\01_malloc_dbg", SaberCheckerAPI::CK_ALLOC},
88 {"_aligned_malloc", SaberCheckerAPI::CK_ALLOC},
89 {"\01_aligned_malloc", SaberCheckerAPI::CK_ALLOC},
90
91 {"VOS_MemFree", SaberCheckerAPI::CK_FREE},
92 {"cfree", SaberCheckerAPI::CK_FREE},
94 {"free_all_mem", SaberCheckerAPI::CK_FREE},
95 {"freeaddrinfo", SaberCheckerAPI::CK_FREE},
96 {"gcry_mpi_release", SaberCheckerAPI::CK_FREE},
97 {"gcry_sexp_release", SaberCheckerAPI::CK_FREE},
98 {"globfree", SaberCheckerAPI::CK_FREE},
99 {"nhfree", SaberCheckerAPI::CK_FREE},
100 {"obstack_free", SaberCheckerAPI::CK_FREE},
101 {"safe_cfree", SaberCheckerAPI::CK_FREE},
102 {"safe_free", SaberCheckerAPI::CK_FREE},
103 {"safefree", SaberCheckerAPI::CK_FREE},
104 {"safexfree", SaberCheckerAPI::CK_FREE},
105 {"sm_free", SaberCheckerAPI::CK_FREE},
106 {"vim_free", SaberCheckerAPI::CK_FREE},
107 {"xfree", SaberCheckerAPI::CK_FREE},
108 {"SSL_CTX_free", SaberCheckerAPI::CK_FREE},
109 {"SSL_free", SaberCheckerAPI::CK_FREE},
110 {"XFree", SaberCheckerAPI::CK_FREE},
111 {"HeapFree", SaberCheckerAPI::CK_FREE},
112 {"\01HeapFree", SaberCheckerAPI::CK_FREE},
113 {"LocalFree", SaberCheckerAPI::CK_FREE},
114 {"\01LocalFree", SaberCheckerAPI::CK_FREE},
115 {"GlobalFree", SaberCheckerAPI::CK_FREE},
116 {"\01GlobalFree", SaberCheckerAPI::CK_FREE},
117 {"_free_dbg", SaberCheckerAPI::CK_FREE},
118 {"\01_free_dbg", SaberCheckerAPI::CK_FREE},
119 {"_aligned_free", SaberCheckerAPI::CK_FREE},
120 {"\01_aligned_free", SaberCheckerAPI::CK_FREE},
121
122 {"fopen", SaberCheckerAPI::CK_FOPEN},
123 {"\01_fopen", SaberCheckerAPI::CK_FOPEN},
124 {"\01fopen64", SaberCheckerAPI::CK_FOPEN},
125 {"\01readdir64", SaberCheckerAPI::CK_FOPEN},
126 {"\01tmpfile64", SaberCheckerAPI::CK_FOPEN},
127 {"fopen64", SaberCheckerAPI::CK_FOPEN},
128 {"XOpenDisplay", SaberCheckerAPI::CK_FOPEN},
129 {"XtOpenDisplay", SaberCheckerAPI::CK_FOPEN},
130 {"fopencookie", SaberCheckerAPI::CK_FOPEN},
131 {"popen", SaberCheckerAPI::CK_FOPEN},
132 {"readdir", SaberCheckerAPI::CK_FOPEN},
133 {"readdir64", SaberCheckerAPI::CK_FOPEN},
134 {"gzdopen", SaberCheckerAPI::CK_FOPEN},
135 {"iconv_open", SaberCheckerAPI::CK_FOPEN},
136 {"tmpfile", SaberCheckerAPI::CK_FOPEN},
137 {"tmpfile64", SaberCheckerAPI::CK_FOPEN},
138 {"BIO_new_socket", SaberCheckerAPI::CK_FOPEN},
139 {"gcry_md_open", SaberCheckerAPI::CK_FOPEN},
140 {"gcry_cipher_open", SaberCheckerAPI::CK_FOPEN},
141
142
143 {"fclose", SaberCheckerAPI::CK_FCLOSE},
144 {"XCloseDisplay", SaberCheckerAPI::CK_FCLOSE},
145 {"XtCloseDisplay", SaberCheckerAPI::CK_FCLOSE},
146 {"__res_nclose", SaberCheckerAPI::CK_FCLOSE},
147 {"pclose", SaberCheckerAPI::CK_FCLOSE},
148 {"closedir", SaberCheckerAPI::CK_FCLOSE},
149 {"dlclose", SaberCheckerAPI::CK_FCLOSE},
150 {"gzclose", SaberCheckerAPI::CK_FCLOSE},
151 {"iconv_close", SaberCheckerAPI::CK_FCLOSE},
152 {"gcry_md_close", SaberCheckerAPI::CK_FCLOSE},
153 {"gcry_cipher_close", SaberCheckerAPI::CK_FCLOSE},
154
155 //This must be the last entry.
157
158};
159
160
165{
168 t_seen.insert(CK_DUMMY);
169 for(const ei_pair *p= ei_pairs; p->n; ++p)
170 {
171 if(p->t != prev_t)
172 {
173 //This will detect if you move an entry to another block
174 // but forget to change the type.
175 if(t_seen.count(p->t))
176 {
177 fputs(p->n, stderr);
178 putc('\n', stderr);
179 assert(!"ei_pairs not grouped by type");
180 }
181 t_seen.insert(p->t);
182 prev_t= p->t;
183 }
184 if(tdAPIMap.count(p->n))
185 {
186 fputs(p->n, stderr);
187 putc('\n', stderr);
188 assert(!"duplicate name in ei_pairs");
189 }
190 tdAPIMap[p->n]= p->t;
191 }
192}
static const ei_pair ei_pairs[]
cJSON * p
Definition cJSON.cpp:2559
cJSON * n
Definition cJSON.cpp:2558
@ CK_FREE
memory allocation
@ CK_FOPEN
memory deallocation
static SaberCheckerAPI * ckAPI
Static reference.
void init()
Initialize the map.
TDAPIMap tdAPIMap
API map, from a string to threadAPI type.
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76