
ARommel784014 (Community Member) asked a question.
Whilst scanning a big C++ application (took > 2 weeks), we got flaws (CWE-121 - stack-based buffer overflows) around _stprintf(). We changed it to _stprintf_s().
To verify our changes (whether the scanner will accept it), we built a small test application with old and new code lines.
A static scan of the small test applicatons shows NO flaws. Even lines like the following are accepted:
wchar_t shortbuf[ 12 ];
_stprintf( shortbuf, _T("%s"), L"String is too long for sure..." );
What's the reason for this? How can we rely on Veracodes "no-findings"?
.png)
Hi @ARommel784014 (Community Member) ,
Veracode Static Analysis focusses on finding security risks in the application.
As such, it requires that the input is manipulatable through some application input.
The input in the given example appears to be hardcoded.
Thank you,
Boy Baukema
OK, THX - that's what we thought in the meanwhile. We changed our test to the following - but got the same result: No message 😦
:
wchar_t shortbuf[ 12 ];
char answer[ 1024 ];
puts( "# of chars to build a string?" ); gets( answer );
_stprintf( shortbuf, _T("%s"), build_string( atoi( answer ) );
:
wchar_t *build_string( int count )
{
static wchar_t buf[ 1000 ];
for( int i = 0; i < count; i++ )
buf[i] = L'*';
buf[ count ] = 0;
return buf;
}
Hi @ARommel784014 (Community Member) ,
In this example the user input only indirectly causes the overflow, all with hardcoded characters. This too will not be reported by Veracode Static Analysis. Our analysis must see attacker data go into the destination buffer.
I would recommend using code from your application that is already reported by Veracode Static Analysis as our analysis is tuned for finding flaws in production code with a low false positive count.
Thank you,
Boy Baukema
THX again. Scanner seems to be more intelligent than me ;-)
Using code from our application is somewhat complicated and because we're in an evalutation phase of using Veracode on our own (and not only on request of a end-customer), we want to get familiar with its pros and cons.
The easiest way to get attacker data to a limited destination buffer might be
char shortbuf[ 12 ], answer[ 1024 ];
puts( "provide a large string: " ); gets_s( answer );
sprintf( shortbuf, "%s", answer );
But this is OK for Veraocde - in spite of runtime breaks within VisualStudio (Stack corrupted) and coding-time error-messages in Klocwork :-(. Can it be a false-negative?
Hi @ARommel784014 (Community Member) ,
I would recommend you contact our technical support team. Here's how you can log a case:
1. Navigate to the upper right corner of any page in the Community, click on your user avatar.
2. Select Contact Support from the drop-down menu.
In your case please mention:
Thank you,
Boy Baukema