@@ -82,22 +82,31 @@ class CallWithBufferSize extends FunctionCall
8282 Expr buffer ( ) {
8383 exists ( int i |
8484 bufferAndSizeFunction ( this .getTarget ( ) , i , _) and
85- result = this .getArgument ( i ) )
85+ result = this .getArgument ( i )
86+ )
8687 }
87- Expr statedSize ( ) {
88+ Expr statedSizeExpr ( ) {
8889 exists ( int i |
8990 bufferAndSizeFunction ( this .getTarget ( ) , _, i ) and
90- result = this .getArgument ( i ) )
91+ result = this .getArgument ( i )
92+ )
93+ }
94+ int statedSizeValue ( ) {
95+ exists ( Expr statedSizeSrc |
96+ DataFlow:: localFlowStep * ( DataFlow:: exprNode ( statedSizeSrc ) , DataFlow:: exprNode ( statedSizeExpr ( ) ) ) and
97+ result = statedSizeSrc .getValue ( ) .toInt ( )
98+ )
9199 }
92100}
93101
94102predicate wrongBufferSize ( Expr error , string msg ) {
95- exists ( CallWithBufferSize call , int bufsize , Variable buf |
103+ exists ( CallWithBufferSize call , int bufsize , Variable buf , int statedSize |
96104 staticBuffer ( call .buffer ( ) , buf , bufsize ) and
97- call .statedSize ( ) .getValue ( ) .toInt ( ) > bufsize and
98- error = call .statedSize ( ) and
105+ statedSize = call .statedSizeValue ( ) and
106+ statedSize > bufsize and
107+ error = call .statedSizeExpr ( ) and
99108 msg = "Potential buffer-overflow: '" + buf .getName ( ) +
100- "' has size " + bufsize .toString ( ) + " not " + call . statedSize ( ) . getValue ( ) + "." )
109+ "' has size " + bufsize .toString ( ) + " not " + statedSize + "." )
101110}
102111
103112predicate outOfBounds ( BufferAccess bufaccess , string msg )
0 commit comments