Skip to content

Commit 6ceb50e

Browse files
xhanulikJakuje
authored andcommitted
iso7816.c: Check length of key_ref_len to prevent buffer overrun
1 parent 6923b97 commit 6ceb50e

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

src/libopensc/iso7816.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ iso7816_set_security_env(struct sc_card *card,
10211021
*p++ = 0x83;
10221022
else
10231023
*p++ = 0x84;
1024-
if (env->key_ref_len > 0xFF)
1024+
if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
10251025
return SC_ERROR_INVALID_ARGUMENTS;
10261026
*p++ = env->key_ref_len & 0xFF;
10271027
memcpy(p, env->key_ref, env->key_ref_len);

src/libopensc/opensc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ typedef struct sc_security_env {
251251

252252
unsigned long algorithm_ref;
253253
struct sc_path file_ref;
254-
unsigned char key_ref[8];
254+
unsigned char key_ref[SC_MAX_KEYREF_SIZE];
255255
size_t key_ref_len;
256256
struct sc_path target_file_ref; /* target key file in unwrap operation */
257257

src/libopensc/types.h

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef unsigned char u8;
5050
#define SC_MAX_CRTS_IN_SE 12
5151
#define SC_MAX_SE_NUM 8
5252
#define SC_MAX_PKCS15_EMULATORS 48
53+
#define SC_MAX_KEYREF_SIZE 8
5354

5455
/* When changing this value, pay attention to the initialization of the ASN1
5556
* static variables that use this macro, like, for example,

0 commit comments

Comments
 (0)