From a2e788d74b3e0fbf66037bde6e1a270976a45b6b Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 27 Jun 2021 16:40:25 +0000 Subject: Teach hexdump() how to identify differing bytes. This allows differences between the received data and the test data to be more readily identified. --- src/regress/lib/libssl/client/clienttest.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/regress/lib/libssl/client/clienttest.c') diff --git a/src/regress/lib/libssl/client/clienttest.c b/src/regress/lib/libssl/client/clienttest.c index 86f6e2d6ca..2770e9559c 100644 --- a/src/regress/lib/libssl/client/clienttest.c +++ b/src/regress/lib/libssl/client/clienttest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clienttest.c,v 1.30 2021/06/27 16:36:53 jsing Exp $ */ +/* $OpenBSD: clienttest.c,v 1.31 2021/06/27 16:40:25 jsing Exp $ */ /* * Copyright (c) 2015 Joel Sing * @@ -289,13 +289,17 @@ static const struct client_hello_test client_hello_tests[] = { (sizeof(client_hello_tests) / sizeof(*client_hello_tests)) static void -hexdump(const uint8_t *buf, size_t len) +hexdump(const uint8_t *buf, size_t len, const uint8_t *compare) { + const char *mark = ""; size_t i; - for (i = 1; i <= len; i++) - fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 && i != len ? "" : "\n"); - + for (i = 1; i <= len; i++) { + if (compare != NULL) + mark = (buf[i - 1] != compare[i - 1]) ? "*" : " "; + fprintf(stderr, " %s0x%02hhx,%s", mark, buf[i - 1], + i % 8 && i != len ? "" : "\n"); + } fprintf(stderr, "\n"); } @@ -428,9 +432,9 @@ client_hello_test(int testno, const struct client_hello_test *cht) fprintf(stderr, "FAIL: test returned ClientHello length %li, " "want %zu\n", len, client_hello_len); fprintf(stderr, "received:\n"); - hexdump(wbuf, len); + hexdump(wbuf, len, NULL); fprintf(stderr, "test data:\n"); - hexdump(client_hello, client_hello_len); + hexdump(client_hello, client_hello_len, NULL); fprintf(stderr, "\n"); goto failure; } @@ -447,9 +451,9 @@ client_hello_test(int testno, const struct client_hello_test *cht) if (memcmp(client_hello, wbuf, client_hello_len) != 0) { fprintf(stderr, "FAIL: ClientHello differs:\n"); fprintf(stderr, "received:\n"); - hexdump(wbuf, len); + hexdump(wbuf, len, client_hello); fprintf(stderr, "test data:\n"); - hexdump(client_hello, client_hello_len); + hexdump(client_hello, client_hello_len, wbuf); fprintf(stderr, "\n"); goto failure; } -- cgit v1.2.3-55-g6feb