Lint rules new in 1.66
Seventeen rules new in 1.66: eight research rules (OFF), the R4 rule reserve (DI, labels, RSA keys, IVs, cookies) and variant-record-punning (OFF).
Read this when a 1.66 lint run shows a rule id you have not seen, or to switch on one of the OFF research rules: each rule with its category, severity, default, CWE and what it reports.
How to run it
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule hardcoded-crypto-key
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule raise-in-except-without-inner
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule regex-redos-literal
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule double-checked-locking
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule stream-position-not-reset
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule task-captures-modified-local
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule oncalcfields-sets-datafield
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule onchange-assigns-own-control
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule nested-try-depth
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule unused-label
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule negated-condition-with-else
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule rsa-key-too-short
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule fixed-cipher-iv
Full flag list: lint in the CLI reference.
drag-lint lint <path> [--profile <name>] [--target-compiler <ver|auto>] [--rule <id>|help] [--disable id1,id2] [--rules-dir <dir>] [--json] [--labels] [--no-preprocess] [--library-db <lib.sqlite>] [--build-config <name>] [--no-budget]
Example:
drag-lint lint <file.pas> --rule cookie-without-secure
Full flag list: lint in the CLI reference.
drag-lint lint-all [--profile <name>] [--target-compiler <ver|auto>] [--db <file.sqlite>] [--project <.dproj>] [--build-config <name>] [--rule <id>[,<id>...]] [--disable id,...] [--output <report.txt>] [--json] [--labels] [--quiet] [--lint-third-party] [--no-preprocess] [--shared-db <db> ...] [--library-db none] [--no-budget] [--changed-since <rev>]
Example:
drag-lint lint-all --db <project.sqlite> --rule variant-record-punning
Full flag list: lint-all in the CLI reference.
Where to click
No IDE surface: this feature runs from the CLI (see How to run it).
Details
Seventeen rules arrived in 1.66. Every one is listed by drag-lint rules --json and explained by
drag-lint explain <rule-id>. Rules marked OFF run only when named (--rule <id>, --enable <id>, or
"enabled": [...] in the lint config).
drag-lint lint <unit.pas> --rule <id> per-file rules
drag-lint lint-all --db <project.sqlite> --rule <id> project-wide rules (and every per-file rule over the project)
Research rules -- all OFF
| rule | category | severity | CWE | what it reports |
|---|---|---|---|---|
hardcoded-crypto-key | security | warning | CWE-321 | a literal or const-literal key: HMAC key argument (THashSHA2 / MD5 / SHA1.GetHMAC), TDCP_* Init / InitStr, TIdHMAC*.Key := |
raise-in-except-without-inner | bug-patterns | hint | - | raise <ctor>(.. E.Message ..) inside on E: T do that drops E (use Exception.RaiseOuterException) |
regex-redos-literal | security | warning | CWE-1333 | a literal TRegEx / TPerlRegEx pattern with a nested unbounded quantifier (a+)+ or a repeated duplicate alternative (a|a)* |
double-checked-locking | bug-patterns | warning | CWE-609 | if F = nil then <lock>; if F = nil then F := ..Create on a field / global (CompareExchange and [volatile] exempt) |
stream-position-not-reset | bug-patterns | warning | - | a local TMemoryStream / TStringStream / TBytesStream written and then read without Position := / Seek / Clear |
task-captures-modified-local | bug-patterns | warning | CWE-362 | an anonymous method given to TTask / TThread.Queue / TParallel.For uses a local that is assigned after the dispatch |
oncalcfields-sets-datafield | firedac | warning | - | an OnCalcFields handler assigns a persistent data field (reads the .dfm beside the unit) |
onchange-assigns-own-control | bug-patterns | warning | - | an OnChange-style handler assigns its own control without a compare-first guard (reads the .dfm beside the unit) |
Fixtures with a hit and a non-hit for each: tests\fixtures\v166\rce1, tests\fixtures\v166\rce2
(runners tests\autotest\run_v166_RCE1.ps1, run_v166_RCE2.ps1). stream-position-not-reset has a manual-only,
risky fixer (lint --fix --fix-rule stream-position-not-reset).
Rule reserve
| rule | category | severity | default | scope | what it reports |
|---|---|---|---|---|---|
di-per-thread-in-task | dependency-injection | warning | ON | project | a Resolve of a singleton-per-thread interface inside a TTask.Run / Future / CreateAnonymousThread / TParallel.For closure |
di-registered-never-resolved | dependency-injection | hint | OFF | project | a registration nothing resolves or injects (silent with a generic Resolve<I>) |
nested-try-depth | complexity | hint | OFF | file | the 4th nested try |
unused-label | dead-code | hint | ON | file | a label no goto jumps to |
negated-condition-with-else | style | hint | OFF | file | if not X then A else B with one plain negation and a non-if else |
rsa-key-too-short | security | warning | ON | file | an RSA key size below 2048 (CWE-326) |
fixed-cipher-iv | security | warning | ON | file | a constant initialisation vector (CWE-329) |
cookie-without-secure | security | warning | ON | file | a cookie created without Secure / HttpOnly (CWE-614, CWE-1004) |
The two DI rules are also on the di-container-rules page. Runner:
tests\autotest\run_v166_R4_rules.ps1. Measured on copies of the ORM3 SERVER / CLIENT indexes: the ON rules found 0.
Variant records
| rule | category | severity | default | what it reports |
|---|---|---|---|---|
variant-record-punning | bug-patterns | warning | OFF | a variant-part field read through the receiver that last wrote another branch of the same variant part (CWE-843) |
Details: v166-variant-record-punning.