buf_comparison: don't use assigned variable so much
[smatch.git] / smatch_buf_comparison.c
blob4f317784c8e3fc112b1ed355dae4f4125eca3c6b
1 /*
2 * Copyright (C) 2012 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * The point here is to store that a buffer has x bytes even if we don't know
20 * the value of x.
24 #include "smatch.h"
25 #include "smatch_extra.h"
26 #include "smatch_slist.h"
28 static int size_id;
29 static int link_id;
32 * There is a bunch of code which does this:
34 * if (size)
35 * foo = malloc(size);
37 * So if "size" is non-zero then the size of "foo" is size. But really it's
38 * also true if size is zero. It's just better to assume to not trample over
39 * the data that we have by merging &undefined states.
42 static struct smatch_state *unmatched_state(struct sm_state *sm)
44 return sm->state;
47 static struct smatch_state *merge_links(struct smatch_state *s1, struct smatch_state *s2)
49 struct expression *expr1, *expr2;
51 expr1 = s1->data;
52 expr2 = s2->data;
54 if (expr1 && expr2 && expr_equiv(expr1, expr2))
55 return s1;
56 return &merged;
59 static void match_link_modify(struct sm_state *sm, struct expression *mod_expr)
61 struct expression *expr;
62 struct sm_state *tmp;
64 expr = sm->state->data;
65 if (expr) {
66 set_state_expr(size_id, expr, &undefined);
67 set_state(link_id, sm->name, sm->sym, &undefined);
68 return;
71 FOR_EACH_PTR(sm->possible, tmp) {
72 expr = tmp->state->data;
73 if (expr)
74 set_state_expr(size_id, expr, &undefined);
75 } END_FOR_EACH_PTR(tmp);
76 set_state(link_id, sm->name, sm->sym, &undefined);
79 static const char *limit_map[] = {
80 "byte_count",
81 "elem_count",
82 "elem_last",
83 "used_count",
84 "used_last",
87 int state_to_limit(struct smatch_state *state)
89 int i;
91 if (!state || !state->data)
92 return -1;
94 for (i = 0; i < ARRAY_SIZE(limit_map); i++) {
95 if (strncmp(state->name, limit_map[i], strlen(limit_map[i])) == 0)
96 return i + BYTE_COUNT;
99 return -1;
102 const char *limit_type_str(unsigned int limit_type)
104 if (limit_type - BYTE_COUNT >= ARRAY_SIZE(limit_map)) {
105 sm_msg("internal: wrong size type %u", limit_type);
106 return "unknown";
109 return limit_map[limit_type - BYTE_COUNT];
112 static struct smatch_state *alloc_compare_size(int limit_type, struct expression *expr)
114 struct smatch_state *state;
115 char *name;
116 char buf[256];
118 state = __alloc_smatch_state(0);
119 expr = strip_expr(expr);
120 name = expr_to_str(expr);
121 snprintf(buf, sizeof(buf), "%s %s", limit_type_str(limit_type), name);
122 state->name = alloc_sname(buf);
123 free_string(name);
124 state->data = expr;
125 return state;
128 static int bytes_per_element(struct expression *expr)
130 struct symbol *type;
132 type = get_type(expr);
133 if (!type)
134 return 0;
136 if (type->type != SYM_PTR && type->type != SYM_ARRAY)
137 return 0;
139 type = get_base_type(type);
140 return type_bytes(type);
143 static void db_save_type_links(struct expression *array, int type_limit, struct expression *size)
145 const char *array_name;
147 array_name = get_data_info_name(array);
148 if (!array_name)
149 array_name = "";
150 sql_insert_data_info(size, type_limit, array_name);
153 static void match_alloc_helper(struct expression *pointer, struct expression *size)
155 struct smatch_state *state;
156 struct expression *tmp;
157 struct sm_state *sm;
158 int limit_type = ELEM_COUNT;
159 sval_t sval;
161 pointer = strip_expr(pointer);
162 size = strip_expr(size);
163 if (!size || !pointer)
164 return;
166 tmp = get_assigned_expr_recurse(size);
167 if (tmp && tmp->op == EXPR_BINOP)
168 size = strip_expr(tmp);
170 if (size->type == EXPR_BINOP && size->op == '*') {
171 struct expression *mult_left, *mult_right;
173 mult_left = strip_expr(size->left);
174 mult_right = strip_expr(size->right);
176 if (get_implied_value(mult_left, &sval) &&
177 sval.value == bytes_per_element(pointer))
178 size = mult_right;
179 else if (get_implied_value(mult_right, &sval) &&
180 sval.value == bytes_per_element(pointer))
181 size = mult_left;
182 else
183 return;
186 /* Only save links to variables, not fixed sizes */
187 if (get_value(size, &sval))
188 return;
190 if (size->type == EXPR_BINOP && size->op == '+' &&
191 get_value(size->right, &sval) && sval.value == 1) {
192 size = size->left;
193 limit_type = ELEM_LAST;
196 db_save_type_links(pointer, limit_type, size);
197 state = alloc_compare_size(limit_type, size);
198 sm = set_state_expr(size_id, pointer, state);
199 if (!sm)
200 return;
201 set_state_expr(link_id, size, alloc_state_expr(pointer));
204 static void match_alloc(const char *fn, struct expression *expr, void *_size_arg)
206 int size_arg = PTR_INT(_size_arg);
207 struct expression *pointer, *call, *arg;
209 pointer = strip_expr(expr->left);
210 call = strip_expr(expr->right);
211 arg = get_argument_from_call_expr(call->args, size_arg);
212 match_alloc_helper(pointer, arg);
215 static void match_calloc(const char *fn, struct expression *expr, void *_start_arg)
217 struct smatch_state *state;
218 int start_arg = PTR_INT(_start_arg);
219 struct expression *pointer, *call, *arg;
220 struct sm_state *tmp;
221 int limit_type = ELEM_COUNT;
222 sval_t sval;
224 pointer = strip_expr(expr->left);
225 call = strip_expr(expr->right);
226 arg = get_argument_from_call_expr(call->args, start_arg);
227 if (get_implied_value(arg, &sval) &&
228 sval.value == bytes_per_element(pointer))
229 arg = get_argument_from_call_expr(call->args, start_arg + 1);
231 if (arg->type == EXPR_BINOP && arg->op == '+' &&
232 get_value(arg->right, &sval) && sval.value == 1) {
233 arg = arg->left;
234 limit_type = ELEM_LAST;
237 state = alloc_compare_size(limit_type, arg);
238 db_save_type_links(pointer, limit_type, arg);
239 tmp = set_state_expr(size_id, pointer, state);
240 if (!tmp)
241 return;
242 set_state_expr(link_id, arg, alloc_state_expr(pointer));
245 static struct expression *get_size_variable_from_binop(struct expression *expr, int *limit_type)
247 struct smatch_state *state;
248 struct expression *ret;
249 struct symbol *type;
250 sval_t orig_fixed;
251 int offset_bytes;
252 sval_t offset;
254 if (!get_value(expr->right, &offset))
255 return NULL;
256 state = get_state_expr(size_id, expr->left);
257 if (!state || !state->data)
258 return NULL;
260 type = get_type(expr->left);
261 if (!type_is_ptr(type))
262 return NULL;
263 type = get_real_base_type(type);
264 if (!type_bytes(type))
265 return NULL;
266 offset_bytes = offset.value * type_bytes(type);
268 ret = state->data;
269 if (ret->type != EXPR_BINOP || ret->op != '+')
270 return NULL;
272 *limit_type = state_to_limit(state);
274 if (get_value(ret->left, &orig_fixed) && orig_fixed.value == offset_bytes)
275 return ret->right;
276 if (get_value(ret->right, &orig_fixed) && orig_fixed.value == offset_bytes)
277 return ret->left;
279 return NULL;
282 struct expression *get_size_variable(struct expression *buf, int *limit_type)
284 struct smatch_state *state;
285 struct expression *ret;
287 buf = strip_expr(buf);
288 if (!buf)
289 return NULL;
290 if (buf->type == EXPR_BINOP && buf->op == '+') {
291 ret = get_size_variable_from_binop(buf, limit_type);
292 if (ret)
293 return ret;
296 state = get_state_expr(size_id, buf);
297 if (!state)
298 return NULL;
299 *limit_type = state_to_limit(state);
300 return state->data;
303 struct expression *get_array_variable(struct expression *size)
305 struct smatch_state *state;
307 state = get_state_expr(link_id, size);
308 if (state)
309 return state->data;
310 return NULL;
313 static void array_check(struct expression *expr)
315 struct expression *array;
316 struct expression *size;
317 struct expression *offset;
318 char *array_str, *offset_str;
319 int limit_type;
321 expr = strip_expr(expr);
322 if (!is_array(expr))
323 return;
325 array = get_array_base(expr);
326 size = get_size_variable(array, &limit_type);
327 if (!size)
328 return;
329 if (limit_type != ELEM_COUNT)
330 return;
331 offset = get_array_offset(expr);
332 if (!possible_comparison(size, SPECIAL_EQUAL, offset))
333 return;
334 if (getting_address(expr))
335 return;
337 array_str = expr_to_str(array);
338 offset_str = expr_to_str(offset);
339 sm_warning("potentially one past the end of array '%s[%s]'", array_str, offset_str);
340 free_string(array_str);
341 free_string(offset_str);
344 struct db_info {
345 char *name;
346 int ret;
349 static int db_limitter_callback(void *_info, int argc, char **argv, char **azColName)
351 struct db_info *info = _info;
354 * If possible the limitters are tied to the struct they limit. If we
355 * aren't sure which struct they limit then we use them as limitters for
356 * everything.
358 if (!info->name || argv[0][0] == '\0' || strcmp(info->name, argv[0]) == 0)
359 info->ret = 1;
360 return 0;
363 static char *vsl_to_data_info_name(const char *name, struct var_sym_list *vsl)
365 struct var_sym *vs;
366 struct symbol *type;
367 static char buf[80];
368 const char *p;
370 if (ptr_list_size((struct ptr_list *)vsl) != 1)
371 return NULL;
372 vs = first_ptr_list((struct ptr_list *)vsl);
374 type = get_real_base_type(vs->sym);
375 if (!type || type->type != SYM_PTR)
376 goto top_level_name;
377 type = get_real_base_type(type);
378 if (!type || type->type != SYM_STRUCT)
379 goto top_level_name;
380 if (!type->ident)
381 goto top_level_name;
383 p = name;
384 while ((name = strstr(p, "->")))
385 p = name + 2;
387 snprintf(buf, sizeof(buf),"(struct %s)->%s", type->ident->name, p);
388 return alloc_sname(buf);
390 top_level_name:
391 if (!(vs->sym->ctype.modifiers & MOD_TOPLEVEL))
392 return NULL;
393 if (vs->sym->ctype.modifiers & MOD_STATIC)
394 snprintf(buf, sizeof(buf),"static %s", name);
395 else
396 snprintf(buf, sizeof(buf),"global %s", name);
397 return alloc_sname(buf);
400 int db_var_is_array_limit(struct expression *array, const char *name, struct var_sym_list *vsl)
402 char *size_name;
403 char *array_name = get_data_info_name(array);
404 struct db_info db_info = {.name = array_name,};
406 size_name = vsl_to_data_info_name(name, vsl);
407 if (!size_name)
408 return 0;
410 run_sql(db_limitter_callback, &db_info,
411 "select value from data_info where type = %d and data = '%s';",
412 ARRAY_LEN, size_name);
414 return db_info.ret;
417 int buf_comparison_index_ok(struct expression *expr)
419 struct expression *array;
420 struct expression *size;
421 struct expression *offset;
422 int limit_type;
423 int comparison;
425 array = get_array_base(expr);
426 size = get_size_variable(array, &limit_type);
427 if (!size)
428 return 0;
429 offset = get_array_offset(expr);
430 comparison = get_comparison(offset, size);
431 if (!comparison)
432 return 0;
434 if ((limit_type == ELEM_COUNT || limit_type == ELEM_LAST) &&
435 (comparison == '<' || comparison == SPECIAL_UNSIGNED_LT))
436 return 1;
437 if (limit_type == ELEM_LAST &&
438 (comparison == SPECIAL_LTE ||
439 comparison == SPECIAL_UNSIGNED_LTE ||
440 comparison == SPECIAL_EQUAL))
441 return 1;
443 return 0;
446 static int known_access_ok_numbers(struct expression *expr)
448 struct expression *array;
449 struct expression *offset;
450 sval_t max;
451 int size;
453 array = get_array_base(expr);
454 offset = get_array_offset(expr);
456 size = get_array_size(array);
457 if (size <= 0)
458 return 0;
460 get_absolute_max(offset, &max);
461 if (max.uvalue < size)
462 return 1;
463 return 0;
466 static void array_check_data_info(struct expression *expr)
468 struct expression *array;
469 struct expression *offset;
470 struct state_list *slist;
471 struct sm_state *sm;
472 struct compare_data *comp;
473 char *offset_name;
474 const char *equal_name = NULL;
476 expr = strip_expr(expr);
477 if (!is_array(expr))
478 return;
480 if (known_access_ok_numbers(expr))
481 return;
482 if (buf_comparison_index_ok(expr))
483 return;
485 array = get_array_base(expr);
486 offset = get_array_offset(expr);
487 offset_name = expr_to_var(offset);
488 if (!offset_name)
489 return;
490 slist = get_all_possible_equal_comparisons(offset);
491 if (!slist)
492 goto free;
494 FOR_EACH_PTR(slist, sm) {
495 comp = sm->state->data;
496 if (strcmp(comp->left_var, offset_name) == 0) {
497 if (db_var_is_array_limit(array, comp->right_var, comp->right_vsl)) {
498 equal_name = comp->right_var;
499 break;
501 } else if (strcmp(comp->right_var, offset_name) == 0) {
502 if (db_var_is_array_limit(array, comp->left_var, comp->left_vsl)) {
503 equal_name = comp->left_var;
504 break;
507 } END_FOR_EACH_PTR(sm);
509 if (equal_name) {
510 char *array_name = expr_to_str(array);
512 sm_warning("potential off by one '%s[]' limit '%s'", array_name, equal_name);
513 free_string(array_name);
516 free:
517 free_slist(&slist);
518 free_string(offset_name);
521 static void add_allocation_function(const char *func, void *call_back, int param)
523 add_function_assign_hook(func, call_back, INT_PTR(param));
526 static int is_sizeof(struct expression *expr)
528 const char *name;
530 if (expr->type == EXPR_SIZEOF)
531 return 1;
532 name = pos_ident(expr->pos);
533 if (name && strcmp(name, "sizeof") == 0)
534 return 1;
535 return 0;
538 static int match_size_binop(struct expression *size, struct expression *expr, int *limit_type)
540 int orig_type = *limit_type;
541 struct expression *left;
542 sval_t sval;
544 left = expr->left;
545 if (!expr_equiv(size, left))
546 return 0;
548 if (expr->op == '-' &&
549 get_value(expr->right, &sval) &&
550 sval.value == 1 &&
551 orig_type == ELEM_COUNT) {
552 *limit_type = ELEM_LAST;
553 return 1;
556 if (expr->op == '+' &&
557 get_value(expr->right, &sval) &&
558 sval.value == 1 &&
559 orig_type == ELEM_LAST) {
560 *limit_type = ELEM_COUNT;
561 return 1;
564 if (expr->op == '*' &&
565 is_sizeof(expr->right) &&
566 orig_type == ELEM_COUNT) {
567 *limit_type = BYTE_COUNT;
568 return 1;
571 if (expr->op == '/' &&
572 is_sizeof(expr->right) &&
573 orig_type == BYTE_COUNT) {
574 *limit_type = ELEM_COUNT;
575 return 1;
578 return 0;
581 static char *buf_size_param_comparison(struct expression *array, struct expression_list *args, int *limit_type)
583 struct expression *tmp, *arg;
584 struct expression *size;
585 static char buf[32];
586 int i;
588 size = get_size_variable(array, limit_type);
589 if (!size)
590 return NULL;
592 if (*limit_type == USED_LAST)
593 *limit_type = ELEM_LAST;
594 if (*limit_type == USED_COUNT)
595 *limit_type = ELEM_COUNT;
597 i = -1;
598 FOR_EACH_PTR(args, tmp) {
599 i++;
600 arg = tmp;
601 if (arg == array)
602 continue;
603 if (expr_equiv(arg, size) ||
604 (arg->type == EXPR_BINOP &&
605 match_size_binop(size, arg, limit_type))) {
606 snprintf(buf, sizeof(buf), "==$%d", i);
607 return buf;
609 } END_FOR_EACH_PTR(tmp);
611 return NULL;
614 static void match_call(struct expression *call)
616 struct expression *arg;
617 char *compare;
618 int param;
619 char buf[5];
620 int limit_type;
622 param = -1;
623 FOR_EACH_PTR(call->args, arg) {
624 param++;
625 if (!is_pointer(arg))
626 continue;
627 compare = buf_size_param_comparison(arg, call->args, &limit_type);
628 if (!compare)
629 continue;
630 snprintf(buf, sizeof(buf), "%d", limit_type);
631 sql_insert_caller_info(call, limit_type, param, compare, buf);
632 } END_FOR_EACH_PTR(arg);
635 static int get_param(int param, char **name, struct symbol **sym)
637 struct symbol *arg;
638 int i;
640 i = 0;
641 FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, arg) {
643 * this is a temporary hack to work around a bug (I think in sparse?)
644 * 2.6.37-rc1:fs/reiserfs/journal.o
645 * If there is a function definition without parameter name found
646 * after a function implementation then it causes a crash.
647 * int foo() {}
648 * int bar(char *);
650 if (arg->ident->name < (char *)100)
651 continue;
652 if (i == param) {
653 *name = arg->ident->name;
654 *sym = arg;
655 return TRUE;
657 i++;
658 } END_FOR_EACH_PTR(arg);
660 return FALSE;
663 static void set_param_compare(const char *array_name, struct symbol *array_sym, char *key, char *value)
665 struct smatch_state *state;
666 struct expression *array_expr;
667 struct expression *size_expr;
668 struct symbol *size_sym;
669 char *size_name;
670 long param;
671 struct sm_state *tmp;
672 int limit_type;
674 if (strncmp(key, "==$", 3) != 0)
675 return;
676 param = strtol(key + 3, NULL, 10);
677 if (!get_param(param, &size_name, &size_sym))
678 return;
679 array_expr = symbol_expression(array_sym);
680 size_expr = symbol_expression(size_sym);
681 limit_type = strtol(value, NULL, 10);
683 state = alloc_compare_size(limit_type, size_expr);
684 tmp = set_state_expr(size_id, array_expr, state);
685 if (!tmp)
686 return;
687 set_state_expr(link_id, size_expr, alloc_state_expr(array_expr));
690 static void set_implied(struct expression *call, struct expression *array_expr, char *key, char *value)
692 struct expression *size_expr;
693 struct symbol *size_sym;
694 char *size_name;
695 long param;
696 struct sm_state *tmp;
697 int limit_type;
699 if (strncmp(key, "==$", 3) != 0)
700 return;
701 param = strtol(key + 3, NULL, 10);
702 if (!get_param(param, &size_name, &size_sym))
703 return;
704 size_expr = symbol_expression(size_sym);
706 limit_type = strtol(value, NULL, 10);
707 tmp = set_state_expr(size_id, array_expr, alloc_compare_size(limit_type, size_expr));
708 if (!tmp)
709 return;
710 set_state_expr(link_id, size_expr, alloc_state_expr(array_expr));
713 static void munge_start_states(struct statement *stmt)
715 struct state_list *slist = NULL;
716 struct sm_state *sm;
717 struct sm_state *poss;
719 FOR_EACH_MY_SM(size_id, __get_cur_stree(), sm) {
720 if (sm->state != &merged)
721 continue;
723 * screw it. let's just assume that if one caller passes the
724 * size then they all do.
726 FOR_EACH_PTR(sm->possible, poss) {
727 if (poss->state != &merged &&
728 poss->state != &undefined) {
729 add_ptr_list(&slist, poss);
730 break;
732 } END_FOR_EACH_PTR(poss);
733 } END_FOR_EACH_SM(sm);
735 FOR_EACH_PTR(slist, sm) {
736 set_state(size_id, sm->name, sm->sym, sm->state);
737 } END_FOR_EACH_PTR(sm);
739 free_slist(&slist);
742 static void set_used(struct expression *expr)
744 struct expression *parent;
745 struct expression *array;
746 struct expression *offset;
747 struct sm_state *tmp;
748 int limit_type;
750 if (expr->op != SPECIAL_INCREMENT)
751 return;
753 limit_type = USED_LAST;
754 if (expr->type == EXPR_POSTOP)
755 limit_type = USED_COUNT;
757 parent = expr_get_parent_expr(expr);
758 if (!parent || parent->type != EXPR_BINOP)
759 return;
760 parent = expr_get_parent_expr(parent);
761 if (!parent || !is_array(parent))
762 return;
764 array = get_array_base(parent);
765 offset = get_array_offset(parent);
766 if (offset != expr)
767 return;
769 tmp = set_state_expr(size_id, array, alloc_compare_size(limit_type, offset->unop));
770 if (!tmp)
771 return;
772 set_state_expr(link_id, offset->unop, alloc_state_expr(array));
775 static int match_assign_array(struct expression *expr)
777 // FIXME: implement
778 return 0;
781 static int match_assign_size(struct expression *expr)
783 struct expression *right, *size, *array;
784 struct smatch_state *state;
785 struct sm_state *tmp;
786 int limit_type;
788 right = expr->right;
789 size = right;
790 if (size->type == EXPR_BINOP)
791 size = size->left;
793 array = get_array_variable(size);
794 if (!array)
795 return 0;
796 state = get_state_expr(size_id, array);
797 if (!state || !state->data)
798 return 0;
800 limit_type = state_to_limit(state);
801 if (limit_type < 0)
802 return 0;
804 if (right->type == EXPR_BINOP && !match_size_binop(size, right, &limit_type))
805 return 0;
807 tmp = set_state_expr(size_id, array, alloc_compare_size(limit_type, expr->left));
808 if (!tmp)
809 return 0;
810 set_state_expr(link_id, expr->left, alloc_state_expr(array));
811 return 1;
814 static void match_assign(struct expression *expr)
816 if (expr->op != '=')
817 return;
819 if (match_assign_array(expr))
820 return;
821 match_assign_size(expr);
824 static void match_copy(const char *fn, struct expression *expr, void *unused)
826 struct expression *src, *size;
827 int src_param, size_param;
829 src = get_argument_from_call_expr(expr->args, 1);
830 size = get_argument_from_call_expr(expr->args, 2);
831 src = strip_expr(src);
832 size = strip_expr(size);
833 if (!src || !size)
834 return;
835 if (src->type != EXPR_SYMBOL || size->type != EXPR_SYMBOL)
836 return;
838 src_param = get_param_num_from_sym(src->symbol);
839 size_param = get_param_num_from_sym(size->symbol);
840 if (src_param < 0 || size_param < 0)
841 return;
843 sql_insert_cache(call_implies, "'%s', '%s', 0, %d, %d, %d, '==$%d', '%d'",
844 get_base_file(), get_function(), fn_static(),
845 BYTE_COUNT, src_param, size_param, BYTE_COUNT);
848 void register_buf_comparison(int id)
850 int i;
852 size_id = id;
854 set_dynamic_states(size_id);
856 add_unmatched_state_hook(size_id, &unmatched_state);
858 add_allocation_function("malloc", &match_alloc, 0);
859 add_allocation_function("memdup", &match_alloc, 1);
860 add_allocation_function("realloc", &match_alloc, 1);
861 if (option_project == PROJ_KERNEL) {
862 add_allocation_function("kmalloc", &match_alloc, 0);
863 add_allocation_function("kzalloc", &match_alloc, 0);
864 add_allocation_function("vmalloc", &match_alloc, 0);
865 add_allocation_function("__vmalloc", &match_alloc, 0);
866 add_allocation_function("sock_kmalloc", &match_alloc, 1);
867 add_allocation_function("kmemdup", &match_alloc, 1);
868 add_allocation_function("memdup_user", &match_alloc, 1);
869 add_allocation_function("dma_alloc_attrs", &match_alloc, 1);
870 add_allocation_function("dma_alloc_coherent", &match_alloc, 1);
871 add_allocation_function("devm_kmalloc", &match_alloc, 1);
872 add_allocation_function("devm_kzalloc", &match_alloc, 1);
873 add_allocation_function("kcalloc", &match_calloc, 0);
874 add_allocation_function("devm_kcalloc", &match_calloc, 1);
875 add_allocation_function("kmalloc_array", &match_calloc, 0);
876 add_allocation_function("krealloc", &match_alloc, 1);
878 add_function_hook("copy_from_user", &match_copy, NULL);
879 add_function_hook("__copy_from_user", &match_copy, NULL);
882 add_hook(&array_check, OP_HOOK);
883 add_hook(&array_check_data_info, OP_HOOK);
884 add_hook(&set_used, OP_HOOK);
886 add_hook(&match_call, FUNCTION_CALL_HOOK);
887 add_hook(&munge_start_states, AFTER_DEF_HOOK);
889 add_hook(&match_assign, ASSIGNMENT_HOOK);
891 for (i = BYTE_COUNT; i <= USED_COUNT; i++) {
892 select_call_implies_hook(i, &set_implied);
893 select_caller_info_hook(set_param_compare, i);
894 select_return_implies_hook(i, &set_implied);
898 void register_buf_comparison_links(int id)
900 link_id = id;
901 set_dynamic_states(link_id);
902 add_merge_hook(link_id, &merge_links);
903 add_modification_hook(link_id, &match_link_modify);