Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c2cpg] Fix StackOverflowError within IncludeAutoDiscovery #5221

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package io.joern.c2cpg.utils

import io.joern.x2cpg.utils.ExternalCommand

import scala.util.{Failure, Success, Try}

object ExternalCommand {
object GccSpecificExternalCommand {

import io.joern.x2cpg.utils.ExternalCommand.ExternalCommandResult
import ExternalCommand.ExternalCommandResult

private val IsWin = scala.util.Properties.isWin

def run(command: Seq[String], cwd: String, extraEnv: Map[String, String] = Map.empty): Try[Seq[String]] = {
io.joern.x2cpg.utils.ExternalCommand.run(command, cwd, mergeStdErrInStdOut = true, extraEnv) match {
ExternalCommand.run(command, cwd, mergeStdErrInStdOut = true, extraEnv) match {
case ExternalCommandResult(0, stdOut, _) =>
Success(stdOut)
case ExternalCommandResult(1, stdOut, _) if IsWin && IncludeAutoDiscovery.gccAvailable() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.joern.c2cpg.utils

import better.files.File
import io.joern.c2cpg.Config
import io.joern.x2cpg.utils.ExternalCommand
import org.slf4j.LoggerFactory

import java.nio.file.Path
Expand Down Expand Up @@ -42,7 +43,7 @@ object IncludeAutoDiscovery {
private var systemIncludePathsCPP: mutable.LinkedHashSet[Path] = mutable.LinkedHashSet.empty

private def checkForGcc(): Boolean = {
ExternalCommand.run(GccVersionCommand, ".") match {
ExternalCommand.run(GccVersionCommand, ".").toTry match {
case Success(result) =>
logger.debug(s"GCC is available: ${result.mkString(System.lineSeparator())}")
true
Expand Down Expand Up @@ -70,15 +71,15 @@ object IncludeAutoDiscovery {
}

private def discoverPaths(command: Seq[String]): mutable.LinkedHashSet[Path] =
ExternalCommand.run(command, ".") match {
GccSpecificExternalCommand.run(command, ".") match {
case Success(output) => extractPaths(output)
case Failure(exception) =>
logger.warn(s"Unable to discover system include paths. Running '$command' failed.", exception)
mutable.LinkedHashSet.empty
}

private def discoverMSVCInstallPath(): Option[String] = {
ExternalCommand.run(VsWhereCommand, ".") match {
GccSpecificExternalCommand.run(VsWhereCommand, ".") match {
case Success(output) =>
output.headOption
case Failure(exception) =>
Expand All @@ -88,7 +89,7 @@ object IncludeAutoDiscovery {
}

private def extractMSVCIncludePaths(resolvedInstallationPath: String): mutable.LinkedHashSet[Path] = {
ExternalCommand.run(VcVarsCommand, resolvedInstallationPath, Map("VSCMD_DEBUG" -> "3")) match {
GccSpecificExternalCommand.run(VcVarsCommand, resolvedInstallationPath, Map("VSCMD_DEBUG" -> "3")) match {
case Success(results) =>
results.find(_.startsWith("INCLUDE=")) match {
case Some(includesLine) =>
Expand Down
Loading