Tag: security
Questions Related to security
int main (int argc, char *argv[]){
char chararray[3];
int intarray[3];
int i;
strncpy(chararray, argv[1], sizeof(chararray) - 1);
for (i=0;i<=3; i++){ /*1*/ chararray[i]= getchar();
intarray[i]=i*i;/*2*/
}
}
Is there a vulnerability in this code? If yes, which line(s) (Line numbers are marked using comments /* */)?
Which of the following is a secure way to use scanf?
How do you fix the unbounded string copy in the following code?
char fname[20]; /* 1 */
cout << “Enter First Name:”; /* 2 */
cin >> fname ; /* 3 */
int main(int argc,char* argv[]){
int *ptr=new int;
if(ptr==NULL) exit(1);
char *j;
for(int i=1; i<=4; i++) {
j=argv[i];
int k=atoi(j);
if (k!=0){
*ptr=k;
delete ptr;
}
}
}
Will this program execute successfully ?