mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-12 15:41:16 +03:00
Getpass: Fix password clearing
This commit is contained in:
@@ -50,7 +50,7 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify) {
|
|||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ZERO_STRUCT(tmp);
|
memset(tmp,'\0',len);
|
||||||
|
|
||||||
/* read the password */
|
/* read the password */
|
||||||
while (!ok) {
|
while (!ok) {
|
||||||
@@ -74,16 +74,16 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify) {
|
|||||||
if (verify) {
|
if (verify) {
|
||||||
char *key_string;
|
char *key_string;
|
||||||
|
|
||||||
key_string = (char *) malloc(len);
|
key_string = malloc(len);
|
||||||
if (key_string == NULL) {
|
if (key_string == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ZERO_STRUCT(key_string);
|
memset(key_string, '\0', len);
|
||||||
|
|
||||||
fprintf(stdout, "\nVerifying, please re-enter. %s", prompt);
|
fprintf(stdout, "\nVerifying, please re-enter. %s", prompt);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (! fgets(key_string, len, stdin)) {
|
if (! fgets(key_string, len, stdin)) {
|
||||||
ZERO_STRUCT(key_string);
|
memset(key_string, '\0', len);
|
||||||
SAFE_FREE(key_string);
|
SAFE_FREE(key_string);
|
||||||
clearerr(stdin);
|
clearerr(stdin);
|
||||||
continue;
|
continue;
|
||||||
@@ -94,18 +94,17 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify) {
|
|||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
if (strcmp(buf, key_string)) {
|
if (strcmp(buf, key_string)) {
|
||||||
printf("\n\07\07Mismatch - try again\n");
|
printf("\n\07\07Mismatch - try again\n");
|
||||||
ZERO_STRUCT(key_string);
|
memset(key_string, '\0', len);
|
||||||
SAFE_FREE(key_string);
|
SAFE_FREE(key_string);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ZERO_STRUCT(key_string);
|
memset(key_string, '\0', len);
|
||||||
SAFE_FREE(key_string);
|
SAFE_FREE(key_string);
|
||||||
}
|
}
|
||||||
ok = 1;
|
ok = 1;
|
||||||
}
|
}
|
||||||
|
memset(tmp, '\0', len);
|
||||||
ZERO_STRUCT(tmp);
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
@@ -147,7 +146,7 @@ int ssh_getpass(const char *prompt,
|
|||||||
SetConsoleMode(h, mode);
|
SetConsoleMode(h, mode);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
ZERO_STRUCT(buf);
|
memset (buf, '\0', len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +259,7 @@ int ssh_getpass(const char *prompt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
ZERO_STRUCT(buf);
|
memset (buf, '\0', len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user