Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.

Commit f84df0b

Browse files
authored
Create file.sc
Create a Joern query for File.
1 parent 6523919 commit f84df0b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Tools/Joern_Queries/file.sc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This script detects whether arguments of memcpy were validated using comparison operators
2+
// before the actual call to memcpy.
3+
4+
importCpg("cpg.bin")
5+
6+
// Step 1: Get all arguments passed to memcpy
7+
val memcpyArgs = cpg.call.name("memcpy").argument.reachableBy(cpg.identifier).toSet
8+
9+
// Step 2: Look for comparison calls like <, >, <=, >=
10+
val comparisonCalls = cpg.call.name(".*less.*", ".*greater.*", ".*equals.*").argument.reachableBy(memcpyArgs).toSet
11+
12+
// Step 3: Check if any of the same identifiers are used in both memcpy and in comparisons
13+
val validatedInputs = memcpyArgs.intersect(comparisonCalls).asInstanceOf[Set[Call]]
14+
15+
// Step 4: Report them — show what was checked
16+
validatedInputs.foreach { call =>
17+
println(s"Possibly validated input before memcpy: '${call.code}' at line ${call.lineNumber.getOrElse("?" )}")
18+
}

0 commit comments

Comments
 (0)