From: Jiasheng Jiang Date: Sat, 2 Aug 2025 23:10:32 +0000 (+0000) Subject: tests/psk-importer.c: Add check for gnutls_malloc to avoid potential NULL pointer... X-Git-Tag: 3.8.11~21^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d6e45b175c49fc608f64b9beea792f2f64b97bb4;p=thirdparty%2Fgnutls.git tests/psk-importer.c: Add check for gnutls_malloc to avoid potential NULL pointer dereference Add check for the return value of gnutls_malloc() to avoid potential NULL pointer dereference. Fixes: 4fe788cc1 ("psk: Add basic support for RFC 9258 external PSK importer interface") Signed-off-by: Jiasheng Jiang --- diff --git a/tests/psk-importer.c b/tests/psk-importer.c index c747bad528..41b38d31ca 100644 --- a/tests/psk-importer.c +++ b/tests/psk-importer.c @@ -71,6 +71,10 @@ static int server_pskfunc(gnutls_session_t session, printf("psk: Got username with length %d\n", username->size); key->data = gnutls_malloc(4); + if (key->data == NULL) { + return -1; + } + key->data[0] = 0xDE; key->data[1] = 0xAD; key->data[2] = 0xBE; @@ -114,6 +118,11 @@ static int client_pskfunc(gnutls_session_t session, gnutls_datum_t *username, } key->data = gnutls_malloc(4); + if (key->data == NULL) { + gnutls_free(username->data); + return -1; + } + key->data[0] = 0xDE; key->data[1] = 0xAD; key->data[2] = 0xBE;