From: Nikos Mavrogiannopoulos Date: Mon, 29 Feb 2016 09:18:58 +0000 (+0100) Subject: pkcs11: Fixes to prevent undefined behavior (found with libubsan) X-Git-Tag: gnutls_3_5_0~288 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bf89ef06091cd24d88fec19963b9c25b2e91e5e;p=thirdparty%2Fgnutls.git pkcs11: Fixes to prevent undefined behavior (found with libubsan) --- diff --git a/lib/pkcs11.c b/lib/pkcs11.c index dd22e4caef..b2508d4ed4 100644 --- a/lib/pkcs11.c +++ b/lib/pkcs11.c @@ -2998,7 +2998,8 @@ gnutls_pkcs11_obj_list_import_url3(gnutls_pkcs11_obj_t * p_list, } *n_list = priv.current; - memcpy(p_list, priv.p_list, priv.current*sizeof(p_list[0])); + if (p_list) + memcpy(p_list, priv.p_list, priv.current*sizeof(p_list[0])); gnutls_free(priv.p_list); return 0; diff --git a/lib/pkcs11_int.h b/lib/pkcs11_int.h index 272e426ae2..0855787690 100644 --- a/lib/pkcs11_int.h +++ b/lib/pkcs11_int.h @@ -142,7 +142,7 @@ ck_object_class_t pkcs11_strtype_to_class(const char *type); * @GNUTLS_PKCS11_OBJ_FLAG_EXPECT_PRIVKEY: Hint for private key */ #define GNUTLS_PKCS11_OBJ_FLAG_EXPECT_CERT (1<<29) #define GNUTLS_PKCS11_OBJ_FLAG_EXPECT_PRIVKEY (1<<30) -#define GNUTLS_PKCS11_OBJ_FLAG_EXPECT_PUBKEY (1<<31) +#define GNUTLS_PKCS11_OBJ_FLAG_EXPECT_PUBKEY ((unsigned int)1<<31) int pkcs11_token_matches_info(struct p11_kit_uri *info, struct ck_token_info *tinfo,