]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
src/pkcs11.c: Add check for gnutls_malloc and gnutls_strdup
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Mon, 4 Aug 2025 00:17:10 +0000 (00:17 +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() and gnutls_strdup() to avoid potential NULL pointer dereference.
Fixes: 44541d17 ("p11tool: copy vendor query attributes when listing privkeys")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
src/pkcs11.c

index 5211ccd5d361e61db2a2f2dcf32ef265c77d63d9..3947f4b5b24d771ba8416b240e0c1873e1c2e790 100644 (file)
@@ -322,10 +322,21 @@ void pkcs11_list(FILE *outfile, const char *url, int type, unsigned int flags,
                if (vendor) {
                        objurl = gnutls_malloc(strlen(output) + strlen(vendor) +
                                               1);
+                       if (objurl == NULL) {
+                               fprintf(stderr, "memory error\n");
+                               gnutls_free(output);
+                               app_exit(1);
+                       }
+
                        strcpy(objurl, output);
                        strcat(objurl, vendor);
                } else {
                        objurl = gnutls_strdup(output);
+                       if (objurl == NULL) {
+                               fprintf(stderr, "memory error\n");
+                               gnutls_free(output);
+                               app_exit(1);
+                       }
                }
 
                p = NULL;