Repository navigation
Conversation
The functions that split comma-separated name lists (target_loggers, process_string etc.) copied them into fixed 124-1024 byte stack buffers with strcpy, so a long list overflowed the stack. Use strdup and free. Fixes #2788. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@mads-bertelsen @Lomholy: this fixes #2788. The Union functions that split comma-separated name lists ( The same pattern was in 33 functions in 22 files, not only the two conditionals: @mads-bertelsen, could you review? |
Free-form text area
Please describe what your PR is adding in terms of features or bugfixes:
Fixes #2788. The functions that split comma-separated name lists (
target_loggers,process_stringetc.) copied the input into fixed 124-1024 byte stack buffers withstrcpy. A long list overflowed the stack (SIGTRAP on macOS, silent stack corruption elsewhere).The same pattern was in 33 functions in 22 files, not just the two conditionals named in the issue:
Union_conditional_PSD/_standard, all loggers and abs-loggers,Union_make_material(McStas and McXtrace),Union_NCrystal_materialandshare/union-lib.c. Each now usesstrdupand frees before every return. A copy inside a commented-out block inUnion_conditional_standardis left alone.The edit was done with a script with a dry-run mode; the dry-run diff was reviewed before applying.
Numerical behaviour: none. Same-seed runs (
-n 1e5 -s 42) give identical detector output tomainfor Conditional_test, Logger_test, Test_abs_logger_event and Test_abs_logger_nD_scintillator. The reproducer from #2788 crashes onmainand runs on this branch.Declaration of use of AI-tools
Co-Authored-Byline naming the tool, see CONTRIBUTING.mdDevelopment OS / boundary conditions
Please describe what OS you developed and tested your additions on, and if any special dependencies are required:
macOS arm64,
mccode-devconda env. Not tested on Linux, Windows or GPU.PR Checklist for contributing to McStas/McXtrace
My contribution includes patches to an existing component file
mctestutility to test one or more instruments making use of the component (please attachmcviewtestreport as screenshot in comments)mccode-clangformattool to apply the standard McCode component indentation schemeMy work touches / adds to the runtime lib code (.c,.h etc in multiple locations
union-lib.cneeds the Union framework; covered by the Union test instruments above.My PR is meant to fix a specific, existing issue
🤖 Generated with Claude Code