user_data: make a function static
[smatch.git] / check_proc_create.c
blob494eafd52958e68f72db22b892ff47c66ab91103
1 /*
2 * sparse/check_proc_create.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static struct {
15 int name_param;
16 int mode_param;
17 } param_index[] = {
18 {.name_param = 0, .mode_param = 1},
19 {.name_param = 1, .mode_param = 2},
22 #define S_IWOTH 00002
24 static void match_create(const char *fn, struct expression *expr, void *_param_type)
26 struct expression *arg_expr;
27 sval_t sval;
28 char *name;
29 int idx = PTR_INT(_param_type);
31 arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].mode_param);
32 if (!get_implied_value(arg_expr, &sval))
33 return;
34 if (!(sval.uvalue & S_IWOTH))
35 return;
36 arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].name_param);
37 name = expr_to_var(arg_expr);
38 sm_msg("warn: proc file '%s' is world writable", name);
39 free_string(name);
42 void check_proc_create(int id)
44 my_id = id;
45 if (option_project != PROJ_KERNEL)
46 return;
48 add_function_hook("proc_create", &match_create, INT_PTR(0));
49 add_function_hook("create_proc_entry", &match_create, INT_PTR(0));
50 add_function_hook("proc_create_data", &match_create, INT_PTR(0));
51 add_function_hook("proc_net_fops_create", match_create, INT_PTR(1));