Not over yet, but added some more bound checks in string processing.
The old pre-stdio bounded snprintf(3)/vsnprintf(3) custom code
returned the actual length that could be written. On the other
hand, stdio oddly returns "what could have been written". This is
problematic in loops that expect a short write when a buffer overflow
is mitigated, where the next call can become out of bounds. Hence,
instead of directly using these stdio functions, a wrapper function
is now used which returns the actual string length that could be
written (calling strlen(3)), and also make sure that the end of
the buffer ends with '\0'.
prefix_buffer() did no bounds checking at all and this was noted
in its comment; this function now performs bounds checking.