Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Memory Access problem, solveable by additional sanity check #23980

Closed
bkubicek opened this issue Apr 1, 2022 · 6 comments
Closed

[BUG] Memory Access problem, solveable by additional sanity check #23980

bkubicek opened this issue Apr 1, 2022 · 6 comments

Comments

@bkubicek
Copy link
Contributor

bkubicek commented Apr 1, 2022

Did you test the latest bugfix-2.0.x code?

No, but I will test it now!

Bug Description

There exists no validation for the array size of "SWITCHING_TOOLHEAD_X_POS" in Configuration.h.
With more than two toolheads, this can lead to a memory access problem in tool_change.cpp, line 507 "grabxpos = toolheadposx[new_tool];"
It will query a "random" x position for a toolhead whose index is larger than the array size from configuration.h.
I am not super familiar with the way the sanity checks are done, so am sadly disabled to add a appropriate sanity check myself.
Additionally, Software endstops were enabled, and not regarded during toolhead changes. Which might or might not be on purpose, depending if the parking locations are supposed to be in "printable" area or not by definition.

Bug Timeline

No response

Expected behavior

Toolhead E3 does not crash into x boundaries, especially with software endstops enabled

Actual behavior

With software endstops enabled, changing the toolhead should not cause the toolhead to move to a "random" x position outside of software endstop limits.
During compiletime, it should be checked if there exists a defined parking position for each of the toolheads.

Steps to Reproduce

No response

Version of Marlin Firmware

2.0.9.3

Printer model

similar e3d toolchanger system, corexy, 3 toolheads

Electronics

BOARD_BTT_OCTOPUS_V1_1

Add-ons

No response

Bed Leveling

ABL Bilinear mesh

Your Slicer

No response

Host Software

No response

Additional information & file uploads

No response

@GMagician
Copy link
Contributor

you may try with:
static_assert(COUNT(toolheadposx) == EXTRUDERS, "SWITCHING_TOOLHEAD_X_POS must be an array EXTRUDERS long.");
just after: constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;

@GMagician
Copy link
Contributor

this kind of check is also done outside sanitycheck.h, for some other arrays

@GMagician
Copy link
Contributor

GMagician commented Apr 1, 2022

I just saw now that SWITCHING_TOOLHEAD_X_POS array is also used in other parts of code. Maybe it's better to really add this somewhere to sanitycheck.h:

#if ANY(SWITCHING_TOOLHEAD, MAGNETIC_SWITCHING_TOOLHEAD, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
  constexpr float thpx[] = SWITCHING_TOOLHEAD_X_POS;
  static_assert(COUNT(thpx) == EXTRUDERS, "SWITCHING_TOOLHEAD_X_POS must be an array EXTRUDERS long.");
#endif

@thisiskeithb
Copy link
Member

Closing since a PR was created: #23985

@bkubicek
Copy link
Contributor Author

bkubicek commented Apr 3, 2022

thanks a bunch!

@github-actions
Copy link

github-actions bot commented Jun 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants