Skip to content

Commit 34a3049

Browse files
roblablayellows8
authored andcommitted
Improve error handling in elf2kip
1 parent 3c91ce8 commit 34a3049

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/elf2kip.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,18 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
445445
}
446446
desc = (allow_debug & 1) | ((force_debug & 1) << 1);
447447
kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 17) | (0xFFFF));
448+
} else {
449+
fprintf(stderr, "Error: unknown capability %s\n", type_str);
450+
status = 0;
451+
goto PARSE_CAPS_END;
448452
}
449453
}
450454

451455
for (u32 i = cur_cap; i < 0x20; i++) {
452456
kip_hdr->Capabilities[i] = 0xFFFFFFFF;
453457
}
454458

459+
status = 1;
455460
PARSE_CAPS_END:
456461
cJSON_Delete(npdm_json);
457462
return status;
@@ -479,7 +484,10 @@ int main(int argc, char* argv[]) {
479484
return EXIT_FAILURE;
480485
}
481486

482-
ParseKipConfiguration(json, &kip_hdr);
487+
if (!ParseKipConfiguration(json, &kip_hdr)) {
488+
fprintf(stderr, "Failed to parse kip configuration!\n");
489+
return EXIT_FAILURE;
490+
}
483491

484492
size_t elf_len;
485493
uint8_t* elf = ReadEntireFile(argv[1], &elf_len);

0 commit comments

Comments
 (0)