mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
The zipl boot loaders have their own minimalistic libc implementation. In it printf and sprintf use vsprintf for string formatting. Per definition vsprintf assumes that the buffer it writes to is large enough to contain the formatted string and performs no size checks. This is problematic for the boot loaders because the buffer they use are often allocated on the stack. Thus even small changes to the string format can potentially cause buffer overflows on the stack with the well known consequences. Protect against such errors by implementing vsnprintf. Later patches will make use of it. This implementation of vsnprintf only supports a small subset of format options defined in the C standard. In particular it allows the specifiers: * %s (strings) * %o (unsigned int octal) * %u (unsigned int decimal) * %x (unsigned int hexadecimal) Integer specifiers (o, u, and x) always use the long form, i.e. assume the argument to be of type 'unsigned long int'. The length modified 'l' can be given but is ignored. Furthermore, it is possible to provide the optional field width (aligned to the right only) and precision as decimal integer (i.e. not via '*') as well as the flag for zero padding integers (i.e. '0'). The implementation was heavily inspired by the implementation in lib/vsprintf.c from the Linux kernel tree. Signed-off-by: Philipp Rudo <prudo@linux.ibm.com> Reviewed-by: Stefan Haberland <sth@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>