From 7007eda0baa6c1a2d9ef5dfca3adddc32f86bfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20J=C3=A4=C3=A4skel=C3=A4inen?= Date: Tue, 3 Aug 2021 19:51:47 +0300 Subject: [PATCH] pkcs11-spy: fix random crash in print_generic() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Depending on stack state print_generic() could cause crash or spurious garbage in logs. Example crash: *** buffer overflow detected ***: pkcs11test terminated Signed-off-by: Vesa Jääskeläinen --- src/pkcs11/pkcs11-display.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkcs11/pkcs11-display.c b/src/pkcs11/pkcs11-display.c index 15e16de3..0117228d 100644 --- a/src/pkcs11/pkcs11-display.c +++ b/src/pkcs11/pkcs11-display.c @@ -141,7 +141,8 @@ print_generic(FILE *f, CK_LONG type, CK_VOID_PTR value, CK_ULONG size, CK_VOID_P CK_ULONG i; if((CK_LONG)size != -1 && value != NULL) { - char hex[16*3+1], ascii[16+1]; + char hex[16*3+1] = {0}; + char ascii[16+1]; char *hex_ptr = hex, *ascii_ptr = ascii; int offset = 0;