Skip to main content

deflateinit2

API Overview

deflateInit2 is an API in zlib. This rule belongs to the api pair type. This rule is generated using ChatDetector.

Rule Description

tip

Parameter 1 of deflateInit2 must be released by calling deflateEnd, with the same object passed as the 1-th argument to deflateEnd

info
  • Tags: api pair
  • Parameter Index: 0
  • CWE Type: CWE-404

Rule Code

import cpp
import semmle.code.cpp.dataflow.new.DataFlow


DataFlow::Node getSource(FunctionCall fc){
fc.getTarget().hasName("deflateInit2")
and result.asExpr() = fc.getArgument(0)
}

DataFlow::Node getSink(FunctionCall fc){
fc.getTarget().hasName("deflateEnd")
and result.asExpr() = fc.getArgument(0)
}

FunctionCall freeTarget(FunctionCall malloc){
DataFlow::localFlow(getSource(malloc), getSink(result))
}

from FunctionCall fc
where fc.getTarget().hasName("deflateInit2")
and not exists(
FunctionCall free|
free = freeTarget(fc)
)
select fc.getLocation()