-
Notifications
You must be signed in to change notification settings - Fork 14
/
check_capable.c
124 lines (101 loc) · 3.33 KB
/
check_capable.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (C) 2014 Oracle.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
*/
#include "smatch.h"
#include "smatch_slist.h"
STATE(capable);
static int capable_id;
static int ns_capable_id;
static void match_capable(const char *fn, struct expression *expr, void *_param)
{
struct expression *arg;
sval_t sval;
char buf[32];
arg = get_argument_from_call_expr(expr->args, 0);
if (!get_implied_value(arg, &sval))
return;
snprintf(buf, sizeof(buf), "%s", sval_to_str(sval));
set_state(capable_id, buf, NULL, &capable);
}
static void match_ns_capable(const char *fn, struct expression *expr, void *_param)
{
struct expression *arg;
sval_t sval;
char buf[32];
if (get_function() && strcmp(get_function(), "capable") == 0)
return;
arg = get_argument_from_call_expr(expr->args, 1);
if (!get_implied_value(arg, &sval))
return;
snprintf(buf, sizeof(buf), "%s", sval_to_str(sval));
set_state(ns_capable_id, buf, NULL, &capable);
}
static void save_call_info(struct expression *call)
{
struct sm_state *sm;
FOR_EACH_MY_SM(capable_id, __get_cur_stree(), sm) {
if (sm->state == &capable)
sql_insert_caller_info(call, CAPABLE, 0, sm->name, "");
} END_FOR_EACH_SM(sm);
FOR_EACH_MY_SM(ns_capable_id, __get_cur_stree(), sm) {
if (sm->state == &capable)
sql_insert_caller_info(call, NS_CAPABLE, 0, sm->name, "");
} END_FOR_EACH_SM(sm);
}
static void save_return_info(int return_id, char *return_ranges, struct expression *expr)
{
struct sm_state *sm;
FOR_EACH_MY_SM(capable_id, __get_cur_stree(), sm) {
if (sm->state == &capable)
sql_insert_return_states(return_id, return_ranges,
CAPABLE, 0, sm->name, "");
} END_FOR_EACH_SM(sm);
FOR_EACH_MY_SM(ns_capable_id, __get_cur_stree(), sm) {
if (sm->state == &capable)
sql_insert_return_states(return_id, return_ranges,
CAPABLE, 0, sm->name, "");
} END_FOR_EACH_SM(sm);
}
static void set_db_capable(const char *name, struct symbol *sym, char *key, char *value)
{
char buf[32];
snprintf(buf, sizeof(buf), "%s", key);
set_state(capable_id, buf, NULL, &capable);
}
static void set_db_ns_capable(const char *name, struct symbol *sym, char *key, char *value)
{
char buf[32];
snprintf(buf, sizeof(buf), "%s", key);
set_state(ns_capable_id, buf, NULL, &capable);
}
void check_capable(int id)
{
if (option_project != PROJ_KERNEL)
return;
capable_id = id;
add_function_hook("capable", &match_capable, INT_PTR(0));
add_hook(&save_call_info, FUNCTION_CALL_HOOK);
add_split_return_callback(save_return_info);
select_caller_info_hook(set_db_capable, CAPABLE);
}
void check_ns_capable(int id)
{
if (option_project != PROJ_KERNEL)
return;
ns_capable_id = id;
add_function_hook("ns_capable", &match_ns_capable, INT_PTR(0));
select_caller_info_hook(set_db_ns_capable, NS_CAPABLE);
}