Skip to content

Comments

embedded-service hid: audit panic paths#658

Merged
jerrysxie merged 3 commits intoOpenDevicePartnership:mainfrom
jerrysxie:panic-audit-embedded-service-hid
Dec 22, 2025
Merged

embedded-service hid: audit panic paths#658
jerrysxie merged 3 commits intoOpenDevicePartnership:mainfrom
jerrysxie:panic-audit-embedded-service-hid

Conversation

@jerrysxie
Copy link
Contributor

@jerrysxie jerrysxie commented Dec 22, 2025

This pull request improves error handling and code safety in the HID command and descriptor encoding/decoding logic. The main changes include replacing unsafe unwrap() calls with proper error handling, and documenting/pacifying potential panics when using slice indexing. These updates make the code more robust and easier to maintain.

Error handling improvements:

  • Replaced all unwrap() calls on Option values with ok_or and appropriate error variants in the Command::from_opcode logic, preventing panics when required fields are missing.

Code safety and documentation:

  • Added comments explaining panic safety and allowed Clippy's indexing_slicing lint in all encoding/decoding functions that use slice indexing, ensuring that buffer length checks are always performed before accessing slices. [1] [2] [3] [4] [5] [6] [7]

Buffer access validation:

  • Updated the Command::SetPower encoding to use get_mut with error handling instead of direct slice indexing, ensuring the buffer is large enough before writing.

@jerrysxie jerrysxie self-assigned this Dec 22, 2025
Copilot AI review requested due to automatic review settings December 22, 2025 02:53
@jerrysxie jerrysxie added the enhancement New feature or request label Dec 22, 2025
@jerrysxie jerrysxie requested a review from kurtjd December 22, 2025 02:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR audits and removes panic paths in the HID service code by replacing unwrap() calls with proper error handling and documenting remaining indexing operations with panic safety comments and clippy allow attributes.

  • Replaces unwrap() calls with ok_or() and proper error types in command parsing
  • Adds panic safety comments and clippy allow attributes to justified indexing operations
  • Converts unsafe indexing to safe get_mut() for SetPower command encoding

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
embedded-service/src/hid/mod.rs Adds panic safety comments and clippy allow attributes to descriptor encode/decode functions
embedded-service/src/hid/command.rs Replaces unwrap() calls with proper error handling in command parsing; adds panic safety comments to encoding helper functions; converts SetPower encoding to use safe indexing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jerrysxie jerrysxie marked this pull request as ready for review December 22, 2025 03:15
@jerrysxie jerrysxie requested a review from a team as a code owner December 22, 2025 03:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jerrysxie jerrysxie enabled auto-merge (squash) December 22, 2025 23:23
@jerrysxie jerrysxie merged commit 96b3d2e into OpenDevicePartnership:main Dec 22, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants