Repository navigation
Commit a202452
authored
Fix #15123: clang import: reject AST nodes without the ext tokens the handlers read (#8948)
Follow-up to #8939. Several `createTokens` handlers call
`mExtTokens.back()`/`front()` or index relative to `size()` without
checking that the node line had any ext tokens, so a `--clang` dump line
with nothing after the node name (e.g. `` `-IntegerLiteral `` followed
by a space) reads out of bounds. The same happens for StringLiteral,
CharacterLiteral, CXXBoolLiteralExpr, LabelStmt, EnumDecl, DeclRefExpr
and others, for a VarDecl that only has an address
(`mExtTokens[typeIndex - 1]` with `typeIndex` 0), and for a FunctionDecl
ending in `prev` (dereferences `end()`).
The AstNode constructor now throws an AST internal error when the node
has no ext tokens, and `createTokensVarDecl` /
`createTokensFunctionDecl` throw the same error for the other two
shapes. An address-only FunctionDecl / CXXMethodDecl /
CXXConstructorDecl or EnumConstantDecl (`` `-FunctionDecl 0x1 ``) is
rejected as well: `getSpelling()` is empty there, `addtoken("")` adds
nothing and returns a null `back()`, so both handlers now check the
spelling before adding any token. Real clang dumps always carry the node
address, location, name and type, so they are unaffected (checked
`--clang` on the samples and a few lib files). `crash2` now expects the
internal error instead of silently producing no tokens. The size()-2
sites are guarded in #8939 and not touched here.1 parent 07254e9 commit a202452
2 files changed
Lines changed: 48 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
340 | 343 | | |
341 | 344 | | |
342 | 345 | | |
| |||
1052 | 1055 | | |
1053 | 1056 | | |
1054 | 1057 | | |
1055 | | - | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
1056 | 1062 | | |
1057 | 1063 | | |
1058 | 1064 | | |
| |||
1388 | 1394 | | |
1389 | 1395 | | |
1390 | 1396 | | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
1391 | 1401 | | |
1392 | 1402 | | |
1393 | 1403 | | |
| |||
1409 | 1419 | | |
1410 | 1420 | | |
1411 | 1421 | | |
1412 | | - | |
| 1422 | + | |
1413 | 1423 | | |
1414 | 1424 | | |
1415 | 1425 | | |
1416 | | - | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
1417 | 1430 | | |
1418 | 1431 | | |
1419 | 1432 | | |
| |||
1460 | 1473 | | |
1461 | 1474 | | |
1462 | 1475 | | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
1463 | 1479 | | |
1464 | 1480 | | |
1465 | 1481 | | |
| |||
1562 | 1578 | | |
1563 | 1579 | | |
1564 | 1580 | | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
1565 | 1584 | | |
1566 | 1585 | | |
1567 | 1586 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| |||
1421 | 1422 | | |
1422 | 1423 | | |
1423 | 1424 | | |
1424 | | - | |
| 1425 | + | |
1425 | 1426 | | |
1426 | 1427 | | |
1427 | 1428 | | |
| |||
1442 | 1443 | | |
1443 | 1444 | | |
1444 | 1445 | | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
1445 | 1469 | | |
1446 | 1470 | | |
1447 | 1471 | | |
0 commit comments