All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joern.scanners.c.QueryLangExtensions.scala Maven / Gradle / Ivy

There is a newer version: 4.0.78
Show newest version
package io.joern.scanners.c

import io.shiftleft.codepropertygraph.generated.nodes
import io.shiftleft.semanticcpg.language.*

import scala.util.Try

object QueryLangExtensions {

  implicit class CallExtension(callTrav: Iterator[nodes.Call]) {
    def returnValueNotChecked: Iterator[nodes.Call] = {
      val notDirectlyChecked = callTrav.filterNot { y =>
        val code = y.code
        y.inAstMinusLeaf.isControlStructure.condition.code.exists { x =>
          x.contains(code)
        }
      }
      val notInCondition = notDirectlyChecked.filterNot { call =>
        val inConditions = call.method.controlStructure.condition.ast.l
        val checkedVars  = inConditions.isIdentifier.name.toSet ++ inConditions.isCall.code.toSet
        val targets      = call.inAssignment.target.code.toSet
        (targets & checkedVars).nonEmpty
      }
      notInCondition.whereNot { call =>
        call.inAstMinusLeaf.isReturn
      }
    }
  }

  implicit class LiteralExtension(litTrav: Iterator[nodes.Literal]) {

    def toInt: Iterator[Int] = {
      litTrav.code.flatMap { lit => Try(Integer.decode(lit).intValue()).toOption }
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy