]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests/psk-importer.c: Add check for gnutls_malloc to avoid potential NULL pointer...
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Sat, 2 Aug 2025 23:10:32 +0000 (23:10 +0000)
committerDaiki Ueno <ueno@gnu.org>
Mon, 4 Aug 2025 05:10:26 +0000 (14:10 +0900)
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 <jiashengjiangcool@gmail.com>
tests/psk-importer.c

index c747bad52893b299165848080dffb1cf3c8d76d0..41b38d31ca9f2cee9a550657075a99016bb93a0b 100644 (file)
@@ -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;