Commit 2eb8a58
preprocessor: guard elseSeen/ifdepth against negative elsetracker
A malformed #if expression (e.g. '#if %%%') causes eval() to return
err=true. CPPif increments ifdepth and elsetracker but does not invoke
CPPelse, leaving the preprocessor tracking a phantom conditional block.
Subsequent excess #endif directives are consumed inside CPPelse: the
depth > 0 path at Pp.cpp:328 runs --ifdepth without any guard, driving
ifdepth negative. Once ifdepth < 0 the 'if (ifdepth == 0)' guard in
readCPPline is permanently bypassed (only catches exactly zero). Every
further #endif then executes elseSeen[elsetracker] = false with
elsetracker running arbitrarily negative, writing zero-bytes backward
through TPpContext into the lastLineTokenLocs vector control block,
corrupting its internal pointers and causing a deterministic SEGV.
Fix with three one-line guards:
- Pp.cpp:319 (CPPelse): check elsetracker >= 0 before writing elseSeen
- Pp.cpp:328 (CPPelse depth>0 path): check ifdepth > 0 before decrement
- Pp.cpp:1011 (readCPPline): check elsetracker >= 0 before writing elseSeen
Add test preprocessor.elseseen.oob.vert that reproduces the crash path:
a bad #if desynchronises the counters, excess #endifs then drive
elsetracker to -10. With the fix all excess #endifs produce
'mismatched statements' errors cleanly; without it the process crashes.1 parent a899a43 commit 2eb8a58
5 files changed
Lines changed: 64 additions & 3 deletions
File tree
- Test
- baseResults
- glslang/MachineIndependent/preprocessor
- gtests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
| 319 | + | |
| 320 | + | |
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
| |||
325 | 326 | | |
326 | 327 | | |
327 | 328 | | |
328 | | - | |
| 329 | + | |
| 330 | + | |
329 | 331 | | |
330 | 332 | | |
331 | 333 | | |
| |||
1008 | 1010 | | |
1009 | 1011 | | |
1010 | 1012 | | |
1011 | | - | |
| 1013 | + | |
| 1014 | + | |
1012 | 1015 | | |
1013 | 1016 | | |
1014 | 1017 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
0 commit comments