Skip to content

fix(interp): don't fseek(NULL) on M99 in MDI#4095

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/m99-mdi-segfault
Open

fix(interp): don't fseek(NULL) on M99 in MDI#4095
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/m99-mdi-segfault

Conversation

@grandixximo
Copy link
Copy Markdown
Contributor

Problem

Entering M99 as an MDI command crashes milltask with SIGSEGV. Gmoccapy and QTdragon die; AXIS happens to survive. Reported in #4094.

Backtrace:

#5  fseek () from libc.so.6
#6  Interp::loop_to_beginning (...) at emc/rs274ngc/interp_o_word.cc:526
#7  Interp::convert_stop (...) at emc/rs274ngc/interp_convert.cc
#8  Interp::execute_block (...)
...
#12 emcTaskPlanExecute (command="m99", ...)

Cause

Task always enables loop_on_main_m99 (emctask.cc), so M99 in the main program takes the Fanuc endless-loop branch in convert_stop(), which calls loop_to_beginning() -> fseek(settings->file_pointer, 0, SEEK_SET). In MDI there is no open g-code file, so file_pointer is NULL and fseek(NULL) segfaults.

Fix

  • Require file_pointer != NULL to take the M99 loop branch. In MDI, M99 now falls through to the existing M2/M30 program-end path, which already null-guards file_pointer. This matches AXIS-style "end" behavior.
  • Add a defensive NULL check in loop_to_beginning().

Testing

Built against current master. Verified on Gmoccapy: M99 in MDI no longer crashes.

Fixes #4094

Task always enables loop_on_main_m99, so M99 entered as an MDI command
took the Fanuc endless-loop branch in convert_stop() and called
loop_to_beginning() -> fseek(settings->file_pointer, ...). In MDI no
file is open, so file_pointer is NULL and milltask crashed with SIGSEGV.

Require file_pointer != NULL for the loop branch; otherwise MDI M99 now
falls through to the M2/M30 program-end path (already NULL-guarded). Add
a defensive NULL check in loop_to_beginning() as well.

Fixes LinuxCNC#4094
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

M99 can kill Gmoccapy and QTdragon.

1 participant