Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/copy_from_user-1.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fanalyzer" } */
3 /* { dg-require-effective-target analyzer } */
4
5 typedef __SIZE_TYPE__ size_t;
6
7 #define __user
8
9 extern int copy_from_user(void *to, const void __user *from, long n)
10 __attribute__((access (write_only, 1, 3),
11 access (read_only, 2, 3)
12 ));
13
14 #define EFAULT 14
15 #define EINVAL 22
16
17 /* Taken from Linux: fs/binfmt_misc.c (GPL-2.0-only). */
18
19 int parse_command(const char __user *buffer, size_t count)
20 {
21 char s[4];
22
23 if (count > 3)
24 return -EINVAL;
25 if (copy_from_user(s, buffer, count))
26 return -EFAULT;
27 if (!count)
28 return 0;
29 if (s[count - 1] == '\n') /* { dg-bogus "uninit" } */
30 count--;
31 if (count == 1 && s[0] == '0') /* { dg-bogus "uninit" } */
32 return 1;
33 if (count == 1 && s[0] == '1') /* { dg-bogus "uninit" } */
34 return 2;
35 if (count == 2 && s[0] == '-' && s[1] == '1') /* { dg-bogus "uninit" } */
36 return 3;
37 return -EINVAL;
38 }
39
40 /* Not using return value from copy_from_user. */
41
42 int test_2 (const char __user *buffer, size_t count)
43 {
44 char s[4];
45 if (count > 3)
46 return -EINVAL;
47 copy_from_user(s, buffer, count);
48 return 0;
49 }