Question

What security flaw(s) might exist in the following C software? void chopUserInput( char *mon, char *day,...

What security flaw(s) might exist in the following C software? void chopUserInput( char *mon, char *day, char *input ) { char *m, *d; m = strtok( input, “/”); d = strtok( NULL, “/” ); strcpy( mon, m ); strcpy( day, d ); }

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

Code:

#include <stdio.h>

#include <string.h>

void chopUserInput( char *mon, char *day, char *input )

{

char *m, *d;

m = strtok(input,"/");

d = strtok(NULL,"/");

strcpy( mon, m );

strcpy( day, d );

}

int main()

{

char *input=NULL;

char mon[4],day[4];

printf("Enter date in mon/day format : ");

scanf("%s",input);

chopUserInput(mon,day,input);

printf("\nMonth name : %s",mon);

printf("\nDay name : %s",day);

return 0;

}

Explanation: In the above code “main()” is calling function and “chopUserInput()” is called function. The actual parameters passed from “main()” is “mon” and “day” are modified by sub function “chopUserInput()”. So that each modification in sub function is visible and accessible by calling function “main()”.

Add a comment
Know the answer?
Add Answer to:
What security flaw(s) might exist in the following C software? void chopUserInput( char *mon, char *day,...
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
  • For the following task, I have written code in C and need help in determining the...

    For the following task, I have written code in C and need help in determining the cause(s) of a segmentation fault which occurs when run. **It prints the message on line 47 "printf("Reading the input file and writing data to output file simultaneously..."); then results in a segmentation fault (core dumped) I am using mobaXterm v11.0 (GNU nano 2.0.9) CSV (comma-separated values) is a popular file format to store tabular kind of data. Each record is in a separate line...

  • what is the output of the following program? #include<stdio.h> #include<string.h> int main(void){ char word[20]; int i...

    what is the output of the following program? #include<stdio.h> #include<string.h> int main(void){ char word[20]; int i =0    strcpy(word, "ORGANISE"); while(word[i] !='\0'){ if(i%2 ==1) word[i] = 'C'; i++; } printf("%s",word); return 0; }

  • This program uses C++. This program reads in a line from the user and prints it...

    This program uses C++. This program reads in a line from the user and prints it out in a certain format. An example would be Input: 1 2 3 4 5 would result Output: [{1}, {2}, {3}, {4}, {5}]. When quotations marks are added into the input the format becomes different. For instance, Input 1 2 "3 4 5" would result in [{1}, {2}, {3 4 5}]. When I ad multiple quotation marks into the input, it will only use...

  • Program 2: Thread version int i = 100; char *buffer: void *tfuc(void *noarg) { int j...

    Program 2: Thread version int i = 100; char *buffer: void *tfuc(void *noarg) { int j = 0; printf("B:1-%d, j = %d\n",1,1); printf("B: I = %d, j = %d\n",1,1); j = 3; strcpy(buffer, "red"); Pthread exit(NULL); //print the string (show values of i, j) //print the string (show values of i,1) //copy the string "red" to buffer. int main(void) { pthread_t tid; //declaring vars int j = 1; buffer strcpy(malloc(100), "blue"); //Initialize buffer and copy the "blue" to it pthread_create(&tid,...

  • Given the following enumeration, what is the output from the printf(): enum day { sun, mon,...

    Given the following enumeration, what is the output from the printf(): enum day { sun, mon, tue, wed, thu, fri, sat}; enum day d; d = mon; prrintf("%d\n", d); a. mon b. 1 c. MON d. 0

  • Programming In C A) What will print after the following statements execute? char s1[50] = "jack";...

    Programming In C A) What will print after the following statements execute? char s1[50] = "jack"; char s2[50] = "jill"; char s3[50]; printf("%s", strcat(strcat(strcpy(s3, s1), " and "), s2)); B) What will print after the following statements execute? char s1[50] = "jack"; char s2[50] = "jill"; char s3[50]; printf("%u", strlen(s3));

  • Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; };...

    Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; }; void func(struct student stud); int main() { struct student astud; astud.id=9401; strcpy(astud.name, "Joe"); astud.grade = 'A'; func(astud); return 0; } Abdelghani Bellaachia, CSCI 1121 Page: 16 void func(struct student astud) { printf(" Id is: %d \n", astud.id); printf(" Name is: %s \n", astud.name); printf(" Grade is: %c \n", astud.grade); } Modify this program to include the address of a student as a separate structure....

  • Q4 Let f be the following C function: void f(char *p) {char *q = p; while...

    Q4 Let f be the following C function: void f(char *p) {char *q = p; while (*q) q++; while (p < q){char ch - *p; *p++ = ---q;*q = ch;}}What modification dues f perform to the string that is passed to it? Explain how f works. Give a coherent English description of the algorithm that f uses; do not simply repeat what the code says.

  • c++ language Step 1. Try to execute the following program (CP11E02) and record the results. #include...

    c++ language Step 1. Try to execute the following program (CP11E02) and record the results. #include <iostream.h> #include <string.h> class tv show private: char title[30]; int length; // 30 or 60 minutes char kind; // Ccomedy, d-drama, i - infomercial public: tv_show(char til),int I, char k) // constructor (strcpy(title, s); length = 1 kind=k; void main(void) tv show one("One Day to Live", 60,'d'); tv show two("Enemies".30,'c'), Step 2. Modify the statement tv_show one("One Day to Live",60,'d'); to read tv_show one;...

  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

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