[BUG FIX] Add NULL check for fopen return value in process_hex()#2157
[BUG FIX] Add NULL check for fopen return value in process_hex()#2157Anayo-Anyafulu wants to merge 1 commit intoCCExtractor:masterfrom
Conversation
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit c3c5d9c...:
Your PR breaks these cases:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 8de778a...:
Congratulations: Merging this PR would fix the following tests:
All tests passed completely. Check the result page for more info. |
cfsmp3
left a comment
There was a problem hiding this comment.
The NULL check is needed, but the error handling should use fatal() instead of mprint() + return.
Right now, if the file can't be opened, process_hex silently returns and the program exits with success (code 0). The caller in ccextractor.c:253 is a switch case that just breaks after the call — so scripts and users will think processing succeeded when it actually did nothing.
The existing pattern in this same function uses fatal() for the malloc failure on line 367. This should be consistent:
if (!fr)
{
fatal(EXIT_READ_ERROR, "Error: Could not open hex file %s\n", filename);
}(No need to free(line) if you use fatal() since it terminates the process.)
Summary
In process_hex() in src/lib_ccx/general_loop.c, fopen() was called without checking if the returned FILE pointer is NULL. If the file cannot be opened, the subsequent fgets() call would crash with a NULL pointer dereference.
Changes
Testing
Manually verified the fix compiles cleanly.