Skip to content

Commit 692a79f

Browse files
committed
bd_info: replace realloc() with stack allocated buffer
1 parent 4a3f5cc commit 692a79f

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/examples/bd_info.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,14 @@ static const char *_num2str(char *buf, size_t buf_size, int i)
4848
return "<undefined>";
4949
}
5050

51-
static const char *_hex2str(const uint8_t *data, size_t len)
51+
static const char *_hex2str(char *str, size_t str_size, const uint8_t *data, size_t len)
5252
{
53-
static char *str = NULL;
5453
size_t i;
5554

55+
if (str_size < 3 || (str_size-1)/2 < len)
56+
return "<overflow>";
5657

57-
char *tmp = (char*)realloc(str, 2*len + 1);
58-
if (tmp)
59-
str = tmp;
60-
else
61-
return "";
6258
*str = 0;
63-
6459
for (i = 0; i < len; i++) {
6560
sprintf(str+2*i, "%02X", data[i]);
6661
}
@@ -211,7 +206,8 @@ int main(int argc, char *argv[])
211206
if (info->aacs_detected) {
212207
printf("libaacs detected : %s\n", _yes_no(info->libaacs_detected));
213208
if (info->libaacs_detected) {
214-
printf("Disc ID : %s\n", _hex2str(info->disc_id, sizeof(info->disc_id)));
209+
char buf[sizeof(info->disc_id) * 2 + 1];
210+
printf("Disc ID : %s\n", _hex2str(buf, sizeof(buf), info->disc_id, sizeof(info->disc_id)));
215211
printf("AACS MKB version : %d\n", info->aacs_mkbv);
216212
printf("AACS handled : %s\n", _yes_no(info->aacs_handled));
217213
if (!info->aacs_handled) {

0 commit comments

Comments
 (0)