mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
getpass: Use calloc to allocate memory
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
@@ -49,11 +49,10 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify) {
|
|||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
tmp = malloc(len);
|
tmp = calloc(1, len);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(tmp,'\0',len);
|
|
||||||
|
|
||||||
/* read the password */
|
/* read the password */
|
||||||
while (!ok) {
|
while (!ok) {
|
||||||
@@ -80,11 +79,10 @@ 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 = malloc(len);
|
key_string = calloc(1, len);
|
||||||
if (key_string == NULL) {
|
if (key_string == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user