There are several consequences of disabling the warning:
(a) your code has been consistently giving the illusion that it is
working, but it is not actually working correctly; you just haven’t yet hit
the situation in which it will fail catastrophically
(b) your code is already seriously broken, but you never noticed because
the brokenness is harmless today. But don’t assume it will remain so.
Although (a) and (b) look the same, they are not; (a) says that you haven’t
yet experienced the situation that will do the damage that results in
catastrophe, and (b) says that it is already causing problems that have not
yet been noticed (the classic is copying a 4-character field into a
4-character buffer, and the NUL character overwrites the next variable,
which this week is always zero so the clobbering of its low-order byte is
harmless, but as soon as it is deployed, the user will do something that
uses a nonzero value and this bug will cause severe damage). Or another way
to say it, (a) says the damage is possible, but hasn’t happened yet and (b)
says the damage is already happening, but isn’t being noticed.
Ideally, you would want to use the STRING type and do all this using the
appropriate Rtl functions, which guarantee there can be no buffer overrun.
But if you use any function which does not check the size of the target
implicitly, you must make sure that you are checking the target size to make
sure there can be no buffer overrun. Sadly, many people assume that the
target is going to be big enough. This usually results in your driver
making the headlines, the kind that say “Virus takes over 300,000 machines
in an hour” and explains how everyone who has your product is vulnerable.
While free publicity is usually good, this kind isn’t.
What you can best do to fix it is not use strcpy in the kernel. Or strcat,
or sprintf. This would be a good start. strcpy was never safe (in fact,
when I started programming in C in 1975, I looked at these functions and
said “these are really stupid ideas” and wrote my own versions of strcpy_s,
strcat_s, and so on, and it only took the C world 30 more years to do the
same!). In some companies, using strcpy is considered a firable offense.
So using it is a habit you should definitely break. By the way, in many of
these situations, it doesn’t matter if you say “but I *do* check the buffer
size before using it!” because the simple presence of an unsafe string
operation is considered violation of program safety standards.
joe
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Sarbojit Sarkar
Sent: Monday, February 14, 2011 7:56 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] errors - warnings
If you want you can disable that particular type of warning and check if
things are working for you.
/sarbojit
On Mon, Feb 14, 2011 at 5:50 PM, wrote:
Hi all,
I have a compiling error, i couldnt see it compile window but prefast warned
me as;
driverentry.cpp(255) : warning 28719: Banned API Usage: strcpy is a Banned
API as listed in dontuse.h for security purposes.
Found in function ‘InitializeGenericExtension’
what can i do to fix it?
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by http:</http:> MailScanner, and is
believed to be clean.