exam questions

Exam CS0-002 All Questions

View all questions & answers for the CS0-002 exam

Exam CS0-002 topic 1 question 18 discussion

Actual exam question from CompTIA's CS0-002
Question #: 18
Topic #: 1
[All CS0-002 Questions]

An internally developed file-monitoring system identified the following excerpt as causing a program to crash often: char filedata[100]; fp = fopen(`access.log`, `r`); srtcopy (filedata, fp); printf (`%s\n`, filedata);
Which of the following should a security analyst recommend to fix the issue?

  • A. Open the access.log file in read/write mode.
  • B. Replace the strcpy function.
  • C. Perform input sanitization.
  • D. Increase the size of the file data butter.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Abyad
Highly Voted 2 years, 6 months ago
B comptia study guide Use of insecure functions can make it much harder to secure code. Functions like strcpy, which don't have critical security features built in, can result in code that is easier for attackers to target. In fact, strcpy is the only specific function that the CySA+ objectives call out, likely because of how commonly it is used for buffer overflow attacks in applications written in C. strcpy allows data to be copied without caring whether the source is bigger than the destination. If this occurs, attackers can place arbitrary data in memory locations past the original destination, possibly allowing a buffer overflow attack to succeed.
upvoted 15 times
wico1337
2 years, 6 months ago
Sure, that fixes the security issue. But this isnt a question about security. Its a question about application crashing...
upvoted 2 times
ra774ra7
2 years, 4 months ago
The question clearly states security "Which of the following should a security analyst recommend to fix the issue?"
upvoted 4 times
...
...
2Fish
2 years, 1 month ago
Agree. 'strcpy' should be replaced with something like 'strncopy'. 'strncpy' is used to avoid buffer overflow issues that can arise when copying strings using functions like strcpy that do not have a parameter to specify the maximum number of characters to copy.
upvoted 1 times
...
...
AbdallaAM
Most Recent 1 year, 7 months ago
Selected Answer: B
**Incorrect Usage of `strcpy`**: The `strcpy` function is used to copy a string from one memory location to another. However, in this snippet, `fp` (a file pointer) is being passed as an argument to `strcpy`, which is incorrect. `strcpy` expects a character pointer as its source argument, not a file pointer. B.Replace the strcpy function: - This is a step in the right direction. Replacing `strcpy` with a function like `fgets` or `fread` would be more appropriate for reading data from a file.
upvoted 1 times
...
kiduuu
2 years, 2 months ago
Selected Answer: B
The code snippet provided shows that the program is reading data from the "access.log" file and then copying it into a buffer using the "strcpy" function. However, the size of the buffer is fixed at 100 bytes, which could cause a buffer overflow if the data in the file is larger than 100 bytes. This can lead to a crash or other security vulnerabilities. To fix this issue, the security analyst should recommend replacing the "strcpy" function with a safer alternative, such as "strncpy" or "memcpy," which take a size parameter to ensure that only a certain number of bytes are copied to the buffer. Additionally, the size of the buffer should be increased to accommodate larger files if necessary.
upvoted 2 times
...
Qongo
2 years, 2 months ago
I think Option B is correct. Increasing the size of the buffer may temporarily fix the symptom of the issue, but it does not address the underlying problem of a potential buffer overflow vulnerability.
upvoted 1 times
...
absabs
2 years, 3 months ago
Selected Answer: B
I taked from book; C and C++ contain built-in functions suchas strcpy that do not provide a default mechanism for checking if data will overwritethe boundaries of a buffer. So i going with B.
upvoted 1 times
...
encxorblood
2 years, 3 months ago
Selected Answer: B
The strncpy() function is insecure because if the NULL character is not available in the first n characters in the source string then the destination string will not be NULL terminated.
upvoted 1 times
...
smudder
2 years, 3 months ago
Selected Answer: C
C. Perform input sanitization. The issue with the code excerpt is that it is not properly handling user input, which can lead to a program crash if the access.log file contains unexpected or malicious data. Input sanitization is the process of ensuring that user input is valid and safe to use. This can involve checking for and removing invalid characters, validating the input against a known set of acceptable values, or implementing other techniques to ensure that the input is safe to use. By performing input sanitization, the security analyst can help to prevent the program from crashing due to unexpected or malicious input.
upvoted 2 times
...
jleonard_ddc
2 years, 3 months ago
Selected Answer: B
B for sure. But that's not just because every study guide says strcopy is bad. More importantly, it's about why. strcopy is bad because it's susceptible to buffer overflow. The hint that the program is crashing is implying it's because of "buffer overflow". A and D bot had me going at first, but are eliminated after further review for this reason: strcopy parameters are (dest, src) [https://www.tutorialspoint.com/c_standard_library/c_function_strcpy.htm] So for this question src = fp (the access.log file) dest = the filedata array This means the file buffer is irrelevant, as are the permissions. The array is too small - that's why the buffer is having issues. But that's not the file buffer but the string buffer. Input sanitization is not even related to the discussion.
upvoted 3 times
...
david124
2 years, 3 months ago
Selected Answer: B
B is correct
upvoted 1 times
...
CyberNoob404
2 years, 4 months ago
Selected Answer: B
Sybex Study Guide & Sybex 1000 Practice Exam Books: "The CySA+ exam objectives mention strcpy, so you should be sure you know why it is a concern. Outside of the exam, we suggest reading more about buffer overflows instead of just knowing about strcpy." "The strcpy() function is notorious for leading to buffer overflow vulnerabilities and must be used very carefully." Only choosing B because it's covered in the objectives so much.
upvoted 1 times
...
CyberNoob404
2 years, 4 months ago
Selected Answer: B
I choose B based on Exam Objectives
upvoted 1 times
...
trainingsmits
2 years, 4 months ago
Selected Answer: B
strcpy is an insecure code function specifically called out in the comptia study guides
upvoted 2 times
...
trojan123
2 years, 5 months ago
Selected Answer: D
D. Although there are some alternatives to some of these functions advertised as safe, those functions may themselves be vulnerable to other types of attacks. The strncpy() function, for example, is said to be a safer version of strcpy(), because it enables a maximum size to be specified. However, the strncpy() function doesn’t null terminate the destination if the buffer is completely filled, which may lead to stability problems in code. As a security analyst, it’s important that you not take alternative recommendations for granted. Doing so can give you a false sense of security and may introduce additional vulnerabilities. Proposing other functions can lead to a different issues, to fix this one we can increase the buffer.
upvoted 1 times
...
trojan123
2 years, 5 months ago
Selected Answer: B
According to written code data copies from access.log to array, even if you will increase the size of the buffer, you never know the size of access.log, next time it might be bigger than your new buffer value, such vulnerable functions like strcpy should be avoided to use. The answers are tricky, of course increasing of the buffer can help, but this is not the best solution.
upvoted 1 times
trojan123
2 years, 5 months ago
Changing my answer to D. Although there are some alternatives to some of these functions advertised as safe, those functions may themselves be vulnerable to other types of attacks. The strncpy() function, for example, is said to be a safer version of strcpy(), because it enables a maximum size to be specified. However, the strncpy() function doesn’t null terminate the destination if the buffer is completely filled, which may lead to stability problems in code. As a security analyst, it’s important that you not take alternative recommendations for granted. Doing so can give you a false sense of security and may introduce additional vulnerabilities.
upvoted 1 times
...
...
Abyad
2 years, 6 months ago
Selected Answer: B
B is the correct answer
upvoted 2 times
Abyad
2 years, 6 months ago
strcpy is the only specific function that the CySA+ objectives call out
upvoted 3 times
...
...
SolventCourseisSCAM
2 years, 6 months ago
Selected Answer: D
buffer needs to be bigger than 100 bytes to not crash, so the answer should be D
upvoted 3 times
...
forklord72
2 years, 6 months ago
ignoring the typo, am I crazy for thinking D is the only viable answer? How does read/write access prevent a program from crashing? I think maybe it could be B but I have no idea what that even means.
upvoted 1 times
581777a
1 year, 6 months ago
yepppp
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago