From 9802c1448945286d2566eeac595eaa9ecdc3d2cd Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Tue, 24 May 2022 17:50:17 +0200 Subject: [PATCH] reader: more meaningful null pointer check in get_sw At the moment msgb_apdu_de(resp) is used to check if the msgb that is handed over to get_sw is properly populated with data. However, since msgb_apdu_de() is just adding an offset, which cannot be 0 to ->l2h the returned value also can never be NULL. This means that we cannot use msgb_apdu_de() to detect if resp contains a nullpointer. Lets check if ->l2h is not NULL instead. This will make sure that ->l2h is populated. Change-Id: I32bc56c9264c01911a4f4b4f911b09e955205010 Related: OS#5560 --- src/sim/reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sim/reader.c b/src/sim/reader.c index b41b730dc..982b2eef5 100644 --- a/src/sim/reader.c +++ b/src/sim/reader.c @@ -40,7 +40,7 @@ static int get_sw(struct msgb *resp) { int ret; - if (!msgb_apdu_de(resp) || msgb_apdu_le(resp) < 2) + if (!resp->l2h || msgb_apdu_le(resp) < 2) return -EIO; ret = msgb_get_u16(resp);