blob: b129518d759f7d9e71d3a8174cb67030b254bdb6 (
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
67
68
69
70
71
72
73
74
|
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
/* { dg-skip-if "" { powerpc-ibm-aix* } } */
#include <string.h>
#define LOREM_IPSUM \
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod" \
" tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" \
" veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" \
" commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" \
" velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" \
" occaecat cupidatat non proident, sunt in culpa qui officia deserunt" \
" mollit anim id est laborum."
void test (void)
{
char buf[500];
strcpy (buf, LOREM_IPSUM);
strcat (buf, LOREM_IPSUM); /* { dg-warning "stack-based buffer overflow" } */
}
/* { dg-begin-multiline-output "" }
┌─────┬───┬───┬───┬───┬───┬────────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ [0] │[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│
├─────┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤
│ 'L' │'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │
├─────┴───┴───┴───┴───┴───┴────────┴─────┴─────┴─────┴─────┴─────┴─────┤
│ string literal (type: 'char[446]') │
└──────────────────────────────────────────────────────────────────────┘
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
v v v v v v v v v v v v v v v
┌───┬────────────────────────────────────────────┬─────┬────────────────────┬─────┐┌────────────────────────────────────┐
│[0]│ ... │[445]│ ... │[499]││ │
├───┼───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬┼─────┼────────────────────┴─────┘│ │
│'L'│'o'│'r'│'e'│'m'│' '│...│'o'│'r'│'u'│'m'│'.'││ NUL │ │ after valid range │
├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴┴─────┴──────────────────────────┐│ │
│ 'buf' (type: 'char[500]') ││ │
└─────────────────────────────────────────────────────────────────────────────────┘└────────────────────────────────────┘
├────────────────────────────────────────┬────────────────────────────────────────┤├─────────────────┬──────────────────┤
│ │
╭─────────┴─────────╮ ╭──────────┴──────────╮
│capacity: 500 bytes│ │overflow of 391 bytes│
╰───────────────────╯ ╰─────────────────────╯
{ dg-end-multiline-output "" { target c } } */
/* { dg-begin-multiline-output "" }
┌─────┬───┬───┬───┬───┬───┬────────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ [0] │[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│
├─────┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤
│ 'L' │'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │
├─────┴───┴───┴───┴───┴───┴────────┴─────┴─────┴─────┴─────┴─────┴─────┤
│ string literal (type: 'const char[446]') │
└──────────────────────────────────────────────────────────────────────┘
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
v v v v v v v v v v v v v v v
┌───┬────────────────────────────────────────────┬─────┬────────────────────┬─────┐┌────────────────────────────────────┐
│[0]│ ... │[445]│ ... │[499]││ │
├───┼───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬┼─────┼────────────────────┴─────┘│ │
│'L'│'o'│'r'│'e'│'m'│' '│...│'o'│'r'│'u'│'m'│'.'││ NUL │ │ after valid range │
├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴┴─────┴──────────────────────────┐│ │
│ 'char buf [500]' (type: 'char[500]') ││ │
└─────────────────────────────────────────────────────────────────────────────────┘└────────────────────────────────────┘
├────────────────────────────────────────┬────────────────────────────────────────┤├─────────────────┬──────────────────┤
│ │
╭─────────┴─────────╮ ╭──────────┴──────────╮
│capacity: 500 bytes│ │overflow of 391 bytes│
╰───────────────────╯ ╰─────────────────────╯
{ dg-end-multiline-output "" { target c++ } } */
|