Question

Problem 4 (25 points). What will the following code print? Why? Identify the line where the vulnerability is. Explain the vulnerability. Show how the vulnerability can be eliminated Algorithm 2 Example vulnerability l.void called (int foo) 2. if (foo 1) printf(foo) 3. else printf(bar S.int main O 6. called(2): 7. return 0:)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code will print foo. This is because of the if statement in the function.

if(foo=1) here the statement is not making comparison but is doing assignment, assigning value 1 to foo. the statement will be aways true and if statement will be executed.

To solve this, make if statement as:

if(foo == 1)

Add a comment
Know the answer?
Add Answer to:
Problem 4 (25 points). What will the following code print? Why? Identify the line where the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT