Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/taint-CVE-2020-13143-1.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 static inline struct gadget_info *to_gadget_info(struct config_item *item)
10 {
11 return container_of(to_config_group(item), struct gadget_info, group);
12 }
13
14 static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
15 const char *page, size_t len)
16 {
17 struct gadget_info *gi = to_gadget_info(item);
18 char *name;
19 int ret;
20
21 #if 0
22 /* FIXME: this is the fix. */
23 if (strlen(page) < len)
24 return -EOVERFLOW;
25 #endif
26
27 name = kstrdup(page, GFP_KERNEL);
28 if (!name)
29 return -ENOMEM;
30 if (name[len - 1] == '\n') /* { dg-warning "use of attacker-controlled value 'len \[^\n\r\]+' as offset without upper-bounds checking" } */
31 name[len - 1] = '\0'; /* { dg-warning "use of attacker-controlled value 'len \[^\n\r\]+' as offset without upper-bounds checking" } */
32 /* [...snip...] */ \
33 }
34
35 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\\)\\)'" } */