Skip to content

[BUG] Unchecked fopen() and alloc_demuxer_data() return values in process_hex() in general_loop.c #2201

@Navdeepkaur-11

Description

@Navdeepkaur-11

Summary

In process_hex() in src/lib_ccx/general_loop.c, two return
values are not checked:

  1. fopen() on line 370 — if the file cannot be opened, fr
    is NULL and the subsequent fgets(fr) call will crash
    with a segfault.

  2. alloc_demuxer_data() on line 374 — return value is never
    checked. If allocation fails, data will be NULL and cause
    undefined behavior when used later.

Code

FILE *fr = fopen(filename, "rt");  // ← no NULL check
// ...
struct demuxer_data *data = alloc_demuxer_data();  // ← no NULL check
while (fgets(line, max - 1, fr) != NULL)  // ← crashes if fr is NULL

Suggested Fix

Add NULL checks for both with appropriate fatal() calls,
freeing already-allocated resources before exiting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions