|
|
61de54 |
commit a87d9e8f89f946a733c756c72bf5ec41e0a738b8
|
|
|
61de54 |
Author: Jakub Jelen <jjelen@redhat.com>
|
|
|
61de54 |
Date: Wed Apr 14 15:51:27 2021 +0900
|
|
|
61de54 |
|
|
|
61de54 |
core,emacs,tty,curses: Fix memory leaks, invalid accese, and mistake.
|
|
|
61de54 |
|
|
|
61de54 |
* pinentry/pinentry-curses.c (dialog_create): Free NEW.
|
|
|
61de54 |
[HAVE_NCURSESW] (dialog_run): Free OLD_CTYPE on error.
|
|
|
61de54 |
* pinentry/pinentry.c (pinentry_inq_genpin): Free VALUE on error.
|
|
|
61de54 |
* tty/pinentry-tty.c (tty_cmd_handler): Don't access closed FDs.
|
|
|
61de54 |
* pinentry/pinentry-emacs.c (set_labels): Fix for ->default_cancel.
|
|
|
61de54 |
|
|
|
61de54 |
--
|
|
|
61de54 |
|
|
|
61de54 |
GnuPG-bug-id: 5384
|
|
|
61de54 |
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
|
|
|
61de54 |
|
|
|
61de54 |
diff --git a/pinentry/pinentry-curses.c b/pinentry/pinentry-curses.c
|
|
|
61de54 |
index a3fe2e2..1c3008a 100644
|
|
|
61de54 |
--- a/pinentry/pinentry-curses.c
|
|
|
61de54 |
+++ b/pinentry/pinentry-curses.c
|
|
|
61de54 |
@@ -315,6 +315,7 @@ dialog_create (pinentry_t pinentry, dialog_t dialog)
|
|
|
61de54 |
} \
|
|
|
61de54 |
dialog->which = pinentry_utf8_to_local (pinentry->lc_ctype, \
|
|
|
61de54 |
new ? new : default); \
|
|
|
61de54 |
+ free (new); \
|
|
|
61de54 |
if (!dialog->which) \
|
|
|
61de54 |
{ \
|
|
|
61de54 |
err = 1; \
|
|
|
61de54 |
@@ -873,6 +874,9 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
|
|
|
61de54 |
{
|
|
|
61de54 |
pinentry->specific_err = gpg_error_from_syserror ();
|
|
|
61de54 |
pinentry->specific_err_loc = "open_tty_for_read";
|
|
|
61de54 |
+#ifdef HAVE_NCURSESW
|
|
|
61de54 |
+ free (old_ctype);
|
|
|
61de54 |
+#endif
|
|
|
61de54 |
return confirm_mode? 0 : -1;
|
|
|
61de54 |
}
|
|
|
61de54 |
ttyfo = fopen (tty_name, "w");
|
|
|
61de54 |
@@ -883,6 +887,9 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
|
|
|
61de54 |
errno = err;
|
|
|
61de54 |
pinentry->specific_err = gpg_error_from_syserror ();
|
|
|
61de54 |
pinentry->specific_err_loc = "open_tty_for_write";
|
|
|
61de54 |
+#ifdef HAVE_NCURSESW
|
|
|
61de54 |
+ free (old_ctype);
|
|
|
61de54 |
+#endif
|
|
|
61de54 |
return confirm_mode? 0 : -1;
|
|
|
61de54 |
}
|
|
|
61de54 |
screen = newterm (tty_type, ttyfo, ttyfi);
|
|
|
61de54 |
@@ -897,6 +904,9 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
|
|
|
61de54 |
errno = ENOTTY;
|
|
|
61de54 |
pinentry->specific_err = gpg_error_from_syserror ();
|
|
|
61de54 |
pinentry->specific_err_loc = "isatty";
|
|
|
61de54 |
+#ifdef HAVE_NCURSESW
|
|
|
61de54 |
+ free (old_ctype);
|
|
|
61de54 |
+#endif
|
|
|
61de54 |
return confirm_mode? 0 : -1;
|
|
|
61de54 |
}
|
|
|
61de54 |
init_screen = 1;
|
|
|
61de54 |
diff --git a/pinentry/pinentry-emacs.c b/pinentry/pinentry-emacs.c
|
|
|
61de54 |
index 16ae1c2..9685b67 100644
|
|
|
61de54 |
--- a/pinentry/pinentry-emacs.c
|
|
|
61de54 |
+++ b/pinentry/pinentry-emacs.c
|
|
|
61de54 |
@@ -498,7 +498,7 @@ set_labels (pinentry_t pe)
|
|
|
61de54 |
set_label (pe, "SETOK", pe->default_ok);
|
|
|
61de54 |
if (pe->cancel)
|
|
|
61de54 |
set_label (pe, "SETCANCEL", pe->cancel);
|
|
|
61de54 |
- else if (pe->default_ok)
|
|
|
61de54 |
+ else if (pe->default_cancel)
|
|
|
61de54 |
set_label (pe, "SETCANCEL", pe->default_cancel);
|
|
|
61de54 |
if (pe->notok)
|
|
|
61de54 |
set_label (pe, "SETNOTOK", pe->notok);
|
|
|
61de54 |
diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c
|
|
|
61de54 |
index ef81f12..26ec77a 100644
|
|
|
61de54 |
--- a/pinentry/pinentry.c
|
|
|
61de54 |
+++ b/pinentry/pinentry.c
|
|
|
61de54 |
@@ -656,6 +656,7 @@ pinentry_inq_genpin (pinentry_t pin)
|
|
|
61de54 |
if (rc)
|
|
|
61de54 |
{
|
|
|
61de54 |
fprintf (stderr, "ASSUAN READ LINE failed: rc=%d\n", rc);
|
|
|
61de54 |
+ free (value);
|
|
|
61de54 |
return 0;
|
|
|
61de54 |
}
|
|
|
61de54 |
}
|
|
|
61de54 |
diff --git a/tty/pinentry-tty.c b/tty/pinentry-tty.c
|
|
|
61de54 |
index 403dd60..4a2b67f 100644
|
|
|
61de54 |
--- a/tty/pinentry-tty.c
|
|
|
61de54 |
+++ b/tty/pinentry-tty.c
|
|
|
61de54 |
@@ -559,7 +559,7 @@ tty_cmd_handler (pinentry_t pinentry)
|
|
|
61de54 |
}
|
|
|
61de54 |
}
|
|
|
61de54 |
|
|
|
61de54 |
- if (terminal_save (fileno (ttyfi)) < 0)
|
|
|
61de54 |
+ if (!rc && terminal_save (fileno (ttyfi)) < 0)
|
|
|
61de54 |
rc = -1;
|
|
|
61de54 |
|
|
|
61de54 |
if (! rc)
|
|
|
61de54 |
|
|
|
61de54 |
From 7f7fd8bcfd74919091cc318b27b8617a9ef2ac82 Mon Sep 17 00:00:00 2001
|
|
|
61de54 |
From: NIIBE Yutaka <gniibe@fsij.org>
|
|
|
61de54 |
Date: Fri, 16 Apr 2021 12:54:43 +0900
|
|
|
61de54 |
Subject: [PATCH] tty: Fix error return paths and its resource leaks.
|
|
|
61de54 |
|
|
|
61de54 |
* tty/pinentry-tty.c (tty_cmd_handler): Only call do_touch_file
|
|
|
61de54 |
on successful interaction. Fix closing file.
|
|
|
61de54 |
|
|
|
61de54 |
--
|
|
|
61de54 |
|
|
|
61de54 |
GnuPG-bug-id: 5384
|
|
|
61de54 |
Co-authored-by: Jakub Jelen <jjelen@redhat.com>
|
|
|
61de54 |
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
|
|
|
61de54 |
---
|
|
|
61de54 |
tty/pinentry-tty.c | 34 +++++++++++++++++-----------------
|
|
|
61de54 |
1 file changed, 17 insertions(+), 17 deletions(-)
|
|
|
61de54 |
|
|
|
61de54 |
diff --git a/tty/pinentry-tty.c b/tty/pinentry-tty.c
|
|
|
61de54 |
index 4a2b67f..c4d85c6 100644
|
|
|
61de54 |
--- a/tty/pinentry-tty.c
|
|
|
61de54 |
+++ b/tty/pinentry-tty.c
|
|
|
61de54 |
@@ -525,6 +525,7 @@ tty_cmd_handler (pinentry_t pinentry)
|
|
|
61de54 |
int rc = 0;
|
|
|
61de54 |
FILE *ttyfi = stdin;
|
|
|
61de54 |
FILE *ttyfo = stdout;
|
|
|
61de54 |
+ int saved_errno = 0;
|
|
|
61de54 |
|
|
|
61de54 |
#ifndef HAVE_DOSISH_SYSTEM
|
|
|
61de54 |
timed_out = 0;
|
|
|
61de54 |
@@ -545,30 +546,27 @@ tty_cmd_handler (pinentry_t pinentry)
|
|
|
61de54 |
{
|
|
|
61de54 |
ttyfi = fopen (pinentry->ttyname, "r");
|
|
|
61de54 |
if (!ttyfi)
|
|
|
61de54 |
- rc = -1;
|
|
|
61de54 |
- else
|
|
|
61de54 |
+ return -1;
|
|
|
61de54 |
+
|
|
|
61de54 |
+ ttyfo = fopen (pinentry->ttyname, "w");
|
|
|
61de54 |
+ if (!ttyfo)
|
|
|
61de54 |
{
|
|
|
61de54 |
- ttyfo = fopen (pinentry->ttyname, "w");
|
|
|
61de54 |
- if (!ttyfo)
|
|
|
61de54 |
- {
|
|
|
61de54 |
- int err = errno;
|
|
|
61de54 |
- fclose (ttyfi);
|
|
|
61de54 |
- errno = err;
|
|
|
61de54 |
- rc = -1;
|
|
|
61de54 |
- }
|
|
|
61de54 |
+ saved_errno = errno;
|
|
|
61de54 |
+ fclose (ttyfi);
|
|
|
61de54 |
+ errno = saved_errno;
|
|
|
61de54 |
+ return -1;
|
|
|
61de54 |
}
|
|
|
61de54 |
}
|
|
|
61de54 |
|
|
|
61de54 |
- if (!rc && terminal_save (fileno (ttyfi)) < 0)
|
|
|
61de54 |
+ if (terminal_save (fileno (ttyfi)) < 0)
|
|
|
61de54 |
rc = -1;
|
|
|
61de54 |
-
|
|
|
61de54 |
- if (! rc)
|
|
|
61de54 |
+ else
|
|
|
61de54 |
{
|
|
|
61de54 |
if (terminal_setup (fileno (ttyfi), !!pinentry->pin) == -1)
|
|
|
61de54 |
{
|
|
|
61de54 |
- int err = errno;
|
|
|
61de54 |
+ saved_errno = errno;
|
|
|
61de54 |
fprintf (stderr, "terminal_setup failure, exiting\n");
|
|
|
61de54 |
- errno = err;
|
|
|
61de54 |
+ rc = -1;
|
|
|
61de54 |
}
|
|
|
61de54 |
else
|
|
|
61de54 |
{
|
|
|
61de54 |
@@ -578,17 +576,19 @@ tty_cmd_handler (pinentry_t pinentry)
|
|
|
61de54 |
rc = confirm (pinentry, ttyfi, ttyfo);
|
|
|
61de54 |
|
|
|
61de54 |
terminal_restore (fileno (ttyfi));
|
|
|
61de54 |
+ do_touch_file (pinentry);
|
|
|
61de54 |
}
|
|
|
61de54 |
}
|
|
|
61de54 |
|
|
|
61de54 |
- do_touch_file (pinentry);
|
|
|
61de54 |
-
|
|
|
61de54 |
if (pinentry->ttyname)
|
|
|
61de54 |
{
|
|
|
61de54 |
fclose (ttyfi);
|
|
|
61de54 |
fclose (ttyfo);
|
|
|
61de54 |
}
|
|
|
61de54 |
|
|
|
61de54 |
+ if (saved_errno)
|
|
|
61de54 |
+ errno = saved_errno;
|
|
|
61de54 |
+
|
|
|
61de54 |
return rc;
|
|
|
61de54 |
}
|
|
|
61de54 |
|
|
|
61de54 |
--
|
|
|
61de54 |
2.30.2
|