GCIH · Question #299
Which of the following functions in c/c++ can be the cause of buffer overflow? Each correct answer represents a complete solution. Choose two.
The correct answer is B. strcat() C. strcpy(). strcpy() and strcat() are unsafe C/C++ standard library functions that perform string operations without bounds checking, making them classic sources of buffer overflow vulnerabilities.
Question
Which of the following functions in c/c++ can be the cause of buffer overflow? Each correct answer represents a complete solution. Choose two.
Options
- Aprintf()
- Bstrcat()
- Cstrcpy()
- Dstrlength()
How the community answered
(66 responses)- A3% (2)
- B89% (59)
- D8% (5)
Why each option
strcpy() and strcat() are unsafe C/C++ standard library functions that perform string operations without bounds checking, making them classic sources of buffer overflow vulnerabilities.
printf() is primarily associated with format string vulnerabilities when user-controlled input is passed as the format argument, not with classic buffer overflow caused by unchecked memory writes.
strcat() appends a source string to a destination buffer without verifying that the destination has sufficient space to hold the result, allowing writes beyond the allocated buffer boundary.
strcpy() copies a source string into a destination buffer without checking the destination size, so if the source is longer than the allocated buffer, it will overwrite adjacent memory and cause a buffer overflow.
strlength() is not a valid C/C++ standard library function - the correct function is strlen() - and strlen() only reads string length without writing to any buffer, so it cannot cause a buffer overflow.
Concept tested: Unsafe C/C++ string functions causing buffer overflow
Source: https://owasp.org/www-community/vulnerabilities/Buffer_Overflow
Topics
Community Discussion
No community discussion yet for this question.