diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2017-06-09 12:52:08 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2017-06-09 12:57:00 +0300 |
commit | 46c7bf438e5349676139dba0655faed3b2230827 (patch) | |
tree | 6e650d4401d6dbea0d2376aa4cf5fd332e39f740 /rpmsign.c | |
parent | 542f41a8bdc385ed849170565ac353956a47683a (diff) | |
download | rpm-46c7bf438e5349676139dba0655faed3b2230827.tar.gz |
Fix a number of problems in get_fskpass()
Fix segfault in case of fgets() failure, fix memleak on password
buffer on failure.
Diffstat (limited to 'rpmsign.c')
-rw-r--r-- | rpmsign.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -61,7 +61,7 @@ static char *get_fskpass(void) struct termios flags, tmp_flags; int passlen = 64; char *password = xmalloc(passlen); - char *pwd; + char *pwd = NULL; tcgetattr(fileno(stdin), &flags); tmp_flags = flags; @@ -70,17 +70,23 @@ static char *get_fskpass(void) if (tcsetattr(fileno(stdin), TCSANOW, &tmp_flags) != 0) { perror("tcsetattr"); - return NULL; + goto exit; } printf("PEM password: "); pwd = fgets(password, passlen, stdin); - pwd[strlen(pwd) - 1] = '\0'; /* remove newline */ if (tcsetattr(fileno(stdin), TCSANOW, &flags) != 0) { perror("tcsetattr"); - return NULL; + pwd = NULL; + goto exit; } + +exit: + if (pwd) + pwd[strlen(pwd) - 1] = '\0'; /* remove newline */ + else + free(password); return pwd; } #endif |