deref_check: check_deref: print both line numbers
[smatch.git] / check_proc_create.c
blob5f4f694ae01f126e818cb75c1fc3dec70923aff1
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},
20 };
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 long long val;
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, &val))
33 return;
34 if (!(val & S_IWOTH))
35 return;
36 arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].name_param);
37 name = get_variable_from_expr(arg_expr, NULL);
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));