Fix related with reallocation under some optimization situations.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-10-05 09:33:18 +02:00
parent 8f14db677e
commit e5fe638c68
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3

View file

@ -395,10 +395,17 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
uint8_t *tpos = p-asn1_len_tag(tag, tag_len);
memmove(tpos, p, fdata+ef_size-p);
tpos += fdata+ef_size-p;
uintptr_t meta_offset = tpos-fdata;
volatile uintptr_t meta_offset = tpos-fdata;
ef_size += len - (tag_len-2);
if (len > tag_len-2)
fdata = (uint8_t *)realloc(fdata, ef_size);
if (len > tag_len-2) {
uint8_t *fdata_new = (uint8_t *)realloc(fdata, ef_size);
if (fdata_new != NULL)
fdata = fdata_new;
else {
free(fdata);
return CCID_ERR_MEMORY_FATAL;
}
}
uint8_t *f = fdata+meta_offset;
*f++ = fid & 0xff;
f += format_tlv_len(len+2, f);