diff options
-rw-r--r-- | generator/generator_c.ml | 4 | ||||
-rw-r--r-- | src/guestfs-internal.h | 1 | ||||
-rw-r--r-- | src/guestfs.c | 29 |
3 files changed, 33 insertions, 1 deletions
diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 0a9060b6..dad3ac30 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -591,7 +591,6 @@ check_state (guestfs_h *g, const char *caller) | Dev_or_Path n | FileIn n | FileOut n - | BufferIn n | Key n -> (* guestfish doesn't support string escaping, so neither do we *) pr " fprintf (stderr, \" \\\"%%s\\\"\", %s);\n" n @@ -613,6 +612,9 @@ check_state (guestfs_h *g, const char *caller) pr " fprintf (stderr, \" %%d\", %s);\n" n | Int64 n -> pr " fprintf (stderr, \" %%\" PRIi64, %s);\n" n + | BufferIn n -> (* RHBZ#646822 *) + pr " fputc (' ', stderr);\n"; + pr " guestfs___print_BufferIn (stderr, %s, %s_size);\n" n n ) args; (* Optional arguments. *) diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 212006d9..a42375fc 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -212,6 +212,7 @@ extern int guestfs___send_to_daemon (guestfs_h *g, const void *v_buf, size_t n); extern int guestfs___recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn); extern int guestfs___accept_from_daemon (guestfs_h *g); extern int guestfs___build_appliance (guestfs_h *g, char **kernel, char **initrd, char **appliance); +extern void guestfs___print_BufferIn (FILE *out, const char *buf, size_t buf_size); #define error guestfs_error #define perrorf guestfs_perrorf diff --git a/src/guestfs.c b/src/guestfs.c index f79aaedf..325bdb0c 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -61,6 +61,7 @@ #include <arpa/inet.h> #include <netinet/in.h> +#include "c-ctype.h" #include "glthread/lock.h" #include "hash.h" #include "hash-pjw.h" @@ -731,3 +732,31 @@ guestfs_get_private (guestfs_h *g, const char *key) else return NULL; } + +/* When tracing, be careful how we print BufferIn parameters which + * usually contain large amounts of binary data (RHBZ#646822). + */ +void +guestfs___print_BufferIn (FILE *out, const char *buf, size_t buf_size) +{ + size_t i; + size_t orig_size = buf_size; + + if (buf_size > 256) + buf_size = 256; + + fputc ('"', out); + + for (i = 0; i < buf_size; ++i) { + if (c_isprint (buf[i])) + fputc (buf[i], out); + else + fprintf (out, "\\x%02x", (unsigned char) buf[i]); + } + + fputc ('"', out); + + if (orig_size > buf_size) + fprintf (out, + _("<truncated, original size %zu bytes>"), orig_size); +} |