fru: Fix crashes on 6-bit ASCII strings

Fix calculation of the buffer size for decoded 6-bit ASCII
strings. Previously the program could allocate too a short buffer
that caused buffer overflows and segmentation fault crashes on
certain FRU contents.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
Alexander Amelkin 2020-09-15 16:49:20 +03:00 committed by Alexander Amelkin
parent 50d8c36edf
commit 1245aaa387

View File

@ -175,8 +175,8 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
size = (len * 2); size = (len * 2);
break; break;
case 2: /* 10b: 6-bit ASCII */ case 2: /* 10b: 6-bit ASCII */
/* 4 chars per group of 1-3 bytes */ /* 4 chars per group of 1-3 bytes, round up to 4 bytes boundary */
size = (((len * 4 + 2) / 3) & ~3); size = (len / 3 + 1) * 4;
break; break;
case 3: /* 11b: 8-bit ASCII */ case 3: /* 11b: 8-bit ASCII */
/* no length adjustment */ /* no length adjustment */