GeezerVison is showing github.com — Use `getLocation` instead of `hasLocationInfo` · github/codeql@f322cb7
File treeExpand file treeCollapse file tree Open diff view settings CWE-522-DecompressionBombs
query-tests/Security/CWE-681
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/DiagnosticsReporting.qll +4-14Lines changed: 4 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,20 +19,10 @@ private class Diagnostic extends @diagnostic { | 19 | 19 | string getMessage() { diagnostics(this, _, _, result, _, _) } | 20 | 20 |
| 21 | 21 | /** Gets the file that this error is associated with, if any. */ | 22 | | - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } | | 22 | + File getFile() { result = this.getLocation().getFile() } | 23 | 23 |
| 24 | | - /** | 25 | | - * Holds if this element is at the specified location. | 26 | | - * The location spans column `startcolumn` of line `startline` to | 27 | | - * column `endcolumn` of line `endline` in file `filepath`. | 28 | | - * For more information, see | 29 | | - * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 30 | | - */ | 31 | | - predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) { | 32 | | - exists(Location loc | diagnostics(this, _, _, _, _, loc) | | 33 | | - loc.hasLocationInfo(path, sl, sc, el, ec) | 34 | | - ) | 35 | | - } | | 24 | + /** Gets the location for this error. */ | | 25 | + Location getLocation() { diagnostics(this, _, _, _, _, result) } | 36 | 26 |
| 37 | 27 | string toString() { result = this.getMessage() } | 38 | 28 | } | @@ -69,7 +59,7 @@ predicate reportableDiagnostics(Diagnostic d, string msg, int sev) { | 69 | 59 | exists(File f | f = d.getFile() | | 70 | 60 | exists(f.getAChild()) and | 71 | 61 | msg = | 72 | | - "Extraction failed in " + d.getFile().getRelativePath() + " with error " + | | 62 | + "Extraction failed in " + f.getRelativePath() + " with error " + | 73 | 63 | removeAbsolutePaths(d.getMessage()) | 74 | 64 | ) | 75 | 65 | or | |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/Scopes.qll +26-22Lines changed: 26 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,36 +144,34 @@ class Entity extends @object { | 144 | 144 | /** Gets a textual representation of this entity. */ | 145 | 145 | string toString() { result = this.getName() } | 146 | 146 |
| 147 | | - private predicate hasRealLocationInfo( | 148 | | - string filepath, int startline, int startcolumn, int endline, int endcolumn | 149 | | - ) { | 150 | | - // take the location of the declaration if there is one | 151 | | - this.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or | 152 | | - any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable()) | 153 | | - .hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 147 | + /** Gets the location of this entity. */ | | 148 | + Location getLocation() { | | 149 | + result = this.getDeclaration().getLocation() | | 150 | + or | | 151 | + result = any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable()).getLocation() | 154 | 152 | } | 155 | 153 |
| 156 | 154 | /** | | 155 | + * DEPRECATED: Use `getLocation()` instead. | | 156 | + * | 157 | 157 | * Holds if this element is at the specified location. | 158 | 158 | * The location spans column `startcolumn` of line `startline` to | 159 | 159 | * column `endcolumn` of line `endline` in file `filepath`. | 160 | 160 | * For more information, see | 161 | 161 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 162 | 162 | */ | 163 | | - predicate hasLocationInfo( | | 163 | + deprecated predicate hasLocationInfo( | 164 | 164 | string filepath, int startline, int startcolumn, int endline, int endcolumn | 165 | 165 | ) { | 166 | | - // take the location of the declaration if there is one | 167 | | - if this.hasRealLocationInfo(_, _, _, _, _) | 168 | | - then this.hasRealLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 169 | | - else ( | 170 | | - // otherwise fall back on dummy location | 171 | | - filepath = "" and | 172 | | - startline = 0 and | 173 | | - startcolumn = 0 and | 174 | | - endline = 0 and | 175 | | - endcolumn = 0 | 176 | | - ) | | 166 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 167 | + or | | 168 | + // otherwise fall back on dummy location | | 169 | + not exists(this.getLocation()) and | | 170 | + filepath = "" and | | 171 | + startline = 0 and | | 172 | + startcolumn = 0 and | | 173 | + endline = 0 and | | 174 | + endcolumn = 0 | 177 | 175 | } | 178 | 176 | } | 179 | 177 |
| @@ -680,16 +678,22 @@ class Callable extends TCallable { | 680 | 678 | result = this.asFuncLit().getName() | 681 | 679 | } | 682 | 680 |
| | 681 | + /** Gets the location of this callable. */ | | 682 | + Location getLocation() { | | 683 | + result = this.asFunction().getLocation() or result = this.asFuncLit().getLocation() | | 684 | + } | | 685 | + | 683 | 686 | /** | | 687 | + * DEPRECATED: Use `getLocation()` instead. | | 688 | + * | 684 | 689 | * Holds if this element is at the specified location. | 685 | 690 | * The location spans column `sc` of line `sl` to | 686 | 691 | * column `ec` of line `el` in file `fp`. | 687 | 692 | * For more information, see | 688 | 693 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 689 | 694 | */ | 690 | | - predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { | 691 | | - this.asFunction().hasLocationInfo(fp, sl, sc, el, ec) or | 692 | | - this.asFuncLit().hasLocationInfo(fp, sl, sc, el, ec) | | 695 | + deprecated predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { | | 696 | + this.getLocation().hasLocationInfo(fp, sl, sc, el, ec) | 693 | 697 | } | 694 | 698 | } | 695 | 699 |
| |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/StringOps.qll +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -548,20 +548,25 @@ module StringOps { | 548 | 548 | else result = "concatenation element" | 549 | 549 | } | 550 | 550 |
| | 551 | + /** Gets the location of this element. */ | | 552 | + Location getLocation() { result = this.asNode().getLocation() } | | 553 | + | 551 | 554 | /** | | 555 | + * DEPRECATED: Use `getLocation()` instead. | | 556 | + * | 552 | 557 | * Holds if this element is at the specified location. | 553 | 558 | * The location spans column `startcolumn` of line `startline` to | 554 | 559 | * column `endcolumn` of line `endline` in file `filepath`. | 555 | 560 | * For more information, see | 556 | 561 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 557 | 562 | */ | 558 | | - predicate hasLocationInfo( | | 563 | + deprecated predicate hasLocationInfo( | 559 | 564 | string filepath, int startline, int startcolumn, int endline, int endcolumn | 560 | 565 | ) { | 561 | | - this.asNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 566 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 562 | 567 | or | 563 | 568 | // use dummy location for elements that don't have a corresponding node | 564 | | - not exists(this.asNode()) and | | 569 | + not exists(this.getLocation()) and | 565 | 570 | filepath = "" and | 566 | 571 | startline = 0 and | 567 | 572 | startcolumn = 0 and | |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/Types.qll +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,19 +144,24 @@ class Type extends @type { | 144 | 144 | */ | 145 | 145 | string toString() { result = this.getName() } | 146 | 146 |
| | 147 | + /** Gets the location of this type. */ | | 148 | + Location getLocation() { result = this.getEntity().getLocation() } | | 149 | + | 147 | 150 | /** | | 151 | + * DEPRECATED: Use `getLocation()` instead. | | 152 | + * | 148 | 153 | * Holds if this element is at the specified location. | 149 | 154 | * The location spans column `startcolumn` of line `startline` to | 150 | 155 | * column `endcolumn` of line `endline` in file `filepath`. | 151 | 156 | * For more information, see | 152 | 157 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 153 | 158 | */ | 154 | | - predicate hasLocationInfo( | | 159 | + deprecated predicate hasLocationInfo( | 155 | 160 | string filepath, int startline, int startcolumn, int endline, int endcolumn | 156 | 161 | ) { | 157 | | - this.getEntity().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 162 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 158 | 163 | or | 159 | | - not exists(this.getEntity()) and | | 164 | + not exists(this.getLocation()) and | 160 | 165 | filepath = "" and | 161 | 166 | startline = 0 and | 162 | 167 | startcolumn = 0 and | |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/VariableWithFields.qll +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,16 +183,21 @@ class VariableWithFields extends TVariableWithFields { | 183 | 183 | */ | 184 | 184 | string getElement() { this = TVariableElementStep(_, result) } | 185 | 185 |
| | 186 | + /** Gets the location of this variable with fields. */ | | 187 | + Location getLocation() { result = this.getBaseVariable().getLocation() } | | 188 | + | 186 | 189 | /** | | 190 | + * DEPRECATED: Use `getLocation()` instead. | | 191 | + * | 187 | 192 | * Holds if this element is at the specified location. | 188 | 193 | * The location spans column `startcolumn` of line `startline` to | 189 | 194 | * column `endcolumn` of line `endline` in file `filepath`. | 190 | 195 | * For more information, see | 191 | 196 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 192 | 197 | */ | 193 | | - predicate hasLocationInfo( | | 198 | + deprecated predicate hasLocationInfo( | 194 | 199 | string filepath, int startline, int startcolumn, int endline, int endcolumn | 195 | 200 | ) { | 196 | | - this.getBaseVariable().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 201 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 197 | 202 | } | 198 | 203 | } |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/controlflow/BasicBlocks.qll +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -114,17 +114,22 @@ class BasicBlock extends TControlFlowNode { | 114 | 114 | /** Gets a textual representation of this basic block. */ | 115 | 115 | string toString() { result = "basic block" } | 116 | 116 |
| | 117 | + /** Gets the source location for this element. */ | | 118 | + Location getLocation() { result = this.getFirstNode().getLocation() } | | 119 | + | 117 | 120 | /** | | 121 | + * DEPRECATED: Use `getLocation()` instead. | | 122 | + * | 118 | 123 | * Holds if this basic block is at the specified location. | 119 | 124 | * The location spans column `startcolumn` of line `startline` to | 120 | 125 | * column `endcolumn` of line `endline` in file `filepath`. | 121 | 126 | * For more information, see | 122 | 127 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 123 | 128 | */ | 124 | | - predicate hasLocationInfo( | | 129 | + deprecated predicate hasLocationInfo( | 125 | 130 | string filepath, int startline, int startcolumn, int endline, int endcolumn | 126 | 131 | ) { | 127 | | - this.getFirstNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 132 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 128 | 133 | } | 129 | 134 | } | 130 | 135 |
| |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll +11-7Lines changed: 11 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -77,23 +77,31 @@ module ControlFlow { | 77 | 77 | Root getRoot() { none() } | 78 | 78 |
| 79 | 79 | /** Gets the file to which this node belongs. */ | 80 | | - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } | | 80 | + File getFile() { result = this.getLocation().getFile() } | 81 | 81 |
| 82 | 82 | /** | 83 | 83 | * Gets a textual representation of this control flow node. | 84 | 84 | */ | 85 | 85 | string toString() { result = "control-flow node" } | 86 | 86 |
| | 87 | + /** Gets the source location for this element. */ | | 88 | + Location getLocation() { none() } | | 89 | + | 87 | 90 | /** | | 91 | + * DEPRECATED: Use `getLocation()` instead. | | 92 | + * | 88 | 93 | * Holds if this element is at the specified location. | 89 | 94 | * The location spans column `startcolumn` of line `startline` to | 90 | 95 | * column `endcolumn` of line `endline` in file `filepath`. | 91 | 96 | * For more information, see | 92 | 97 | * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). | 93 | 98 | */ | 94 | | - predicate hasLocationInfo( | | 99 | + deprecated predicate hasLocationInfo( | 95 | 100 | string filepath, int startline, int startcolumn, int endline, int endcolumn | 96 | 101 | ) { | | 102 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | | 103 | + or | | 104 | + not exists(this.getLocation()) and | 97 | 105 | filepath = "" and | 98 | 106 | startline = 0 and | 99 | 107 | startcolumn = 0 and | @@ -244,11 +252,7 @@ module ControlFlow { | 244 | 252 |
| 245 | 253 | override string toString() { result = cond + " is " + outcome } | 246 | 254 |
| 247 | | - override predicate hasLocationInfo( | 248 | | - string filepath, int startline, int startcolumn, int endline, int endcolumn | 249 | | - ) { | 250 | | - cond.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 251 | | - } | | 255 | + override Location getLocation() { result = cond.getLocation() } | 252 | 256 | } | 253 | 257 |
| 254 | 258 | /** | |
Collapse file Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll +3-15Lines changed: 3 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -418,11 +418,7 @@ class SkipNode extends ControlFlow::Node, MkSkipNode { | 418 | 418 |
| 419 | 419 | override string toString() { result = "skip" } | 420 | 420 |
| 421 | | - override predicate hasLocationInfo( | 422 | | - string filepath, int startline, int startcolumn, int endline, int endcolumn | 423 | | - ) { | 424 | | - skip.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 425 | | - } | | 421 | + override Location getLocation() { result = skip.getLocation() } | 426 | 422 | } | 427 | 423 |
| 428 | 424 | /** | @@ -437,11 +433,7 @@ class EntryNode extends ControlFlow::Node, MkEntryNode { | 437 | 433 |
| 438 | 434 | override string toString() { result = "entry" } | 439 | 435 |
| 440 | | - override predicate hasLocationInfo( | 441 | | - string filepath, int startline, int startcolumn, int endline, int endcolumn | 442 | | - ) { | 443 | | - root.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 444 | | - } | | 436 | + override Location getLocation() { result = root.getLocation() } | 445 | 437 | } | 446 | 438 |
| 447 | 439 | /** | @@ -456,11 +448,7 @@ class ExitNode extends ControlFlow::Node, MkExitNode { | 456 | 448 |
| 457 | 449 | override string toString() { result = "exit" } | 458 | 450 |
| 459 | | - override predicate hasLocationInfo( | 460 | | - string filepath, int startline, int startcolumn, int endline, int endcolumn | 461 | | - ) { | 462 | | - root.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | 463 | | - } | | 451 | + override Location getLocation() { result = root.getLocation() } | 464 | 452 | } | 465 | 453 |
| 466 | 454 | /** | |
|