]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tools: fix memleak around getline
authorEkaterina Zilotina <zilotina.ed@npc-ksb.ru>
Mon, 26 Aug 2024 10:22:36 +0000 (13:22 +0300)
committerDaiki Ueno <ueno@gnu.org>
Thu, 29 Aug 2024 08:11:40 +0000 (17:11 +0900)
Fixes: #1573
Signed-off-by: Ekaterina Zilotina <zilotina.ed@npc-ksb.ru>
Signed-off-by: Daiki Ueno <ueno@gnu.org>
src/certtool-cfg.c
src/cli.c

index 2d7a1dcaf6198479562f3f39e04f2fc7e0b1e525..7b6a2f94b85a560ca45bf5bd100750079a689906 100644 (file)
@@ -621,10 +621,7 @@ void read_crt_set(gnutls_x509_crt_t crt, const char *input_str, const char *oid)
 
        fputs(input_str, stderr);
        ret = getline(&lineptr, &linesize, stdin);
-       if (ret == -1)
-               return;
-
-       if (IS_NEWLINE(lineptr)) {
+       if (ret == -1 || IS_NEWLINE(lineptr)) {
                free(lineptr);
                return;
        }
@@ -647,10 +644,7 @@ void read_crq_set(gnutls_x509_crq_t crq, const char *input_str, const char *oid)
 
        fputs(input_str, stderr);
        ret = getline(&lineptr, &linesize, stdin);
-       if (ret == -1)
-               return;
-
-       if (IS_NEWLINE(lineptr)) {
+       if (ret == -1 || IS_NEWLINE(lineptr)) {
                free(lineptr);
                return;
        }
@@ -789,8 +783,10 @@ const char *read_str(const char *input_str)
 
        fputs(input_str, stderr);
        ret = getline(&lineptr, &linesize, stdin);
-       if (ret == -1)
+       if (ret == -1) {
+               free(lineptr);
                return NULL;
+       }
 
        ret = copystr_without_nl(input, sizeof(input), lineptr, ret);
        free(lineptr);
index 055d102c6ff92f1a46f5e8d560acfce07519d717..4f53b1a02a9a12ae1ea6e14e9b42ffe42159720c 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1921,6 +1921,7 @@ static int psk_callback(gnutls_session_t session, char **username,
 
                if (ret == -1 || p == NULL) {
                        fprintf(stderr, "No username given, aborting...\n");
+                       free(p);
                        return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
                }