5485fb
commit ed55fcd2996930bf58b9bb57e9ba7b1f3a753c43
5485fb
Author: Frank Morgner <frankmorgner@gmail.com>
5485fb
Date:   Mon May 18 17:25:32 2020 +0200
5485fb
5485fb
    fixed invalid read
5485fb
    
5485fb
    fixes https://oss-fuzz.com/testcase-detail/5765246676631552
5485fb
5485fb
diff --git a/src/libopensc/pkcs15-gemsafeGPK.c b/src/libopensc/pkcs15-gemsafeGPK.c
5485fb
index e13f3b87..4b80daf2 100644
5485fb
--- a/src/libopensc/pkcs15-gemsafeGPK.c
5485fb
+++ b/src/libopensc/pkcs15-gemsafeGPK.c
5485fb
@@ -205,7 +205,7 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card)
5485fb
 
5485fb
 	u8 sysrec[7];
5485fb
 	int num_keyinfo = 0;
5485fb
-	keyinfo kinfo[8]; /* will loook for 8 keys */
5485fb
+	keyinfo kinfo[9]; /* will look for 9 keys */
5485fb
 	u8 modulus_buf[ 1 + 1024 / 8]; /* tag+modulus */
5485fb
 	u8 *cp;
5485fb
 	char buf[256];
5485fb
@@ -255,9 +255,9 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card)
5485fb
 
5485fb
 	/* There may be more then one key in the directory. */
5485fb
 	/* we need to find them so we can associate them with the */
5485fb
-	/* the certificate.  The files are 0007 to 000f */
5485fb
+	/* the certificate.  The files are 0007 to 000F */
5485fb
 
5485fb
-	for (i = 7; i < 16; i++) {
5485fb
+	for (i = 0x7; i <= 0xF; i++) {
5485fb
 		path.value[0] = 0x00;
5485fb
 		path.value[1] = i;
5485fb
 		path.len = 2;	
5485fb
@@ -297,7 +297,7 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card)
5485fb
 		while (j--) 
5485fb
 			*cp++ =  modulus_buf[j + 1];
5485fb
 		num_keyinfo++;
5485fb
-	} 
5485fb
+	}
5485fb
 
5485fb
 	/* Get the gemsafe data with the cert */
5485fb
 	 sc_format_path("3F000200004", &path);