summaryrefslogtreecommitdiff
path: root/rpmsign.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2017-06-09 12:52:08 +0300
committerPanu Matilainen <pmatilai@redhat.com>2017-06-09 12:57:00 +0300
commit46c7bf438e5349676139dba0655faed3b2230827 (patch)
tree6e650d4401d6dbea0d2376aa4cf5fd332e39f740 /rpmsign.c
parent542f41a8bdc385ed849170565ac353956a47683a (diff)
downloadrpm-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.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/rpmsign.c b/rpmsign.c
index a59f2dc1c..ae86f666d 100644
--- a/rpmsign.c
+++ b/rpmsign.c
@@ -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