10.5k views
0 votes
The strcpy function performs no bounds checking on the first argument.
A. True
B. False

User How Chen
by
8.1k points

1 Answer

6 votes

Final answer:

The strcpy function indeed performs no bounds checking on the destination buffer, which is true. Safer alternatives, like strncpy, are recommended to prevent buffer overflows.

Step-by-step explanation:

The student asked if it's true that the strcpy function performs no bounds checking on the first argument. The answer is A. True. The strcpy function in C does not check to make sure that the destination array can hold the data that is being copied to it. This is why using this function can potentially lead to buffer overflow exploits, as it might overwrite the end of the buffer if the source string is larger than the destination buffer.

To mitigate this issue, safer alternatives such as strncpy can be used. strncpy requires the size of the destination buffer to be specified, which can prevent buffer overflows by ensuring that no more characters are copied than the destination can hold. However, even strncpy has to be used carefully as it may not null-terminate the string if the buffer size is too low.

User Misiu
by
8.7k points