1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

gpg: Simplify an interactive import status line.

* g10/cpr.c (write_status_printf): Escape CR and LF.
* g10/import.c (print_import_check): Simplify by using
write_status_printf and hexfingerprint.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-03-15 13:02:44 +01:00
parent 3e1f3df618
commit f06b6fe47f
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
2 changed files with 33 additions and 18 deletions

View file

@ -142,7 +142,8 @@ write_status ( int no )
/* Write a status line with code NO followed by the string TEXT and
directly followed by the remaining strings up to a NULL. */
* directly followed by the remaining strings up to a NULL. Embedded
* CR and LFs in the strings (but not in TEXT) are C-style escaped.*/
void
write_status_strings (int no, const char *text, ...)
{
@ -188,12 +189,12 @@ write_status_text (int no, const char *text)
/* Write a status line with code NO followed by the output of the
* printf style FORMAT. The caller needs to make sure that LFs and
* CRs are not printed. */
* printf style FORMAT. Embedded CR and LFs are C-style escaped. */
void
write_status_printf (int no, const char *format, ...)
{
va_list arg_ptr;
char *buf;
if (!statusfp || !status_currently_allowed (no) )
return; /* Not enabled or allowed. */
@ -204,7 +205,30 @@ write_status_printf (int no, const char *format, ...)
{
es_putc ( ' ', statusfp);
va_start (arg_ptr, format);
es_vfprintf (statusfp, format, arg_ptr);
buf = gpgrt_vbsprintf (format, arg_ptr);
if (!buf)
log_error ("error printing status line: %s\n",
gpg_strerror (gpg_err_code_from_syserror ()));
else
{
if (strpbrk (buf, "\r\n"))
{
const byte *s;
for (s=buf; *s; s++)
{
if (*s == '\n')
es_fputs ("\\n", statusfp);
else if (*s == '\r')
es_fputs ("\\r", statusfp);
else
es_fputc (*s, statusfp);
}
}
else
es_fputs (buf, statusfp);
gpgrt_free (buf);
}
va_end (arg_ptr);
}
es_putc ('\n', statusfp);