oberthur: Avoid two buffer overflows
Thanks oss-fuzz https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30112
This commit is contained in:
parent
9c91a4327e
commit
17d8980cde
|
@ -884,12 +884,16 @@ sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
|
||||||
offs = 2;
|
offs = 2;
|
||||||
|
|
||||||
/* Label */
|
/* Label */
|
||||||
if (offs > info_len) {
|
if (offs + 2 > info_len) {
|
||||||
free(info_blob);
|
free(info_blob);
|
||||||
LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'label'");
|
LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'label'");
|
||||||
}
|
}
|
||||||
label = info_blob + offs + 2;
|
label = info_blob + offs + 2;
|
||||||
label_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
|
label_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
|
||||||
|
if (offs + 2 + label_len > info_len) {
|
||||||
|
free(info_blob);
|
||||||
|
LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'label' received");
|
||||||
|
}
|
||||||
if (label_len > sizeof(dobj.label) - 1)
|
if (label_len > sizeof(dobj.label) - 1)
|
||||||
label_len = sizeof(dobj.label) - 1;
|
label_len = sizeof(dobj.label) - 1;
|
||||||
offs += 2 + *(info_blob + offs + 1);
|
offs += 2 + *(info_blob + offs + 1);
|
||||||
|
@ -906,7 +910,7 @@ sc_pkcs15emu_oberthur_add_data(struct sc_pkcs15_card *p15card,
|
||||||
offs += 2 + app_len;
|
offs += 2 + app_len;
|
||||||
|
|
||||||
/* OID encode like DER(ASN.1(oid)) */
|
/* OID encode like DER(ASN.1(oid)) */
|
||||||
if (offs > info_len) {
|
if (offs + 1 > info_len) {
|
||||||
free(info_blob);
|
free(info_blob);
|
||||||
LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'OID'");
|
LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: no 'OID'");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue