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

sprintf with user controlled format string is unsafe #310

Closed
Aeledfyr opened this issue Dec 31, 2021 · 2 comments
Closed

sprintf with user controlled format string is unsafe #310

Aeledfyr opened this issue Dec 31, 2021 · 2 comments

Comments

@Aeledfyr
Copy link

PlotPieChart and RenderHeatmap call sprintf with a provided format string, which is unsafe.

sprintf(buffer, fmt, (double)values[i]);
sprintf(buff, fmt, values[i]);

This can lead to a simple buffer overflow, if the provided format string causes >32 characters of output, but it may also allow writing to arbitrary memory locations by using %n and reading local stack addresses using %p.

I don't know if there are ways to handle the second two issues, but using snprintf instead of sprintf should prevent potential buffer overflows.

@epezent
Copy link
Owner

epezent commented Jan 30, 2022

168244e makes the change to snprintf. Regarding the second issue, ImGui allows users to provide custom format strings throughout its API for various widgets. Do those functions also present the same issue, or is ImGui taking special precauations we should also be taking?

@epezent
Copy link
Owner

epezent commented Jan 30, 2022

Curious, I followed ImGui's format strings all the way through and it doesn't seem ImGui is doing anything special -- all format strings go to vsnprintf without additional checks.

In doing so, I discovered that ImGui wraps raw calls to vsnprintf inside of ImFormatString, which can be override by the user using imconfig.h. I have decided to replace all of our calls to snprintf with ImFormatString so that ImPlot will also honor the user's override (86f4dd6). I suppose one could intercept malicious format arguements there if desired.

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

No branches or pull requests

2 participants