
The printf family of functions in U-Boot cannot deal with a situation where the caller provides a buffer which turns out to be too small for the format string. This can result in buffer overflows, stack overflows and other bad behavior.
This patch series tidies this up in the common vsprintf.c code.
You can find a discussion of the Linux / U-Boot licensing issues here: http://patchwork.ozlabs.org/patch/116161/
Code Size Impact ----------------
(From Simon Glass sjg@chromium.org) With my ARMv7 compiler (gcc-4.4.3_cos_gg_53174) the code size increase is 328 bytes, about 10% increase to code size vsprintf.o.
The newly added functions (snprintf, vscnprintf, scnprintf) are a total of 116 bytes.
The changes to number(), string() and vsprintf() to make them respect an end pointer increase size by 80, 20 and 80 bytes respectively.
Total text size for existing vsprintf.o functions goes from 0xc10 (3088) to 0xd58 (3416), or 328 bytes. Of this 116 bytes is the new functions and the rest is dealing with the end pointer. There is no data.
With the CONFIG_SYS_VSNPRINT option not defined, the code size impact is 12 bytes, or alternatively zero if the ugly macro patch is applied.
Changes in v2: - Use sizeof(printbuffer) instead of CONFIG_SYS_PBSIZE - Drop patch which changes network code to use snprintf()
Changes in v3: - Move prototypes from common.h to vsprintf.h - Add CONFIG_SYS_VSNPRINT option to enable vsnprintf() functions - Update README with CONFIG_SYS_VSNPRINT docs - Use ADDCH macro to support checking/not checking end pointer - Add ugly macros to reduce code size - Move function documentation into header file
Simon Glass (4): Move vsprintf functions into their own header Add limits.h to hold basic limits vsprintf: Introduce ugly macros to reduce code size vsprintf: Move function documentation into header file
Sonny Rao (2): Add safe vsnprintf and snprintf library functions Make printf and vprintf safe from buffer overruns
README | 6 ++ common/console.c | 10 +- fs/ubifs/ubifs.h | 4 +- include/common.h | 10 +-- include/limits.h | 40 +++++++++ include/vsprintf.h | 180 +++++++++++++++++++++++++++++++++++++++ lib/vsprintf.c | 241 +++++++++++++++++++++++++++++++++------------------- 7 files changed, 386 insertions(+), 105 deletions(-) create mode 100644 include/limits.h create mode 100644 include/vsprintf.h