The SAMATE Project Department of Homeland Security
Downloads:  Selected

Back to the previous page...Back to the previous page

Test Case IDCandidate16
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
ContributorSecureSoftware
LanguageC++
Type of test caseSource Code
Input stringN/A
Expected OutputN/A
InstructionsN/A
Submission date2005-10-21
DescriptioniconA buffer underwrite condition occurs when a buffer is indexed with a negative number, or pointer arithmetic with a negative value results in a position before the beginning of the valid memory location. (from TCCLASP-5_2_5_9)
Filename
Flaw
  • (?) CWE-119: Failure to Constrain Operations within the Bounds of an Allocated Memory Buffer at line 9

There is no comments :: Submit a comment :: RSS

>./Buffer_underwrite.cpp
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. char destBuf[1024],srcBuf[1024];
  7. string s1 = "This string is fair short.";
  8. srcBuf[0]='\0';
  9. strncpy(destBuf, &srcBuf[s1.find("abc")], 100);
  10.  
  11. }
  12.  
  13.  
  14.  
  15.