diff --git a/lib/x509/pkcs12_bag.c b/lib/x509/pkcs12_bag.c index 38d01e9..8d71141 100644 --- a/lib/x509/pkcs12_bag.c +++ b/lib/x509/pkcs12_bag.c @@ -587,17 +587,14 @@ gnutls_pkcs12_bag_get_key_id (gnutls_pkcs12_bag_t bag, int indx, gnutls_datum_t * id) { if (bag == NULL) - { - gnutls_assert (); - return GNUTLS_E_INVALID_REQUEST; - } - - if (indx > bag->bag_elements - 1) - { - gnutls_assert (); - return GNUTLS_E_INVALID_REQUEST; - } + return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); + if (indx >= bag->bag_elements) + return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); + + if (bag->element[indx].local_key_id.data == NULL) + return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE); + id->data = bag->element[indx].local_key_id.data; id->size = bag->element[indx].local_key_id.size; diff --git a/src/common.c b/src/common.c index 48f56bd..b61bc0f 100644 --- a/src/common.c +++ b/src/common.c @@ -51,10 +51,10 @@ raw_to_string (const unsigned char *raw, size_t raw_size) static char buf[1024]; size_t i; if (raw_size == 0) - return NULL; + return "(empty)"; if (raw_size * 3 + 1 >= sizeof (buf)) - return NULL; + return "(too large)"; for (i = 0; i < raw_size; i++) { diff --git a/tests/pkcs12-decode/pkcs12 b/tests/pkcs12-decode/pkcs12 index e35004f..6950d0e 100755 --- a/tests/pkcs12-decode/pkcs12 +++ b/tests/pkcs12-decode/pkcs12 @@ -23,24 +23,32 @@ srcdir=${srcdir:-.} CERTTOOL=${CERTTOOL:-../../src/certtool} +DEBUG="" + +if test "x$1" != "x";then + DEBUG="1" +fi ret=0 for p12 in 'client.p12 foobar' noclient.p12 unclient.p12 pkcs12_2certs.p12; do set -- $p12 file=$1 passwd=$2 - $CERTTOOL --p12-info --inder --password "$passwd" \ - --infile $srcdir/$file > out 2>&1 + if test "x$DEBUG" != "x";then + $CERTTOOL -d 99 --p12-info --inder --password "$passwd" \ + --infile $srcdir/$file + else + $CERTTOOL --p12-info --inder --password "$passwd" \ + --infile $srcdir/$file >/dev/null 2>&1 + fi rc=$? if test $rc != 0; then - cat out echo "NEON PKCS12 FATAL $p12" ret=1 else echo "NEON PKCS12 OK $p12" fi done -rm -f out echo "NEON PKCS12 DONE (rc $ret)" exit $ret