summaryrefslogtreecommitdiff
path: root/dbutil.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2020-10-26 22:51:44 +0800
committerMatt Johnston <matt@ucc.asn.au>2020-10-26 22:51:44 +0800
commitacd6a22a0c2204b3129131ff41fd6f55281423a4 (patch)
treeb310e1ae180e40c99cd83e4681880bcf97796dc5 /dbutil.c
parent4e8a1da551db44e5865f6a1cc28e24fc2c2bdd0f (diff)
downloaddropbear-acd6a22a0c2204b3129131ff41fd6f55281423a4.tar.gz
Print ascii in printhex too
Diffstat (limited to 'dbutil.c')
-rw-r--r--dbutil.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/dbutil.c b/dbutil.c
index 5af6330..53256a2 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -385,20 +385,37 @@ void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell) {
#if DEBUG_TRACE
void printhex(const char * label, const unsigned char * buf, int len) {
-
- int i;
+ int i, j;
fprintf(stderr, "%s\n", label);
- for (i = 0; i < len; i++) {
- fprintf(stderr, "%02x", buf[i]);
- if (i % 16 == 15) {
- fprintf(stderr, "\n");
+ /* for each 16 byte line */
+ for (j = 0; j < len; j += 16) {
+ const int linelen = MIN(16, len - j);
+
+ /* print hex digits */
+ for (i = 0; i < 16; i++) {
+ if (i < linelen) {
+ fprintf(stderr, "%02x", buf[j+i]);
+ } else {
+ fprintf(stderr, " ");
+ }
+ // separator between pairs
+ if (i % 2 ==1) {
+ fprintf(stderr, " ");
+ }
}
- else if (i % 2 == 1) {
- fprintf(stderr, " ");
+
+ /* print characters */
+ fprintf(stderr, " ");
+ for (i = 0; i < linelen; i++) {
+ char c = buf[j+i];
+ if (!isprint(c)) {
+ c = '.';
+ }
+ fputc(c, stderr);
}
+ fprintf(stderr, "\n");
}
- fprintf(stderr, "\n");
}
void printmpint(const char *label, mp_int *mp) {