Skip to content

Fix UB in to_string(Error) for unrecognized error codes (#18554) (#18554)#18554

Merged
meta-codesync[bot] merged 1 commit intopytorch:mainfrom
alexey-sidnev:export-D97662639
Apr 9, 2026
Merged

Fix UB in to_string(Error) for unrecognized error codes (#18554) (#18554)#18554
meta-codesync[bot] merged 1 commit intopytorch:mainfrom
alexey-sidnev:export-D97662639

Conversation

@alexey-sidnev
Copy link
Copy Markdown
Contributor

@alexey-sidnev alexey-sidnev commented Mar 28, 2026

Summary:
executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:

  1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
  2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Reviewed By: JacobSzwejbka

Differential Revision: D97662639

Pulled By: alexey-sidnev

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 28, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18554

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (3 Unrelated Failures)

As of commit ef47e08 with merge base 2d13fae (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 28, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Mar 28, 2026

@alexey-sidnev has exported this pull request. If you are a Meta employee, you can view the originating Diff in D97662639.

@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync meta-codesync Bot changed the title Fix UB in to_string(Error) for unrecognized error codes Fix UB in to_string(Error) for unrecognized error codes (#18554) Mar 30, 2026
alexey-sidnev pushed a commit to alexey-sidnev/executorch that referenced this pull request Mar 30, 2026
Summary:

executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Differential Revision: D97662639
alexey-sidnev pushed a commit to alexey-sidnev/executorch that referenced this pull request Mar 30, 2026
Summary:
Pull Request resolved: pytorch#18554

executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Differential Revision: D97662639
alexey-sidnev pushed a commit to alexey-sidnev/executorch that referenced this pull request Mar 30, 2026
Summary:

executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Differential Revision: D97662639
alexey-sidnev pushed a commit to alexey-sidnev/executorch that referenced this pull request Mar 30, 2026
Summary:
Pull Request resolved: pytorch#18554

executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Differential Revision: D97662639
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Mar 30, 2026

@alexey-sidnev has imported this pull request. If you are a Meta employee, you can view this in D97662639.

@alexey-sidnev
Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 31, 2026

Mergebot is not configured for this repository. Please use the merge button provided by GitHub.

@meta-codesync meta-codesync Bot changed the title Fix UB in to_string(Error) for unrecognized error codes (#18554) Fix UB in to_string(Error) for unrecognized error codes (#18554) (#18554) Apr 8, 2026
alexey-sidnev added a commit to alexey-sidnev/executorch that referenced this pull request Apr 8, 2026
… (pytorch#18554)

Summary:
executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.


Reviewed By: JacobSzwejbka

Differential Revision: D97662639

Pulled By: alexey-sidnev
alexey-sidnev added a commit to alexey-sidnev/executorch that referenced this pull request Apr 8, 2026
… (pytorch#18554)

Summary:
executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Pull Request resolved: pytorch#18554

Reviewed By: JacobSzwejbka

Differential Revision: D97662639

Pulled By: alexey-sidnev
alexey-sidnev added a commit to alexey-sidnev/executorch that referenced this pull request Apr 8, 2026
… (pytorch#18554)

Summary:
executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.


Reviewed By: JacobSzwejbka

Differential Revision: D97662639

Pulled By: alexey-sidnev
… (pytorch#18554)

Summary:
executorch::runtime::to_string(Error) returns const char* via a switch statement with no default case. For unrecognized error codes, the function falls off the end without returning (undefined behavior), which in practice returns nullptr.

The fix:
1. Adds a fallback return "Error::Unknown" after the switch in to_string() (without a default: case, preserving -Wswitch coverage for missing enum values).
2. Adds tests for to_string() covering all 21 enum values and the unknown error code path.

Pull Request resolved: pytorch#18554

Reviewed By: JacobSzwejbka

Differential Revision: D97662639

Pulled By: alexey-sidnev
@meta-codesync meta-codesync Bot merged commit 84aa213 into pytorch:main Apr 9, 2026
162 of 166 checks passed
jpiat pushed a commit to jpiat/executorch that referenced this pull request Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants