vsprintf.c: Always enable CONFIG_SYS_VSNPRINTF
Subsystems (2)
PATCH 1/3 vsprintf.c: Always enable CONFIG_SYS_VSNPRINTF
Enabling this function always removes some class of string saftey issues. The size change here in general is about 400 bytes and this seems a reasonable trade-off.
---
I ran my usual world build of buildman with size comparison options this time to test this out. The only exception to the general size change here are q8_a23_tablet_800x480 and gt90h_v4 both in the non-SPL case. These both grow by 3780 bytes in the non-SPL case. In all cases except those two, when paired with the gzwrite patch I posted yesterday we gain all of that back, or more.
--- README | 9 --------- configs/bayleybay_defconfig | 1 - configs/chromebook_link_defconfig | 1 - configs/chromebox_panther_defconfig | 1 - configs/coreboot-x86_defconfig | 1 - configs/crownbay_defconfig | 1 - configs/galileo_defconfig | 1 - configs/minnowmax_defconfig | 1 - configs/qemu-x86_defconfig | 1 - configs/sandbox_defconfig | 1 - include/vsprintf.h | 12 ------------ lib/Kconfig | 9 --------- lib/vsprintf.c | 12 ------------ 13 files changed, 51 deletions(-)
README +0 -9
@@ -890,15 +890,6 @@ The following options need to be configured: 'Sane' compilers will generate smaller code if CONFIG_PRE_CON_BUF_SZ is a power of 2 -- Safe printf() functions - Define CONFIG_SYS_VSNPRINTF to compile in safe versions of - the printf() functions. These are defined in - include/vsprintf.h and include snprintf(), vsnprintf() and - so on. Code size increase is approximately 300-500 bytes. - If this option is not given then these functions will - silently discard their buffer size argument - this means - you are not getting any overflow checking in this case. - - Boot Delay: CONFIG_BOOTDELAY - in seconds Delay before automatically booting the default image; set to -1 to disable autoboot.
configs/bayleybay_defconfig +0 -1
@@ -37,4 +37,3 @@ CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_11A=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y
configs/chromebook_link_defconfig +0 -1
@@ -38,5 +38,4 @@ CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_11A=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y CONFIG_TPM=y
configs/chromebox_panther_defconfig +0 -1
@@ -33,5 +33,4 @@ CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_11A=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y CONFIG_TPM=y
configs/coreboot-x86_defconfig +0 -1
@@ -25,5 +25,4 @@ CONFIG_TPM_TIS_LPC=y CONFIG_USB=y CONFIG_DM_USB=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y CONFIG_TPM=y
configs/crownbay_defconfig +0 -1
@@ -36,4 +36,3 @@ CONFIG_DM_USB=y CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y
configs/galileo_defconfig +0 -1
@@ -28,4 +28,3 @@ CONFIG_TIMER=y CONFIG_USB=y CONFIG_DM_USB=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y
configs/minnowmax_defconfig +0 -1
@@ -39,4 +39,3 @@ CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_11A=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y
configs/qemu-x86_defconfig +0 -1
@@ -30,4 +30,3 @@ CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_111=y CONFIG_USE_PRIVATE_LIBGCC=y -CONFIG_SYS_VSNPRINTF=y
configs/sandbox_defconfig +0 -1
@@ -76,7 +76,6 @@ CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y CONFIG_SYS_USB_EVENT_POLL=y -CONFIG_SYS_VSNPRINTF=y CONFIG_CMD_DHRYSTONE=y CONFIG_TPM=y CONFIG_LZ4=y
include/vsprintf.h +0 -12
@@ -124,7 +124,6 @@ int sprintf(char *buf, const char *fmt, ...)int vsprintf (char *buf,const char *fmt,va_list args);char *simple_itoa (ulong i); -#ifdef CONFIG_SYS_VSNPRINTF /** * Format a string and place it in a buffer *
@@ -199,17 +198,6 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);* See the vsprintf() documentation for format string extensions over C99. */ int vscnprintf (char *buf,size_t size,const char *fmt,va_list args); -#else -/* -* Use macros to silently drop the size parameter. Note that the 'cn' -* versions are the same as the 'n' versions since the functions assume -* there is always enough buffer space when !CONFIG_SYS_VSNPRINTF -*/ -#define snprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args) -#define scnprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args) -#define vsnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) -#define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) -#endif /* CONFIG_SYS_VSNPRINTF */ /** * print_grouped_ull() - print a value with digits grouped by ','
lib/Kconfig +0 -9
@@ -27,15 +27,6 @@ config SYS_HZ get_timer() must operate in milliseconds and this option must be set to 1000. -config SYS_VSNPRINTF - bool "Enable safe version of sprintf()" - help - Since sprintf() can overflow its buffer, it is common to use - snprintf() instead, which knows the buffer size and can avoid - overflow. However, this does increase code size slightly (for - Thumb-2, about 420 bytes). Enable this option for safety when - using sprintf() with data you do not control. - config USE_TINY_PRINTF bool "Enable tiny printf() version" help
lib/vsprintf.c +0 -12
@@ -141,7 +141,6 @@ static noinline char *put_dec(char *buf, uint64_t num)#define SMALL 32/* Must be 32 == 0x20 */ #define SPECIAL 64/* 0x */ -#ifdef CONFIG_SYS_VSNPRINTF /* * Macro to add a new character to our output string, but only if it will * fit. The macro moves to the next character position in the output string.
@@ -151,9 +150,6 @@ static noinline char *put_dec(char *buf, uint64_t num) *(str) = (ch); \ ++str; \ }while (0 ) -#else -#define ADDCH (str, ch) (*(str)++ = (ch)) -#endif static char *number(char *buf, char *end, u64 num,int base,int size,int precision,int type)
@@ -441,13 +437,11 @@ static int vsnprintf_internal(char *buf, size_t size, const char *fmt,/* 't' added for ptrdiff_t */ char *end = buf + size; -#ifdef CONFIG_SYS_VSNPRINTF /* Make sure end is always >= buf - do we want this in U-Boot? */ if (end < buf) { end = ((void *)-1 ); size = end - buf; } -#endif str = buf;for (; *fmt ; ++fmt) {
@@ -609,21 +603,16 @@ repeat: flags); } -#ifdef CONFIG_SYS_VSNPRINTF if (size >0 ) {ADDCH (str,'\0' );if (str > end) end[-1 ] ='\0' ; --str; } -#else - *str ='\0' ; -#endif /* the trailing null byte doesn't count towards the total */ return str - buf; } -#ifdef CONFIG_SYS_VSNPRINTF int vsnprintf (char *buf,size_t size,const char *fmt,va_list args) {
@@ -666,7 +655,6 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)return i; } -#endif /* CONFIG_SYS_VSNPRINT */ /** * Format a string and place it in a buffer (va_list version)
Signature · 1 line
2.6.4
PATCH 1/3 vsprintf.c: Always enable CONFIG_SYS_VSNPRINTF
Quoted 11 lines · Tom Rini
Enabling this function always removes some class of string saftey issues. The size change here in general is about 400 bytes and this seems a reasonable trade-off.
Cc Peng Fan <[email protected]>Cc Peter Robinson <[email protected]>Cc Fabio Estevam <[email protected]>Cc Adrian Alonso <[email protected]>Cc Stefano Babic <[email protected]>Cc Hans de Goede <[email protected]>Signed-off-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160119/10e18618/attachment.sig>
PATCH 2/3 axm/taurus: Enable tiny printf in SPL
In reply to Tom RiniBoth of these boards are very close to their limit and with some toolchains such as gcc 5.x are too large. Switch to tiny printf to reclaim some size.
--- configs/axm_defconfig | 1 + configs/taurus_defconfig | 1 + 2 files changed, 2 insertions(+)
configs/axm_defconfig +1 -0
@@ -12,3 +12,4 @@ CONFIG_SYS_EXTRA_OPTIONS="AT91SAM9G20,MACH_TYPE=2068,BOARD_AXM" # CONFIG_CMD_SETEXPR is not set CONFIG_SPI_FLASH=y CONFIG_SPI_FLASH_STMICRO=y +CONFIG_USE_TINY_PRINTF=y
configs/taurus_defconfig +1 -0
@@ -13,3 +13,4 @@ CONFIG_SYS_PROMPT="U-Boot> " # CONFIG_CMD_SETEXPR is not set CONFIG_SPI_FLASH=y CONFIG_SPI_FLASH_STMICRO=y +CONFIG_USE_TINY_PRINTF=y
Signature · 1 line
2.6.4
PATCH 2/3 axm/taurus: Enable tiny printf in SPL
Quoted 4 lines · Tom Rini
Both of these boards are very close to their limit and with some toolchains such as gcc 5.x are too large. Switch to tiny printf to reclaim some size.
Signed-off-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160119/87775de6/attachment.sig>
PATCH 2/3 axm/taurus: Enable tiny printf in SPL
Hello Tom,
Am 19.01.2016 um 19:08 schrieb Tom Rini:
Quoted 8 lines · Tom Rini
Quoted 5 lines
Both of these boards are very close to their limit and with some toolchains such as gcc 5.x are too large. Switch to tiny printf to reclaim some size.
Signed-off-by Tom Rini <[email protected]>Applied to u-boot/master, thanks!
Missed this patch, tested it on the taurus board, works!
Thanks!
bye,
Heiko
Signature · 3 lines
-- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 1/3 vsprintf.c: Always enable CONFIG_SYS_VSNPRINTF
In reply to Tom RiniHi Tom,
Quoted 11 lines · Tom Rini
Enabling this function always removes some class of string saftey issues. The size change here in general is about 400 bytes and this seems a reasonable trade-off.
Cc Peng Fan <[email protected]>Cc Peter Robinson <[email protected]>Cc Fabio Estevam <[email protected]>Cc Adrian Alonso <[email protected]>Cc Stefano Babic <[email protected]>Cc Hans de Goede <[email protected]>Signed-off-by Tom Rini <[email protected]>
Regards,
Peng.
Quoted 253 lines
---
I ran my usual world build of buildman with size comparison options this time to test this out. The only exception to the general size change here areq8_a23_tablet_800x480andgt90h_v4both in the non-SPL case. These both grow by 3780 bytes in the non-SPL case. In all cases except those two, when paired with the gzwrite patch I posted yesterday we gain all of that back, or more.
---README | 9 --------- configs/bayleybay_defconfig | 1 - configs/chromebook_link_defconfig | 1 - configs/chromebox_panther_defconfig | 1 - configs/coreboot-x86_defconfig | 1 - configs/crownbay_defconfig | 1 - configs/galileo_defconfig | 1 - configs/minnowmax_defconfig | 1 - configs/qemu-x86_defconfig | 1 - configs/sandbox_defconfig | 1 - include/vsprintf.h | 12 ------------ lib/Kconfig | 9 --------- lib/vsprintf.c | 12 ------------ 13 files changed, 51 deletions(-)README +0
-10@@ -890,15 +890,6 @@ The following options need to be configured: 'Sane' compilers will generate smaller code if CONFIG_PRE_CON_BUF_SZ is a power of 2 -- Safe printf() functions - Define CONFIG_SYS_VSNPRINTF to compile in safe versions of - the printf() functions. These are defined in - include/vsprintf.h and include snprintf(), vsnprintf() and - so on. Code size increase is approximately 300-500 bytes. - If this option is not given then these functions will - silently discard their buffer size argument - this means - you are not getting any overflow checking in this case. - - Boot Delay: CONFIG_BOOTDELAY - in seconds Delay before automatically booting the default image; set to -1 to disable autoboot.configs/bayleybay_defconfig +0
-0@@ -37,4 +37,3 @@ CONFIG_VIDEO_VESA=y
CONFIG_FRAMEBUFFER_SET_VESA_MODE=yCONFIG_FRAMEBUFFER_VESA_MODE_11A=yCONFIG_USE_PRIVATE_LIBGCC=yconfigs/bayleybay_defconfig +0
-1-CONFIG_SYS_VSNPRINTF=yconfigs/chromebook_link_defconfig +0
-0@@ -38,5 +38,4 @@ CONFIG_VIDEO_VESA=y
CONFIG_FRAMEBUFFER_SET_VESA_MODE=yCONFIG_FRAMEBUFFER_VESA_MODE_11A=yCONFIG_USE_PRIVATE_LIBGCC=y
-CONFIG_SYS_VSNPRINTF=yCONFIG_TPM=yconfigs/chromebox_panther_defconfig +0
-0@@ -33,5 +33,4 @@ CONFIG_VIDEO_VESA=y
CONFIG_FRAMEBUFFER_SET_VESA_MODE=yCONFIG_FRAMEBUFFER_VESA_MODE_11A=yCONFIG_USE_PRIVATE_LIBGCC=y
-CONFIG_SYS_VSNPRINTF=yCONFIG_TPM=yconfigs/coreboot-x86_defconfig +0
-0@@ -25,5 +25,4 @@ CONFIG_TPM_TIS_LPC=y
CONFIG_USB=yCONFIG_DM_USB=yCONFIG_USE_PRIVATE_LIBGCC=y
-CONFIG_SYS_VSNPRINTF=yCONFIG_TPM=yconfigs/crownbay_defconfig +0
-0@@ -36,4 +36,3 @@ CONFIG_DM_USB=y
CONFIG_VIDEO_VESA=yCONFIG_FRAMEBUFFER_SET_VESA_MODE=yCONFIG_USE_PRIVATE_LIBGCC=yconfigs/crownbay_defconfig +0
-1-CONFIG_SYS_VSNPRINTF=yconfigs/galileo_defconfig +0
-0@@ -28,4 +28,3 @@ CONFIG_TIMER=y
CONFIG_USB=yCONFIG_DM_USB=yCONFIG_USE_PRIVATE_LIBGCC=yconfigs/galileo_defconfig +0
-1-CONFIG_SYS_VSNPRINTF=yconfigs/minnowmax_defconfig +0
-0@@ -39,4 +39,3 @@ CONFIG_VIDEO_VESA=y
CONFIG_FRAMEBUFFER_SET_VESA_MODE=yCONFIG_FRAMEBUFFER_VESA_MODE_11A=yCONFIG_USE_PRIVATE_LIBGCC=yconfigs/minnowmax_defconfig +0
-1-CONFIG_SYS_VSNPRINTF=yconfigs/qemu-x86_defconfig +0
-0@@ -30,4 +30,3 @@ CONFIG_VIDEO_VESA=y
CONFIG_FRAMEBUFFER_SET_VESA_MODE=yCONFIG_FRAMEBUFFER_VESA_MODE_111=yCONFIG_USE_PRIVATE_LIBGCC=yconfigs/qemu-x86_defconfig +0
-1-CONFIG_SYS_VSNPRINTF=yconfigs/sandbox_defconfig +0
-0@@ -76,7 +76,6 @@ CONFIG_USB_EMUL=y
CONFIG_USB_STORAGE=yCONFIG_USB_KEYBOARD=yCONFIG_SYS_USB_EVENT_POLL=y
-CONFIG_SYS_VSNPRINTF=yCONFIG_CMD_DHRYSTONE=yCONFIG_TPM=yCONFIG_LZ4=yinclude/vsprintf.h +0
-12@@ -124,7 +124,6 @@ int sprintf(char *buf, const char *fmt, ...)int vsprintf (char *buf,const char *fmt,va_list args);char *simple_itoa (ulong i); -#ifdef CONFIG_SYS_VSNPRINTF /** * Format a string and place it in a buffer * @@ -199,17 +198,6 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);* See the vsprintf() documentation for format string extensions over C99. */ int vscnprintf (char *buf,size_t size,const char *fmt,va_list args); -#else -/* -* Use macros to silently drop the size parameter. Note that the 'cn' -* versions are the same as the 'n' versions since the functions assume -* there is always enough buffer space when !CONFIG_SYS_VSNPRINTF -*/ -#define snprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args) -#define scnprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args) -#define vsnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) -#define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) -#endif /* CONFIG_SYS_VSNPRINTF */ /** * print_grouped_ull() - print a value with digits grouped by ',' lib/Kconfig +0
-9@@ -27,15 +27,6 @@ config SYS_HZ get_timer() must operate in milliseconds and this option must be set to 1000. -config SYS_VSNPRINTF - bool "Enable safe version of sprintf()" - help - Since sprintf() can overflow its buffer, it is common to use - snprintf() instead, which knows the buffer size and can avoid - overflow. However, this does increase code size slightly (for - Thumb-2, about 420 bytes). Enable this option for safety when - using sprintf() with data you do not control. -config
USE_TINY_PRINTF
bool "Enable tinyprintf()version"
helplib/vsprintf.c +0
-12@@ -141,7 +141,6 @@ static noinline char *put_dec(char *buf, uint64_t num)#define SMALL 32/* Must be 32 == 0x20 */ #define SPECIAL 64/* 0x */ -#ifdef CONFIG_SYS_VSNPRINTF /* * Macro to add a new character to our output string, but only if it will * fit. The macro moves to the next character position in the output string. @@ -151,9 +150,6 @@ static noinline char *put_dec(char *buf, uint64_t num) *(str) = (ch); \ ++str; \ }while (0 ) -#else -#define ADDCH (str, ch) (*(str)++ = (ch)) -#endif static char *number(char *buf, char *end, u64 num,int base,int size,int precision,int type)@@ -441,13 +437,11 @@ static int vsnprintf_internal(char *buf, size_t size, const char *fmt,/* 't' added for ptrdiff_t */ char *end = buf + size; -#ifdef CONFIG_SYS_VSNPRINTF /* Make sure end is always >= buf - do we want this in U-Boot? */ if (end < buf) { end = ((void *)-1 ); size = end - buf; } -#endif str = buf;for (; *fmt ; ++fmt) {@@ -609,21 +603,16 @@ repeat: flags); } -#ifdef CONFIG_SYS_VSNPRINTF if (size >0 ) {ADDCH (str,'\0' );if (str > end) end[-1 ] ='\0' ; --str; } -#else - *str ='\0' ; -#endif /* the trailing null byte doesn't count towards the total */ return str - buf; } -#ifdef CONFIG_SYS_VSNPRINTF int vsnprintf (char *buf,size_t size,const char *fmt,va_list args) {@@ -666,7 +655,6 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)return i; } -#endif /* CONFIG_SYS_VSNPRINT */ /** * Format a string and place it in a buffer (va_list version) Signature · 6 lines
2.6.4 _______________________________________________ U-Boot mailing list U-Boot at lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
PATCH 3/3 gunzip.c: Only include gzwrite on CONFIG_CMD_UNZIP
In reply to Tom RiniOnly when we have CONFIG_CMD_UNZIP enabled do we have the 'gzwrite' command. While this command should be separated from CONFIG_CMD_UNZIP we should also only include the write portion of the gz code in that case as well.
--- lib/gunzip.c | 2 ++ 1 file changed, 2 insertions(+)
lib/gunzip.c +2 -0
@@ -70,6 +70,7 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)return zunzip (dst, dstlen, src, lenp,1 , i); } +#ifdef CONFIG_CMD_UNZIP __weak void gzwrite_progress_init (u64 expectedsize) {
@@ -258,6 +259,7 @@ out: return r; } +#endif /* * Uncompress blocks compressed with zlib without headers
Signature · 1 line
2.6.4
PATCH 3/3 gunzip.c: Only include gzwrite on CONFIG_CMD_UNZIP
Quoted 6 lines · Tom Rini
Only when we have
CONFIG_CMD_UNZIPenabled do we have the 'gzwrite' command. While this command should be separated fromCONFIG_CMD_UNZIPwe should also only include the write portion of the gz code in that case as well.Signed-off-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160119/9df69019/attachment.sig>