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 06:30
When early motion pictures played in movie theaters, they were often accompanied by live organ or piano music. which of the following are the most likely reasons that this happened? (select all that apply). the music was provided to distract audience members from the loud sounds made when filmstrips were changed. the music accompanied the movies because the movies were silent and audiences were used to hearing music during plays in theaters. the music usually was played before, and sometimes after the movie, as an alternative form of entertainment. the music viewers to interpret the dramatic action in the films.
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
question
Computers and Technology, 23.06.2019 22:00
Take a critical look at three gui applications you have used—for example, a spreadsheet, a word-processing program, and a game. describe how well each conforms to the gui design guidelines listed in this chapter.
Answers: 3
question
Computers and Technology, 24.06.2019 01:00
The initial tableau of a linear programming problem is given. use the simplex method to solve it. x 1 x 2 x 3 s 1 s 2 z 1 2 4 1 0 0 8 3 4 1 0 1 0 10 minus3 minus12 1 0 0 1 0 the maximum is nothing when x 1equals nothing, x 2equals nothing, x 3equals nothing, s 1equals3, and s 2equals0. (be sure to simplify to lowest terms if necessary.)
Answers: 2
You know the right answer?
Identify the security vulnerabilities in all of these code segments and, for each vulnerability, dis...
Questions
question
Chemistry, 24.09.2019 20:50
question
Mathematics, 24.09.2019 20:50
question
Mathematics, 24.09.2019 20:50
Questions on the website: 13722361