(Solved) : Review Following Code Improve Code Remove Vulnerabilities Include Include Include Define B Q44124975 . . .
Review the following code and improve the code and removevulnerabilities.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define bzero(b,len) (memset((b),’ ‘, (len)), (void) 0)
using namespace std;
void setPassword(char pass[])
{
cout << “Thepassword accepted is ” << pass << endl;
}
char* getPasswordFromUser(char*prompt) {
char tmp[100];
cout << prompt;
cin >> tmp;
int len =strlen(tmp);
char* ret =(char*)malloc(len + 1);
strncpy_s(ret, len+1,tmp,len + 1);
bzero(tmp, len); /* don’tleave passwd copy in memory */
return ret;
}
void changePassword() {
char* pass1 =getPasswordFromUser(“enter new password: “);
char* pass2 =getPasswordFromUser(“re-enter new password: “);
if (strcmp(pass1, pass2)){
printf(“passwords do not matchn”);
}
else {
setPassword(pass1);
}
bzero(pass1,strlen(pass1)); /* don’t leave in memory */
bzero(pass2,strlen(pass2)); /* don’t leave in memory */
free(pass1);
free(pass2);
}
int main()
{
changePassword();
return 0;
}
Expert Answer
Answer to Review the following code and improve the code and remove vulnerabilities. #include #include #include #define bzero(b,le…
OR