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

Potential bug CWE-197 - Numeric Truncation Error found during static … #6137

Open
wants to merge 1 commit into
base: sprint/25Q1
Choose a base branch
from

Conversation

hridhya-narayanan-infosys

…code analysis in webkitbrowser-plugin.

Below warning is raised during Static Code Analysis (SCA) using PVS-Studio in webkitbrowser-plugin component at
https://github.com/rdkcentral/rdkservices/blob/sprint/25Q1/WebKitBrowser/WebKitBrowser.cpp#L57

_skipURL = _service->WebPrefix().length();

[CWE-197] V1029: Numeric Truncation Error. Return value of the 'length' function is written to the 8-bit variable.

In https://github.com/rdkcentral/rdkservices/blob/sprint/25Q1/WebKitBrowser/WebKitBrowser.h#L277 _skipURL is declared as uint8_t datatype which is an unsigned int of 8 bits that can store a value ranging from 0 to 255.

uint8_t _skipURL;

_skipURL value is received from the length of the string returned by _service->WebPrefix() method:

_skipURL = _service->WebPrefix().length();

As per the code, WebPrefix contains the string "/Service/WebKitBrowser" and the values of _skipURL and WebPrefix().length are 22 which is within the range value of uint8_t.

Probably we would never reach more than 255 value here but in theory service->WebPrefix().length() could return something higher when length() is size_t . If the string length exceeds 255 in the future, it could lead to truncation or unexpected behaviour.

So wanted to address this warning with fix.

@hridhya-narayanan-infosys hridhya-narayanan-infosys force-pushed the hridhya-narayanan-infosys/SQ_issue_Numeric_Truncation_Error_sprint_25Q1 branch from 7cbe230 to 99b1d86 Compare March 18, 2025 07:22
@hridhya-narayanan-infosys hridhya-narayanan-infosys force-pushed the hridhya-narayanan-infosys/SQ_issue_Numeric_Truncation_Error_sprint_25Q1 branch from 99b1d86 to bc5f835 Compare March 19, 2025 06:08
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