Relax ttyname_r error checks

* src/engine-assuan.c (llass_new): Don't treat ttyname_r error as
fatal.
* src/engine-g13.c (g13_new): Likewise.
* src/engine-gpg.c (gpg_new): Likewise.
* src/engine-gpgsm.c (gpgsm_new): Likewise.
* src/engine-uiserver.c (uiserver_new): Likewise.

--
Even though isatty() returns 1, ttyname_r() may fail in many ways, e.g.,
when /dev/pts is not accessible under chroot.  Since all our uses of
ttyname_r() require that the function works, we can treat the failure as
if isatty() fails.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
This commit is contained in:
Daiki Ueno 2015-07-27 16:19:52 +09:00 committed by Werner Koch
parent 97f1f3e883
commit 028a0ef333
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
5 changed files with 24 additions and 29 deletions

View File

@ -282,12 +282,10 @@ llass_new (void **engine, const char *file_name, const char *home_dir)
char *dft_ttytype = NULL; char *dft_ttytype = NULL;
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname)); rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
if (rc)
{ /* Even though isatty() returns 1, ttyname_r() may fail in many
err = gpg_error_from_errno (rc); ways, e.g., when /dev/pts is not accessible under chroot. */
goto leave; if (!rc)
}
else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {

View File

@ -286,12 +286,10 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
int rc; int rc;
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname)); rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
if (rc)
{ /* Even though isatty() returns 1, ttyname_r() may fail in many
err = gpg_error_from_errno (rc); ways, e.g., when /dev/pts is not accessible under chroot. */
goto leave; if (!rc)
}
else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {

View File

@ -513,6 +513,8 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
rc = add_arg (gpg, dft_display); rc = add_arg (gpg, dft_display);
free (dft_display); free (dft_display);
if (rc)
goto leave;
} }
if (isatty (1)) if (isatty (1))
@ -520,9 +522,10 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
int err; int err;
err = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname)); err = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
if (err)
rc = gpg_error_from_errno (err); /* Even though isatty() returns 1, ttyname_r() may fail in many
else ways, e.g., when /dev/pts is not accessible under chroot. */
if (!err)
{ {
if (*dft_ttyname) if (*dft_ttyname)
{ {
@ -547,9 +550,9 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
free (dft_ttytype); free (dft_ttytype);
} }
if (rc)
goto leave;
} }
if (rc)
goto leave;
} }
leave: leave:

View File

@ -408,12 +408,10 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
int rc; int rc;
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname)); rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
if (rc)
{ /* Even though isatty() returns 1, ttyname_r() may fail in many
err = gpg_error_from_errno (rc); ways, e.g., when /dev/pts is not accessible under chroot. */
goto leave; if (!rc)
}
else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {

View File

@ -326,12 +326,10 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
int rc; int rc;
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname)); rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
if (rc)
{ /* Even though isatty() returns 1, ttyname_r() may fail in many
err = gpg_error_from_errno (rc); ways, e.g., when /dev/pts is not accessible under chroot. */
goto leave; if (!rc)
}
else
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {