@@ -54,14 +54,19 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
5454 */
5555 private predicate isSVariant ( ) { this .getName ( ) .matches ( "%\\_s" ) }
5656
57+ /**
58+ * Holds if the function returns the total length the string would have had if the size was unlimited.
59+ */
60+ private predicate returnsTotalLength ( ) { this .getName ( ) = "strlcpy" }
61+
5762 /**
5863 * Gets the index of the parameter that is the maximum size of the copy (in characters).
5964 */
6065 int getParamSize ( ) {
6166 if this .isSVariant ( )
6267 then result = 1
6368 else (
64- this .getName ( ) .matches ( [ "%ncpy%" , "%nbcpy%" , "%xfrm%" , "%lcpy% " ] ) and
69+ this .getName ( ) .matches ( [ "%ncpy%" , "%nbcpy%" , "%xfrm%" , "strlcpy " ] ) and
6570 result = 2
6671 )
6772 }
@@ -101,6 +106,7 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
101106 input .isParameterDeref ( this .getParamSrc ( ) ) and
102107 output .isReturnValueDeref ( )
103108 or
109+ not this .returnsTotalLength ( ) and
104110 input .isParameter ( this .getParamDest ( ) ) and
105111 output .isReturnValue ( )
106112 }
@@ -111,8 +117,9 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
111117 exists ( this .getParamSize ( ) ) and
112118 input .isParameterDeref ( this .getParamSrc ( ) ) and
113119 (
114- output .isParameterDeref ( this .getParamDest ( ) ) or
115- output .isReturnValueDeref ( )
120+ output .isParameterDeref ( this .getParamDest ( ) )
121+ or
122+ not this .returnsTotalLength ( ) and output .isReturnValueDeref ( )
116123 )
117124 }
118125
0 commit comments