Question
#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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started