Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/taint-CVE-2020-13143-2.c

raw
1 /* See notes in this header. */
2 #include "taint-CVE-2020-13143.h"
3
4 struct configfs_attribute {
5 /* [...snip...] */
6 ssize_t (*store)(struct config_item *, const char *, size_t) /* { dg-message "\\(1\\) field 'store' of 'struct configfs_attribute' is marked with '__attribute__\\(\\(tainted_args\\)\\)'" } */
7 __attribute__((tainted_args)); /* (this is added). */
8 };
9
10 /* Highly simplified version. */
11
12 static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
13 const char *page, size_t len)
14 {
15 /* TODO: ought to have state_change_event talking about where the tainted value comes from. */
16
17 char *name;
18 /* [...snip...] */
19
20 name = kstrdup(page, GFP_KERNEL);
21 if (!name)
22 return -ENOMEM;
23 if (name[len - 1] == '\n') /* { dg-warning "use of attacker-controlled value 'len \[^\n\r\]+' as offset without upper-bounds checking" } */
24 name[len - 1] = '\0'; /* { dg-warning "use of attacker-controlled value 'len \[^\n\r\]+' as offset without upper-bounds checking" } */
25 /* [...snip...] */
26 return 0;
27 }
28
29 CONFIGFS_ATTR(gadget_dev_desc_, UDC); /* { dg-message "\\(2\\) function 'gadget_dev_desc_UDC_store' used as initializer for field 'store' marked with '__attribute__\\(\\(tainted_args\\)\\)'" } */