Skip to content

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

Open
alexey-sidnev wants to merge 2 commits intopytorch:mainfrom
alexey-sidnev:export-D97662639
Open

Fix UB in to_string(Error) for unrecognized error codes (#18554)#18554
alexey-sidnev wants to merge 2 commits intopytorch:mainfrom
alexey-sidnev:export-D97662639

Conversation

@alexey-sidnev
Copy link
Copy Markdown

@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.

Differential Revision: D97662639

@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.

❌ 2 Cancelled Jobs

As of commit c70cfd1 with merge base 3d63ad8 (image):

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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
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
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.

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