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

Don't use alloca() or variable-sized arrays in rust_printf.c #317

Open
Taowyoo opened this issue Sep 14, 2023 · 0 comments
Open

Don't use alloca() or variable-sized arrays in rust_printf.c #317

Taowyoo opened this issue Sep 14, 2023 · 0 comments

Comments

@Taowyoo
Copy link
Collaborator

Taowyoo commented Sep 14, 2023

So this comment isn't specific to the change you're making here, since you're just changing a GNU variable-length array on the stack to an explicit alloca(), which is equivalent. But it's not a good idea to use either a variable-length array on the stack or an alloca() with an unbounded size. This allocation is on the stack, and neither the variable-length array allocation nor the alloca() can actually fail. This can result in stack overflow, which could result in security issues depending on the exact nature of the overflow.

There are basically two ways this could be fixed. Either setting an upper bound on the log message length (and simply truncating if the log message is longer than that), or allocating the buffer on the heap. If you're setting a maximum buffer size anad using the stack, then you may as well just use the fixed maximum size as the size of your array so you don't need alloca(). If you decide to heap allocate, it's probably a good idea to set a maximum size anyway, to reduce the possibility of heap exhaustion and/or attacks based on forcing a lot of heap to be allocated.

Basically: don't use alloca() or variable-sized arrays.

Originally posted by @arai-fortanix in #234 (comment)

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

No branches or pull requests

1 participant