From 34bd87940035dbe05ef8495c361581efbb7325eb Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 1 Oct 2019 11:00:06 +0200 Subject: [PATCH] openpgp: Properly free the allocated file structure Resolves: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16879 --- src/libopensc/card-openpgp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c index 2f73a1ab..b8cdd452 100644 --- a/src/libopensc/card-openpgp.c +++ b/src/libopensc/card-openpgp.c @@ -513,6 +513,7 @@ pgp_init(sc_card_t *card) /* explicitly get the full aid */ r = get_full_pgp_aid(card, file); if (r < 0) { + sc_file_free(file); pgp_finish(card); LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD); } @@ -577,8 +578,10 @@ pgp_init(sc_card_t *card) sc_format_path("3f00", &file->path); /* set up the root of our fake file tree */ + /* Transfers ownership of the file to the priv->mf structure */ priv->mf = pgp_new_blob(card, NULL, 0x3f00, file); if (!priv->mf) { + sc_file_free(file); pgp_finish(card); LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); }