aboutsummaryrefslogtreecommitdiffstats
path: root/common/stringhelp.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-01-28 19:12:21 +0000
committerWerner Koch <[email protected]>2015-01-28 19:12:21 +0000
commitd8eea25b8b7becbfa3f059be6f5966a2f1aa7112 (patch)
tree6e82e33f1237fb15bce50726f5502f1af5d3e105 /common/stringhelp.c
parentAdd a hook to be called right after main. (diff)
downloadgnupg-d8eea25b8b7becbfa3f059be6f5966a2f1aa7112.tar.gz
gnupg-d8eea25b8b7becbfa3f059be6f5966a2f1aa7112.zip
gpg: Fix buffering problem in --list-config.
* g10/gpg.c (list_config): Replace print_sanitized_string2 by es_write_sanitized. * common/stringhelp.c (print_sanitized_buffer2): Remove. (print_sanitized_buffer, print_sanitized_utf8_buffer): Remove. (print_sanitized_utf8_buffer, print_sanitized_utf8_string): Remove. (print_sanitized_string): Remove. * sm/certdump.c (print_dn_part, print_dn_parts): Remove arg FP. (pretty_print_sexp, gpgsm_print_name2, gpgsm_print_name): Remove. -- Mixing stdio and estream is never a good idea. This fix also allows us to remove a lot of garbage. Reported-by: Jason A. Donenfeld <[email protected]> GnuPG-bug-id: 1822 Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/stringhelp.c')
-rw-r--r--common/stringhelp.c123
1 files changed, 0 insertions, 123 deletions
diff --git a/common/stringhelp.c b/common/stringhelp.c
index 7ce041d01..7128de5fc 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -671,129 +671,6 @@ hextobyte (const char *s)
}
-/* Print a BUFFER to stream FP while replacing all control characters
- and the characters DELIM and DELIM2 with standard C escape
- sequences. Returns the number of characters printed. */
-size_t
-print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
- int delim, int delim2)
-{
- const unsigned char *p = buffer;
- size_t count = 0;
-
- for (; length; length--, p++, count++)
- {
- if (*p < 0x20
- || *p == 0x7f
- || *p == delim
- || *p == delim2
- || ((delim || delim2) && *p=='\\'))
- {
- putc ('\\', fp);
- count++;
- if (*p == '\n')
- {
- putc ('n', fp);
- count++;
- }
- else if (*p == '\r')
- {
- putc ('r', fp);
- count++;
- }
- else if (*p == '\f')
- {
- putc ('f', fp);
- count++;
- }
- else if (*p == '\v')
- {
- putc ('v', fp);
- count++;
- }
- else if (*p == '\b')
- {
- putc ('b', fp);
- count++;
- }
- else if (!*p)
- {
- putc('0', fp);
- count++;
- }
- else
- {
- fprintf (fp, "x%02x", *p);
- count += 3;
- }
- }
- else
- {
- putc (*p, fp);
- count++;
- }
- }
-
- return count;
-}
-
-/* Same as print_sanitized_buffer2 but with just one delimiter. */
-size_t
-print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
- int delim)
-{
- return print_sanitized_buffer2 (fp, buffer, length, delim, 0);
-}
-
-
-size_t
-print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
- size_t length, int delim)
-{
- const char *p = buffer;
- size_t i;
-
- /* We can handle plain ascii simpler, so check for it first. */
- for (i=0; i < length; i++ )
- {
- if ( (p[i] & 0x80) )
- break;
- }
- if (i < length)
- {
- char *buf = utf8_to_native (p, length, delim);
- /*(utf8 conversion already does the control character quoting)*/
- i = strlen (buf);
- fputs (buf, fp);
- jnlib_free (buf);
- return i;
- }
- else
- return print_sanitized_buffer (fp, p, length, delim);
-}
-
-
-size_t
-print_sanitized_string2 (FILE *fp, const char *string, int delim, int delim2)
-{
- return string? print_sanitized_buffer2 (fp, string, strlen (string),
- delim, delim2):0;
-}
-
-size_t
-print_sanitized_string (FILE *fp, const char *string, int delim)
-{
- return string? print_sanitized_buffer (fp, string, strlen (string), delim):0;
-}
-
-size_t
-print_sanitized_utf8_string (FILE *fp, const char *string, int delim)
-{
- return string? print_sanitized_utf8_buffer (fp,
- string, strlen (string),
- delim) : 0;
-}
-
/* Create a string from the buffer P_ARG of length N which is suitable
for printing. Caller must release the created string using xfree.
This function terminates the process on memory shortage. */