Skip to content

Commit b0c03eb

Browse files
committed
Fix unchecked fopen() and alloc_demuxer_data() return values in process_hex()
- Add NULL check for fopen() return; call fatal() with appropriate error code if the file cannot be opened, preventing a segfault on fgets(). - Add NULL check for alloc_demuxer_data() return; close the already-opened file handle before calling fatal() to avoid a resource leak. Fixes #2201
1 parent 03ad9e8 commit b0c03eb

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/lib_ccx/general_loop.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,21 @@ void process_hex(struct lib_ccx_ctx *ctx, char *filename)
368368
}
369369
/* const char *mpeg_header="00 00 01 b2 43 43 01 f8 "; // Always present */
370370
FILE *fr = fopen(filename, "rt");
371+
if (fr == NULL)
372+
{
373+
fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED,
374+
"In process_hex: Unable to open file: %s\n", filename);
375+
}
371376
unsigned char *bytes = NULL;
372377
unsigned byte_count = 0;
373378
int warning_shown = 0;
374379
struct demuxer_data *data = alloc_demuxer_data();
380+
if (data == NULL)
381+
{
382+
fclose(fr);
383+
fatal(EXIT_NOT_ENOUGH_MEMORY,
384+
"In process_hex: Out of memory allocating demuxer data.\n");
385+
}
375386
while (fgets(line, max - 1, fr) != NULL)
376387
{
377388
char *c1, *c2 = NULL; // Positions for first and second colons

0 commit comments

Comments
 (0)