Skip to content

Commit 3307457

Browse files
committed
use implements predicate for io interfaces,
so we can reduce many repetitive parts of query
1 parent 13b0a9a commit 3307457

File tree

1 file changed

+7
-127
lines changed

1 file changed

+7
-127
lines changed

go/ql/src/experimental/frameworks/DecompressionBombsCustomizations.qll

Lines changed: 7 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ module DecompressionBombs {
7474
|
7575
this = m.getACall().getReceiver()
7676
)
77-
or
78-
exists(Method m, DataFlow::CallNode cn |
79-
m.hasQualifiedName("github.com/klauspost/compress/zstd", "Decoder", ["WriteTo", "Read"]) and
80-
cn = m.getACall()
81-
|
82-
this = cn.getReceiver() and
83-
not hasFlowToComparison(cn.getResult(0))
84-
)
8577
}
8678
}
8779

@@ -178,18 +170,6 @@ module DecompressionBombs {
178170
* Provides decompression bomb sinks and additional flow steps for `github.com/ulikunitz/xz` package
179171
*/
180172
module UlikunitzXz {
181-
class TheSink extends Sink {
182-
TheSink() {
183-
exists(Method m, DataFlow::CallNode cn |
184-
m.hasQualifiedName("github.com/ulikunitz/xz", "Reader", "Read") and
185-
cn = m.getACall()
186-
|
187-
this = cn.getReceiver() and
188-
not hasFlowToComparison(cn.getResult(0))
189-
)
190-
}
191-
}
192-
193173
class TheAdditionalTaintStep extends AdditionalTaintStep {
194174
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
195175

@@ -216,18 +196,6 @@ module DecompressionBombs {
216196
* Provides decompression bomb sinks and additional flow steps for `compress/gzip` package
217197
*/
218198
module CompressGzipBombs {
219-
class TheSink extends Sink {
220-
TheSink() {
221-
exists(Method m, DataFlow::CallNode cn |
222-
m.hasQualifiedName("compress/gzip", "Reader", "Read") and
223-
cn = m.getACall()
224-
|
225-
this = cn.getReceiver() and
226-
not hasFlowToComparison(cn.getResult(0))
227-
)
228-
}
229-
}
230-
231199
class TheAdditionalTaintStep extends AdditionalTaintStep {
232200
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
233201

@@ -255,19 +223,6 @@ module DecompressionBombs {
255223
* Provides decompression bomb sinks and additional flow steps for `github.com/klauspost/compress/gzip` package
256224
*/
257225
module KlauspostGzipAndPgzip {
258-
class TheSink extends Sink {
259-
TheSink() {
260-
exists(Method m, DataFlow::CallNode cn |
261-
m.hasQualifiedName(["github.com/klauspost/compress/gzip", "github.com/klauspost/pgzip"],
262-
"Reader", ["Read", "WriteTo"]) and
263-
cn = m.getACall()
264-
|
265-
this = cn.getReceiver() and
266-
not hasFlowToComparison(cn.getResult(0))
267-
)
268-
}
269-
}
270-
271226
class TheAdditionalTaintStep extends AdditionalTaintStep {
272227
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
273228

@@ -301,18 +256,6 @@ module DecompressionBombs {
301256
* Provides decompression bomb sinks and additional flow steps for `compress/bzip2` package
302257
*/
303258
module CompressBzip2 {
304-
class TheSink extends Sink {
305-
TheSink() {
306-
exists(Method m, DataFlow::CallNode cn |
307-
m.hasQualifiedName("compress/bzip2", "reader", "Read") and
308-
cn = m.getACall()
309-
|
310-
this = cn.getReceiver() and
311-
not hasFlowToComparison(cn.getResult(0))
312-
)
313-
}
314-
}
315-
316259
class TheAdditionalTaintStep extends AdditionalTaintStep {
317260
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
318261

@@ -340,18 +283,6 @@ module DecompressionBombs {
340283
* Provides decompression bomb sinks and additional flow steps for `github.com/dsnet/compress/bzip2` package
341284
*/
342285
module DsnetBzip2 {
343-
class TheSink extends Sink {
344-
TheSink() {
345-
exists(Method m, DataFlow::CallNode cn |
346-
m.hasQualifiedName("github.com/dsnet/compress/bzip2", "Reader", "Read") and
347-
cn = m.getACall()
348-
|
349-
this = cn.getReceiver() and
350-
not hasFlowToComparison(cn.getResult(0))
351-
)
352-
}
353-
}
354-
355286
class TheAdditionalTaintStep extends AdditionalTaintStep {
356287
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
357288

@@ -379,18 +310,6 @@ module DecompressionBombs {
379310
* Provides decompression bomb sinks and additional flow steps for `github.com/dsnet/compress/flate` package
380311
*/
381312
module DsnetFlate {
382-
class TheSink extends Sink {
383-
TheSink() {
384-
exists(Method m, DataFlow::CallNode cn |
385-
m.hasQualifiedName("github.com/dsnet/compress/flate", "Reader", "Read") and
386-
cn = m.getACall()
387-
|
388-
this = cn.getReceiver() and
389-
not hasFlowToComparison(cn.getResult(0))
390-
)
391-
}
392-
}
393-
394313
class TheAdditionalTaintStep extends AdditionalTaintStep {
395314
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
396315

@@ -496,18 +415,6 @@ module DecompressionBombs {
496415
* Provides decompression bomb sinks and additional flow steps for `github.com/klauspost/compress/zlib` package
497416
*/
498417
module KlauspostZlib {
499-
class TheSink extends Sink {
500-
TheSink() {
501-
exists(Method m, DataFlow::CallNode cn |
502-
m.hasQualifiedName("github.com/klauspost/compress/zlib", "reader", "Read") and
503-
cn = m.getACall()
504-
|
505-
this = cn.getReceiver() and
506-
not hasFlowToComparison(cn.getResult(0))
507-
)
508-
}
509-
}
510-
511418
class TheAdditionalTaintStep extends AdditionalTaintStep {
512419
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
513420

@@ -535,18 +442,6 @@ module DecompressionBombs {
535442
* Provides decompression bomb sinks and additional flow steps for `compress/zlib` package
536443
*/
537444
module CompressZlibBombs {
538-
class TheSink extends Sink {
539-
TheSink() {
540-
exists(Method m, DataFlow::CallNode cn |
541-
m.hasQualifiedName("compress/zlib", "reader", "Read") and
542-
cn = m.getACall()
543-
|
544-
this = cn.getReceiver() and
545-
not hasFlowToComparison(cn.getResult(0))
546-
)
547-
}
548-
}
549-
550445
class TheAdditionalTaintStep extends AdditionalTaintStep {
551446
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
552447

@@ -574,18 +469,6 @@ module DecompressionBombs {
574469
* Provides decompression bomb sinks and additional flow steps for `github.com/golang/snappy` package
575470
*/
576471
module GolangSnappy {
577-
class TheSink extends Sink {
578-
TheSink() {
579-
exists(Method m, DataFlow::CallNode cn |
580-
m.hasQualifiedName("github.com/golang/snappy", "Reader", ["Read", "ReadByte"]) and
581-
cn = m.getACall()
582-
|
583-
this = cn.getReceiver() and
584-
not hasFlowToComparison(cn.getResult(0))
585-
)
586-
}
587-
}
588-
589472
class TheAdditionalTaintStep extends AdditionalTaintStep {
590473
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
591474

@@ -643,8 +526,7 @@ module DecompressionBombs {
643526
class TheSink extends Sink {
644527
TheSink() {
645528
exists(Method m, DataFlow::CallNode cn |
646-
m.hasQualifiedName("github.com/klauspost/compress/s2", "Reader",
647-
["DecodeConcurrent", "ReadByte", "Read"]) and
529+
m.hasQualifiedName("github.com/klauspost/compress/s2", "Reader", "DecodeConcurrent") and
648530
cn = m.getACall()
649531
|
650532
this = cn.getReceiver() and
@@ -690,14 +572,12 @@ module DecompressionBombs {
690572
)
691573
or
692574
exists(Method m, DataFlow::CallNode cn |
693-
m.hasQualifiedName("io", "Reader", "Read") and cn = m.getACall()
694-
|
695-
this = cn.getReceiver() and
696-
not hasFlowToComparison(cn.getResult(0))
697-
)
698-
or
699-
exists(Method m, DataFlow::CallNode cn |
700-
m.hasQualifiedName("archive/tar", "Reader", "Read") and cn = m.getACall()
575+
(
576+
m.implements("io", "Reader", "Read") or
577+
m.implements("io", "ByteReader", "ReadByte") or
578+
m.implements("io", "WriterTo", "WriteTo")
579+
) and
580+
cn = m.getACall()
701581
|
702582
this = cn.getReceiver() and
703583
not hasFlowToComparison(cn.getResult(0))

0 commit comments

Comments
 (0)