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 co… #5906

Open
wants to merge 1 commit into
base: sprint/24Q4
Choose a base branch
from

Conversation

hridhya-narayanan-infosys

…de 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/24Q4/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/24Q4/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.

@CLAassistant
Copy link

CLAassistant commented Dec 3, 2024

CLA assistant check
All committers have signed the CLA.

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