subject

Identify the security vulnerabilities in all of these code segments and, for each vulnerability, discuss at least one way that it could be improved.
a)
/* file leak */
int main(int argc, char *argv[]){
char *filepath = argv[0];
char *shellpath = argv[1];
file *passwords;
passwords = fopen(filepath, "r");
/* read password and do something with it */
/* . . */
/* execute alternative shell */
execl(shellpath, "shell", null);
}
b)
/*
assume the following function is written for an electronic storefront.
the user will enter the id of the item to be ordered, as well
as the quantity of units that they would like to purchase.
the program will then lookup the price for the price for the
item using a predefined function, and return
the total cost of the order.
*/
int gettotalcost(){
char itemid[9];
int price, unitsordered, cost;
printf(" enter the 9-digit id of desired item: ");
scanf("%s", & itemid);
/* lookup price according to the itemid */
price = getpricebyid(itemid);
printf(" enter the quantity of units to be ordered: ");
scanf("%d", & unitsordered);
cost = price * unitsordered;
return cost;
}
c)
/* the following is intended to return a user's full name
by concatenating the user's first and last name into a single string
and then returning that string. */
char *getfullname(char *firstname, char *lastname, int max_len){
char fullname[max_len];
strcpy(fullname, firstname);
strcat(fullname, " ");
strcat(fullname, lastname);
return fullname;
}
d)
/* the following code snippet runs through the list of cli arguments
entered and displays them to the console. */
int main(int argc, char *argv[]){
int i;
printf("you've entered the following arguments: ");
for(i = 0; i < argc; i++){
printf(argv[i]);
printf("\n");
}
/* */
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 12:00
From excel to powerpoint, you can copy and paste a. cell ranges and charts, one at a time. b. cell ranges and charts, simultaneously. c. charts only. d. cell ranges only.
Answers: 3
question
Computers and Technology, 23.06.2019 20:40
Instruction active describing list features which statements accurately describe the features of word that are used to create lists? check all that apply. the tab key can be used to create a sublist. the enter key can be used to add an item to a list. the numbering feature allows for the use of letters in a list. the numbering feature can change the numbers to bullets in a list. the multilevel list feature provides options for different levels in a list.
Answers: 2
question
Computers and Technology, 25.06.2019 11:30
What is a wiki farm? a.) a hosting service that allows you to build a wiki. b.) a collection of servers that store wiki search queries. c.) an association of wiki hosting companies. d.) a wiki created using environmentally friendly material.
Answers: 2
question
Computers and Technology, 25.06.2019 12:00
If you fear you have been abusive to a partner, what can you do?
Answers: 2
You know the right answer?
Identify the security vulnerabilities in all of these code segments and, for each vulnerability, dis...
Questions
question
History, 06.10.2020 15:01
question
History, 06.10.2020 15:01
question
Geography, 06.10.2020 15:01
question
Mathematics, 06.10.2020 15:01
Questions on the website: 13722367