Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #define BUFFER_LENGTH 512 /* * Week 3 Lab 2 * * This program allows for input of formatted output * characters on

#include

#include

#include

#define BUFFER_LENGTH 512

/* * Week 3 Lab 2 * * This program allows for input of formatted output * characters on the command line (such as %x and %s), * and is therefore vulnerable to a formatted output * exploit.

*/int main (int argc, char **argv)

{

char buffer[BUFFER_LENGTH + 1] = {0};

if (argc < 2)

{

printf ("Invalid number of arguments. ");

return -1;

}

if (strlen(argv[1]) > BUFFER_LENGTH)

{

printf ("Buffer length too long. ");

return -1;

}

/* * This program needs to be corrected to reject any

* input that contains formatted output characters.

*/

snprintf(buffer, sizeof(buffer), argv[1]);

buffer[BUFFER_LENGTH + 1] = '\0';

printf("You entered %s. ", buffer);

return 0;}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions