Skip to content

fix: the telink b91 platform provides a custom decla... in string.h#1119

Open
orbisai0security wants to merge 3 commits into
openthread:mainfrom
orbisai0security:fix-remove-unsafe-strcpy-declaration
Open

fix: the telink b91 platform provides a custom decla... in string.h#1119
orbisai0security wants to merge 3 commits into
openthread:mainfrom
orbisai0security:fix-remove-unsafe-strcpy-declaration

Conversation

@orbisai0security
Copy link
Copy Markdown

Summary

Fix critical severity security issue in third_party/telink/b91/common/string.h.

Vulnerability

Field Value
ID V-001
Severity CRITICAL
Scanner multi_agent_ai
Rule V-001
File third_party/telink/b91/common/string.h:70
CWE CWE-120

Description: The Telink B91 platform provides a custom declaration of strcpy() in third_party/telink/b91/common/string.h at line 70. This function performs no bounds checking on the destination buffer. Any call site in the firmware that passes attacker-influenced data — such as strings from Thread network packets, UART input, or commissioning data — to this strcpy() without first validating the source string length against the destination buffer size is vulnerable to a classic stack or heap buffer overflow. The strcpy() function copies bytes from source to destination until a null terminator is encountered, with no mechanism to stop at the destination buffer boundary.

Changes

  • third_party/telink/b91/common/string.h

Verification

  • Build passes
  • Scanner re-scan confirms fix
  • LLM code review passed

Automated security fix by OrbisAI Security

Automated security fix generated by Orbis Security AI
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the strcpy declaration from the Telink B91 string header to mitigate buffer overflow risks. Review feedback points out that strcat remains in the header and poses similar security concerns, and it advises that the suggested alternative, strncpy, requires manual null-termination to ensure safety.

Comment thread third_party/telink/b91/common/string.h Outdated
int strcmp(const char *_s1, const char *_s2);
int strcoll(const char *_s1, const char *_s2);
char * strcpy(char *_s1, const char *_s2);
/* strcpy() removed: use strncpy() with explicit buffer length to prevent buffer overflow */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

While removing strcpy is a positive step for security, this fix is incomplete. The strcat function (line 66) is still present in the header and poses the same buffer overflow risks (CWE-120) as strcpy. To fully address the security concerns mentioned in the PR description, strcat should also be removed or deprecated in favor of strncat.\n\nAdditionally, the suggestion to use strncpy should be accompanied by a warning that it does not guarantee null-termination if the source string is longer than the destination buffer. A safer pattern is to use strncpy followed by manual null-termination of the last byte.

/* strcpy() removed: use strncpy() with destination buffer size and manual null-termination */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@orbisai0security can you address code review comments?

@orbisai0security
Copy link
Copy Markdown
Author

Changes Applied

I've updated the code based on your feedback:

The code review (by @gemini-code-assist) correctly identified that strcat poses the same CWE-120 buffer-overflow risk as strcpy. Just like strcpy was removed and replaced with a deprecation comment pointing users to the safer bounded alternative, we apply the same treatment to strcat. The safe replacement strncat is already declared in the header (line 74), so removing the unsafe strcat declaration leaves callers a clear, safe path forward.

Files modified:

  • third_party/telink/b91/common/string.h

The changes have been pushed to this PR branch. Please review!

@orbisai0security
Copy link
Copy Markdown
Author

Review Feedback Addressed

I've automatically addressed 1 review comment(s):

The file already has strcat() removed (line 66) and strcpy() removed (line 70). The one remaining actionable item from the review is updating the strcpy() comment to warn that strncpy() does not guarantee null-termination when the source is longer than the destination buffer, and that manual null-termination is required. This matches the reviewer's suggested safer comment pattern.

Files modified:

  • third_party/telink/b91/common/string.h

The changes have been pushed to this PR branch. Please review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants