regerror
returns the number of bytes that are needed to store the error message. Since the application I'm working with isn't going "deep" in the stack (i.e. no deeply nested function calls) I was thinking about using alloca
(which the application is already using for other purposes) to acquire temporary storage for the error message on the stack (rather than the heap).
Is it safe to assume that the error message (length) will be bounded, so that I don't run into a stack overflow?
Does this open a security hole (by manipulating the used message catalog)?
size_t const length = regerror(status, regex, NULL, 0);
char * const buffer = alloca(length);
size_t const check_length = regerror(status, regex, buffer, length);
assert(check_length == length);