-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
OverrunWriteFloat.ql
35 lines (32 loc) · 1.21 KB
/
OverrunWriteFloat.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @name Potentially overrunning write with float to string conversion
* @description Buffer write operations that do not control the length
* of data written may overflow when floating point inputs
* take extreme values.
* @kind problem
* @problem.severity error
* @security-severity 9.3
* @precision medium
* @id cpp/overrunning-write-with-float
* @tags reliability
* security
* external/cwe/cwe-120
* external/cwe/cwe-787
* external/cwe/cwe-805
*/
import semmle.code.cpp.security.BufferWrite
/*
* See CWE-120/UnboundedWrite.ql for a summary of CWE-120 alert cases.
*/
from BufferWrite bw, int destSize, int estimated, BufferWriteEstimationReason reason
where
not bw.hasExplicitLimit() and
// has no explicit size limit
destSize = getBufferSize(bw.getDest(), _) and
estimated = bw.getMaxData(reason) and
estimated > destSize and
// and we can deduce that too much data may be copied
bw.getMaxDataLimited(reason) <= destSize // but it would fit without long '%f' conversions
select bw,
"This '" + bw.getBWDesc() + "' operation may require " + estimated +
" bytes because of float conversions, but the target is only " + destSize + " bytes."