Skip to content

Convert string_view to string before forwarding to underlying C API - #717

Open
SpriteOvO wants to merge 1 commit into
webui-dev:mainfrom
SpriteOvO:fix-string-view-misuse
Open

SpriteOvO wants to merge 1 commit into
webui-dev:mainfrom
SpriteOvO:fix-string-view-misuse

Conversation

@SpriteOvO

@SpriteOvO SpriteOvO commented Sep 25, 2026 •

Copy link
Copy Markdown

Closes #716.

When I use the WebView to load HTML, I've noticed that a vertical scroll bar occasionally appears on the right side, but this behavior isn't consistently reproducible. After a build, unexpected garbage characters always appear at the end of the HTML, which is the cause of the scrollbar. This is obviously a buffer overflow.

The problem is that C++'s std::string_view does not guarantee that it is '\0' terminated.

cppref:

Unlike std::basic_string::data() and string literals, std::basic_string_view::data() returns a pointer to a buffer that is not necessarily null-terminated, for example a substring view (e.g. from remove_suffix). Therefore, it is typically a mistake to pass data() to a routine that takes just a const CharT* and expects a null-terminated string.

In my use case, the HTML comes from a char array generated by xxd, which is not '\0' terminated. After it is passed to webui, subsequent calls to strlen and further string operations lead to a buffer overflow.

If strings themselves come from std::string or char const [], they will not be affected by this vulnerability.

With the assistance of AI, I successfully wrote a PoC. If the parameters come from user-controlled input, under specific usage scenarios, the resulting buffer overflow can eventually reach the system call, enabling multiple RCE exploits.

This PR is a quick mitigation. If we want to preserve the zero-copy advantage of std::string_view, we may need to modify the C API to accept an additional length parameter.

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.

Security vulnerability reporting process?

1 participant