Skip to content

Commit

Permalink
[pysrc2cpg] Fixed Crashes on Import Code (#2245)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBakerEffendi authored Feb 5, 2023
1 parent 06dbca0 commit 7122dfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,11 @@ class ContextStack {

def isClassContext: Boolean = {
val stackTail = stack.tail
stackTail.nonEmpty &&
(stackTail.head.isInstanceOf[ClassContext] ||
stackTail.head.asInstanceOf[MethodContext].name.endsWith("<body>"))
stackTail.nonEmpty && (stackTail.headOption match {
case Some(_: ClassContext) => true
case Some(x: MethodContext) => x.name.endsWith("<body>")
case _ => false
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ class RecoverForPythonFile(cpg: Cpg, cu: File, builder: DiffGraphBuilder, global
if (!callCode.endsWith(")")) {
// Case 1: The identifier is at the assignment to a function pointer. Lack of parenthesis should indicate this.
setIdentifier(i, importedTypes)
} else if (callName.charAt(0).isUpper && callCode.endsWith(")")) {
} else if (!callName.isBlank && callName.charAt(0).isUpper && callCode.endsWith(")")) {
// Case 2: The identifier is receiving a constructor invocation, thus is now an instance of the type
setIdentifier(i, importedTypes.map(_.stripSuffix(s".${Defines.ConstructorMethodName}")))
} else {
// TODO: This identifier should contain the type of the return value of 'c'.
// e.g. x = foo(a, b) but not x = y.foo(a, b) as foo in the latter case is interpetted as a field access
// e.g. x = foo(a, b) but not x = y.foo(a, b) as foo in the latter case is interpreted as a field access
}
}

Expand Down

0 comments on commit 7122dfd

Please sign in to comment.