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
81 {"VOS_MemFree", SaberCheckerAPI::CK_FREE},
82 {"cfree", SaberCheckerAPI::CK_FREE},
84 {"free_all_mem", SaberCheckerAPI::CK_FREE},
85 {"freeaddrinfo", SaberCheckerAPI::CK_FREE},
86 {"gcry_mpi_release", SaberCheckerAPI::CK_FREE},
87 {"gcry_sexp_release", SaberCheckerAPI::CK_FREE},
88 {"globfree", SaberCheckerAPI::CK_FREE},
89 {"nhfree", SaberCheckerAPI::CK_FREE},
90 {"obstack_free", SaberCheckerAPI::CK_FREE},
91 {"safe_cfree", SaberCheckerAPI::CK_FREE},
92 {"safe_free", SaberCheckerAPI::CK_FREE},
93 {"safefree", SaberCheckerAPI::CK_FREE},
94 {"safexfree", SaberCheckerAPI::CK_FREE},
95 {"sm_free", SaberCheckerAPI::CK_FREE},
96 {"vim_free", SaberCheckerAPI::CK_FREE},
97 {"xfree", SaberCheckerAPI::CK_FREE},
98 {"SSL_CTX_free", SaberCheckerAPI::CK_FREE},
99 {"SSL_free", SaberCheckerAPI::CK_FREE},
100 {"XFree", SaberCheckerAPI::CK_FREE},
101
102 {"fopen", SaberCheckerAPI::CK_FOPEN},
103 {"\01_fopen", SaberCheckerAPI::CK_FOPEN},
104 {"\01fopen64", SaberCheckerAPI::CK_FOPEN},
105 {"\01readdir64", SaberCheckerAPI::CK_FOPEN},
106 {"\01tmpfile64", SaberCheckerAPI::CK_FOPEN},
107 {"fopen64", SaberCheckerAPI::CK_FOPEN},
108 {"XOpenDisplay", SaberCheckerAPI::CK_FOPEN},
109 {"XtOpenDisplay", SaberCheckerAPI::CK_FOPEN},
110 {"fopencookie", SaberCheckerAPI::CK_FOPEN},
111 {"popen", SaberCheckerAPI::CK_FOPEN},
112 {"readdir", SaberCheckerAPI::CK_FOPEN},
113 {"readdir64", SaberCheckerAPI::CK_FOPEN},
114 {"gzdopen", SaberCheckerAPI::CK_FOPEN},
115 {"iconv_open", SaberCheckerAPI::CK_FOPEN},
116 {"tmpfile", SaberCheckerAPI::CK_FOPEN},
117 {"tmpfile64", SaberCheckerAPI::CK_FOPEN},
118 {"BIO_new_socket", SaberCheckerAPI::CK_FOPEN},
119 {"gcry_md_open", SaberCheckerAPI::CK_FOPEN},
120 {"gcry_cipher_open", SaberCheckerAPI::CK_FOPEN},
121
122
123 {"fclose", SaberCheckerAPI::CK_FCLOSE},
124 {"XCloseDisplay", SaberCheckerAPI::CK_FCLOSE},
125 {"XtCloseDisplay", SaberCheckerAPI::CK_FCLOSE},
126 {"__res_nclose", SaberCheckerAPI::CK_FCLOSE},
127 {"pclose", SaberCheckerAPI::CK_FCLOSE},
128 {"closedir", SaberCheckerAPI::CK_FCLOSE},
129 {"dlclose", SaberCheckerAPI::CK_FCLOSE},
130 {"gzclose", SaberCheckerAPI::CK_FCLOSE},
131 {"iconv_close", SaberCheckerAPI::CK_FCLOSE},
132 {"gcry_md_close", SaberCheckerAPI::CK_FCLOSE},
133 {"gcry_cipher_close", SaberCheckerAPI::CK_FCLOSE},
134
135 //This must be the last entry.
137
138};
139
140
145{
148 t_seen.insert(CK_DUMMY);
149 for(const ei_pair *p= ei_pairs; p->n; ++p)
150 {
151 if(p->t != prev_t)
152 {
153 //This will detect if you move an entry to another block
154 // but forget to change the type.
155 if(t_seen.count(p->t))
156 {
157 fputs(p->n, stderr);
158 putc('\n', stderr);
159 assert(!"ei_pairs not grouped by type");
160 }
161 t_seen.insert(p->t);
162 prev_t= p->t;
163 }
164 if(tdAPIMap.count(p->n))
165 {
166 fputs(p->n, stderr);
167 putc('\n', stderr);
168 assert(!"duplicate name in ei_pairs");
169 }
170 tdAPIMap[p->n]= p->t;
171 }
172}
173
174
175
176
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:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74