File tree Expand file tree Collapse file tree
cpp/ql/src/Likely Bugs/Memory Management Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313import cpp
1414import semmle.code.cpp.commons.Buffer
1515
16- abstract class PotentiallyDangerousFunctionCall extends FunctionCall {
17- abstract predicate isDangerous ( ) ;
18- abstract string getDescription ( ) ;
19- }
20-
21- class SprintfCall extends PotentiallyDangerousFunctionCall {
16+ class SprintfCall extends FunctionCall {
2217 SprintfCall ( ) {
2318 this .getTarget ( ) .hasName ( "sprintf" ) or this .getTarget ( ) .hasName ( "vsprintf" )
2419 }
@@ -31,16 +26,16 @@ class SprintfCall extends PotentiallyDangerousFunctionCall {
3126 result = this .getArgument ( 1 ) .( FormatLiteral ) .getMaxConvertedLength ( )
3227 }
3328
34- override predicate isDangerous ( ) {
29+ predicate isDangerous ( ) {
3530 this .getMaxConvertedLength ( ) > this .getBufferSize ( )
3631 }
3732
38- override string getDescription ( ) {
33+ string getDescription ( ) {
3934 result = "This conversion may yield a string of length " + this .getMaxConvertedLength ( ) .toString ( ) +
4035 ", which exceeds the allocated buffer size of " + this .getBufferSize ( ) .toString ( )
4136 }
4237}
4338
44- from PotentiallyDangerousFunctionCall c
39+ from SprintfCall c
4540where c .isDangerous ( )
4641select c , c .getDescription ( )
You can’t perform that action at this time.
0 commit comments