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

View File

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