myeid: fixed memory leak

This commit is contained in:
liquor 2020-09-21 10:43:01 +08:00
parent 69458e73f5
commit 7876b4e09b
2 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,61 @@
From b119781b0218cdbc5b5a060f9a4e8555a25c8b1d Mon Sep 17 00:00:00 2001
From: Frank Morgner <frankmorgner@gmail.com>
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

View File

@ -3,12 +3,14 @@
Name: opensc Name: opensc
Version: 0.20.0 Version: 0.20.0
Release: 3 Release: 4
License: LGPLv2.1+ License: LGPLv2.1+
Summary: Smart card library and applications Summary: Smart card library and applications
URL: https://github.com/OpenSC/OpenSC/wiki URL: https://github.com/OpenSC/OpenSC/wiki
Source0: https://github.com/OpenSC/OpenSC/releases/download/%{version}/%{name}-%{version}.tar.gz 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: openssl-devel pcsc-lite-devel bash-completion docbook-style-xsl readline-devel
BuildRequires: desktop-file-utils /usr/bin/xsltproc autoconf automake libtool gcc BuildRequires: desktop-file-utils /usr/bin/xsltproc autoconf automake libtool gcc
Requires: pcsc-lite Requires: pcsc-lite
@ -131,6 +133,9 @@ make check
%{_sysconfdir}/xdg/autostart/pkcs11-register.desktop %{_sysconfdir}/xdg/autostart/pkcs11-register.desktop
%changelog %changelog
* Mon Sep 21 2020 liquor <lirui130@huawei.com> - 0.20.0-4
- myeid: fixed memory leak
* Tue Aug 18 2020 liquor <lirui130@huawei.com> - 0.20.0-3 * Tue Aug 18 2020 liquor <lirui130@huawei.com> - 0.20.0-3
- rebuild for requirement package update - rebuild for requirement package update