2 * smatch/check_info_leak.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h"
18 static char *my_get_variable(struct expression
*expr
, struct symbol
**sym
)
22 name
= expr_to_var_sym(expr
, sym
);
27 return (*sym
)->ident
->name
;
30 static void match_kmalloc(const char *fn
, struct expression
*expr
, void *unused
)
35 name
= my_get_variable(expr
->left
, &sym
);
38 set_state(my_id
, name
, sym
, &alloced
);
41 static void match_strcpy(const char *fn
, struct expression
*expr
, void *unused
)
43 struct expression
*dest
;
47 dest
= get_argument_from_call_expr(expr
->args
, 0);
48 name
= my_get_variable(dest
, &sym
);
51 if (!get_state(my_id
, name
, sym
))
53 set_state(my_id
, name
, sym
, &string
);
56 static void match_copy_to_user(const char *fn
, struct expression
*expr
, void *unused
)
58 struct expression
*src
;
63 src
= get_argument_from_call_expr(expr
->args
, 1);
64 name
= my_get_variable(src
, &sym
);
67 sm
= get_sm_state(my_id
, name
, sym
);
68 if (!sm
|| !slist_has_state(sm
->possible
, &string
))
70 name
= expr_to_var(src
);
71 sm_msg("warn: possible info leak '%s'", name
);
75 void check_info_leak(int id
)
77 if (option_project
!= PROJ_KERNEL
)
80 add_function_assign_hook("kmalloc", &match_kmalloc
, NULL
);
81 add_function_hook("strcpy", &match_strcpy
, NULL
);
82 add_function_hook("strlcpy", &match_strcpy
, NULL
);
83 add_function_hook("strlcat", &match_strcpy
, NULL
);
84 add_function_hook("strncpy", &match_strcpy
, NULL
);
85 add_function_hook("copy_to_user", &match_copy_to_user
, NULL
);