From 12d362fc731c3c2a5d7b39d5716eaf1f21cc31ee Mon Sep 17 00:00:00 2001 From: Viktor Tarasov Date: Sun, 9 Feb 2014 13:24:51 +0100 Subject: [PATCH] PIV: fix segfault and valgrind issue prototype of 'get-guid' has been changed; valgrind issue: Conditional jump or move depends on uninitialised value(s) at 0x5A0159B: vfprintf (vfprintf.c:1629) by 0x5AC04BF: __vsnprintf_chk (vsnprintf_chk.c:65) by 0x522A665: sc_do_log_va.part.0 (stdio2.h:78) by 0x522A819: sc_do_log (log.c:52) by 0x529462F: piv_card_ctl (card-piv.c:1794) by 0x5232E2F: sc_card_ctl (card.c:772) by 0x52E561D: sc_pkcs15emu_piv_init (pkcs15-piv.c:626) --- src/libopensc/card-piv.c | 9 +++++---- src/libopensc/pkcs15-piv.c | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libopensc/card-piv.c b/src/libopensc/card-piv.c index 2503dfd0..4238c0fe 100644 --- a/src/libopensc/card-piv.c +++ b/src/libopensc/card-piv.c @@ -1790,10 +1790,11 @@ static int piv_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr) piv_private_data_t * priv = PIV_DATA(card); u8 * opts; /* A or M, key_ref, alg_id */ - SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); - sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,"cmd=%ld ptr=%p"); + LOG_FUNC_CALLED(card->ctx); + sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr); + if (priv == NULL) { - SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL); + LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL); } switch(cmd) { case SC_CARDCTL_PIV_AUTHENTICATE: @@ -1824,7 +1825,7 @@ static int piv_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr) break; } - SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED); + LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED); } static int piv_get_challenge(sc_card_t *card, u8 *rnd, size_t len) diff --git a/src/libopensc/pkcs15-piv.c b/src/libopensc/pkcs15-piv.c index dd9ae507..d77eacbb 100644 --- a/src/libopensc/pkcs15-piv.c +++ b/src/libopensc/pkcs15-piv.c @@ -610,6 +610,8 @@ static int sc_pkcs15emu_piv_init(sc_pkcs15_card_t *p15card) SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); + memset(&serial, 0, sizeof(serial)); + /* could read this off card if needed */ /* CSP does not like a - in the name */