From 43504135adb30eee661ed9b194d4de2bd36c9cfc Mon Sep 17 00:00:00 2001 From: liquor <1692257904@qq.com> Date: Mon, 21 Sep 2020 10:43:01 +0800 Subject: [PATCH] myeid: fixed memory leak --- myeid-fixed-memory-leak.patch | 61 +++++++++++++++++++++++++++++++++++ opensc.spec | 7 +++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 myeid-fixed-memory-leak.patch diff --git a/myeid-fixed-memory-leak.patch b/myeid-fixed-memory-leak.patch new file mode 100644 index 0000000..68fd2c9 --- /dev/null +++ b/myeid-fixed-memory-leak.patch @@ -0,0 +1,61 @@ +From b119781b0218cdbc5b5a060f9a4e8555a25c8b1d Mon Sep 17 00:00:00 2001 +From: Frank Morgner +Date: Wed, 29 Jan 2020 13:34:22 +0100 +Subject: [PATCH] myeid: fixed memory leak + +Credits to OSS-Fuzz + +Fixes https://oss-fuzz.com/testcase-detail/5671550682660864 +--- + src/libopensc/card-myeid.c | 15 ++++++++++++--- + 1 file changed, 12 insertions(+), 3 deletions(-) + +diff --git a/src/libopensc/card-myeid.c b/src/libopensc/card-myeid.c +index 57779ec..677e068 100644 +--- a/src/libopensc/card-myeid.c ++++ b/src/libopensc/card-myeid.c +@@ -176,6 +176,7 @@ static int myeid_init(struct sc_card *card) + size_t resp_len = 0; + static struct sc_aid myeid_aid = { "\xA0\x00\x00\x00\x63\x50\x4B\x43\x53\x2D\x31\x35", 0x0C }; + int rv = 0; ++ void *old_drv_data = card->drv_data; + + LOG_FUNC_CALLED(card->ctx); + +@@ -200,14 +201,14 @@ static int myeid_init(struct sc_card *card) + + /* Ensure that the MyEID applet is selected. */ + rv = myeid_select_aid(card, &myeid_aid, NULL, &resp_len); +- LOG_TEST_RET(card->ctx, rv, "Failed to select MyEID applet."); ++ LOG_TEST_GOTO_ERR(card->ctx, rv, "Failed to select MyEID applet."); + + /* find out MyEID version */ + + appletInfoLen = 20; + + if (0 > myeid_get_info(card, appletInfo, appletInfoLen)) +- LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "Failed to get MyEID applet information."); ++ LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to get MyEID applet information."); + + priv->change_counter = appletInfo[19] | appletInfo[18] << 8; + +@@ -286,7 +287,15 @@ static int myeid_init(struct sc_card *card) + card->max_recv_size = 255; + card->max_send_size = 255; + +- LOG_FUNC_RETURN(card->ctx, SC_SUCCESS); ++ rv = SC_SUCCESS; ++ ++err: ++ if (rv < 0) { ++ free(priv); ++ card->drv_data = old_drv_data; ++ } ++ ++ LOG_FUNC_RETURN(card->ctx, rv); + } + + static const struct sc_card_operations *iso_ops = NULL; +-- +1.8.3.1 + diff --git a/opensc.spec b/opensc.spec index c5e7e27..564d989 100644 --- a/opensc.spec +++ b/opensc.spec @@ -3,12 +3,14 @@ Name: opensc Version: 0.20.0 -Release: 2 +Release: 3 License: LGPLv2.1+ Summary: Smart card library and applications URL: https://github.com/OpenSC/OpenSC/wiki Source0: https://github.com/OpenSC/OpenSC/releases/download/%{version}/%{name}-%{version}.tar.gz +Patch0: myeid-fixed-memory-leak.patch + BuildRequires: openssl-devel pcsc-lite-devel bash-completion docbook-style-xsl readline-devel BuildRequires: desktop-file-utils /usr/bin/xsltproc autoconf automake libtool gcc Requires: pcsc-lite @@ -131,6 +133,9 @@ make check %{_sysconfdir}/xdg/autostart/pkcs11-register.desktop %changelog +* Mon Sep 21 2020 liquor - 0.20.0-3 +- myeid: fixed memory leak + * Fri Feb 14 2020 openEuler Buildteam - 0.20.0-2 - Make check after installation -- Gitee