blob: 53c128a4fa1480ff7e20e423f4f80d6f0fa868db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode -Wno-stringop-overflow" } */
/* { dg-skip-if "" { powerpc-ibm-aix* } } */
#include <string.h>
void test (void)
{
char buf[10];
strcpy (buf, "foo");
strcat (buf, " bar");
strcat (buf, " baz!"); /* { dg-warning "stack-based buffer overflow" } */
}
/* { dg-begin-multiline-output "" }
┌────┬────┬────┐ ┌────┬────┬───────┐
│[0] │[1] │[2] │ │[3] │[4] │ [5] │
├────┼────┼────┤ ├────┼────┼───────┤
│' ' │'b' │'a' │ │'z' │'!' │ NUL │
├────┴────┴────┴─┴────┴────┴───────┤
│ string literal (type: 'char[6]') │
└──────────────────────────────────┘
│ │ │ │ │ │
│ │ │ │ │ │
v v v v v v
┌─────┬─────────────────────────────┬────┬────┬────┐ ┌─────────────────┐
│ [0] │ ... │[7] │... │[9] │ │ │
└─────┴────────┬────┬────┬────┬────┬┼────┼────┴────┘ │ │
│' ' │'b' │'a' │'r' ││NUL │ │after valid range│
┌──────────────┴────┴────┴────┴────┴┴────┴─────────┐ │ │
│ 'buf' (type: 'char[10]') │ │ │
└──────────────────────────────────────────────────┘ └─────────────────┘
├────────────────────────┬─────────────────────────┤ ├────────┬────────┤
│ │
╭─────────┴────────╮ ╭─────────┴─────────╮
│capacity: 10 bytes│ │overflow of 3 bytes│
╰──────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" { target c } } */
/* { dg-begin-multiline-output "" }
┌─────┬─────┬─────┐ ┌─────┬─────┬─────┐
│ [0] │ [1] │ [2] │ │ [3] │ [4] │ [5] │
├─────┼─────┼─────┤ ├─────┼─────┼─────┤
│ ' ' │ 'b' │ 'a' │ │ 'z' │ '!' │ NUL │
├─────┴─────┴─────┴──┴─────┴─────┴─────┤
│string literal (type: 'const char[6]')│
└──────────────────────────────────────┘
│ │ │ │ │ │
│ │ │ │ │ │
v v v v v v
┌────┬──────────────────────────┬─────┬─────┬─────┐ ┌─────────────────┐
│[0] │ ... │ [7] │ ... │ [9] │ │ │
└────┴───────┬────┬────┬───┬───┬┼─────┼─────┴─────┘ │ │
│' ' │'b' │'a'│'r'││ NUL │ │after valid range│
┌────────────┴────┴────┴───┴───┴┴─────┴───────────┐ │ │
│ 'char buf [10]' (type: 'char[10]') │ │ │
└─────────────────────────────────────────────────┘ └─────────────────┘
├────────────────────────┬────────────────────────┤ ├────────┬────────┤
│ │
╭─────────┴────────╮ ╭─────────┴─────────╮
│capacity: 10 bytes│ │overflow of 3 bytes│
╰──────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" { target c++ } } */
|