Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

getscore c code #include #include #include #include #include FILE *scorefile; int get_score(char *name, char *ssn, char *score); char* str_prefix(char *prefix, char *str); int main(int argc,

getscore c code

#include #include #include #include #include FILE *scorefile; int get_score(char *name, char *ssn, char *score); char* str_prefix(char *prefix, char *str); int main(int argc, char *argv[]) { int ruid, euid; char score[128]; if (argc != 3) { printf("Usage: getscore name SSN "); exit(1); } time_t current_time = time(NULL); ruid = getuid (); euid = geteuid (); // This is to make sure the logging command will have // sufficient privilege. if (setreuid(euid, euid)){ perror("setreuid"); } scorefile = fopen("score.txt", "r"); if (scorefile == NULL){ printf ("failed to open score file "); } else{ if (get_score(argv[1], argv[2], score)){ char command[256]; printf("Invalid user name or SSN. "); sprintf(command, "echo \"%s: Invalid user name or SSN: %s,%s\"| cat >> error.log", ctime(¤t_time), argv[1], argv[2]); if (system(command)){ perror("Logging"); } exit(-1); } printf("Your score is %s ", score); } } int get_score(char *name, char *ssn, char *score) { char matching_pattern[128]; char line[128]; char *match_point; strcpy(matching_pattern, name); strcat(matching_pattern, ":"); strcat(matching_pattern, ssn);

while (fgets(line, 128, scorefile)!=NULL){ if ((match_point=str_prefix(matching_pattern, line))){ if (*match_point++==':'){ while (*match_point!=':'){ *score++=*match_point++; } *score=0; return 0; } } } return -1; } char* str_prefix(char *prefix, char *str){ while (*prefix && *str){ if (*prefix != *str) return NULL; prefix++; str++; } return *prefix==0?str:NULL; }

image text in transcribedPlease help me with this!

For the program getscore.c, identify two places where there is a security vulnerability. Demonstrate the existence of the vulnerability by providing the program with inputs that would crash the program. Show that the program will not crash with the same input after you fix the vulnerability. Include screenshots in your answers. Extra credit (5 pts) Try to find a third vulnerability in the code

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

Step: 3

blur-text-image

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

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions