]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
vsprintf.c: Always enable CONFIG_SYS_VSNPRINTF
authorTom Rini <trini@konsulko.com>
Thu, 14 Jan 2016 18:02:03 +0000 (13:02 -0500)
committerTom Rini <trini@konsulko.com>
Tue, 19 Jan 2016 13:31:16 +0000 (08:31 -0500)
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 <peng.fan@nxp.com>
Cc: Peter Robinson <pbrobinson@gmail.com>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Adrian Alonso <aalonso@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
13 files changed:
README
configs/bayleybay_defconfig
configs/chromebook_link_defconfig
configs/chromebox_panther_defconfig
configs/coreboot-x86_defconfig
configs/crownbay_defconfig
configs/galileo_defconfig
configs/minnowmax_defconfig
configs/qemu-x86_defconfig
configs/sandbox_defconfig
include/vsprintf.h
lib/Kconfig
lib/vsprintf.c

diff --git a/README b/README
index 9423c349c9a5b3366fc931bcc5881cb9e897f009..ece479315f4cb8152fa86a5e1cd0fca6d21e4603 100644 (file)
--- a/README
+++ b/README
@@ -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.
index f462e059de2e6b3c84928e70e4d0d57a8584c097..0879d1e6a9695b187c1fba2a327997c0a508723a 100644 (file)
@@ -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
index dbfbb97d9484c85d83875f9bfc84721727c62391..baa0ed84be874578e85d044a52a86900be19e68b 100644 (file)
@@ -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
index ed4428fe6d09a6b92a69a556c78d06c24b0f2230..c368cc06c452398b15b0cd21a67fb147e00b736a 100644 (file)
@@ -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
index cd2be18ac4a5951fc92ad78d2b5d19624b10c420..fda0db20236304e23381cd69251b70210810a4a7 100644 (file)
@@ -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
index 932d9ecc4474bb04ac12dda566fa4eb8c847a0bb..6bc4b8d0bf489045beb315ead14f7a8261853d71 100644 (file)
@@ -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
index 0604aa76a5277dbf02c8036b0c1aa1045ebb0136..925d3eee92843faba7303f9a5d75298f479d5dae 100644 (file)
@@ -28,4 +28,3 @@ CONFIG_TIMER=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USE_PRIVATE_LIBGCC=y
-CONFIG_SYS_VSNPRINTF=y
index 864fd1b72f9a87c171992043b5aa0a2202abe75c..af6a8ec3f23bec2b0aeb041e0969f6c205ed7a14 100644 (file)
@@ -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
index 8c86931cf49bbc5dc5f735ef9489bb917a0522be..b0c935ca22cd2ebf730fdc65b0894610588f3ab0 100644 (file)
@@ -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
index 731fc258870ea05d424fa935056675fc0f6aa728..caa7336280a1d45ee507047915159423734004a6 100644 (file)
@@ -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
index b5bc9c1d95fab6c09d6cf637202b10ae57e9f85f..376f5dd32499d54eac281435b9ab24cf2aeb8c3f 100644 (file)
@@ -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 ','
index 9d580e4115e6ac8218a8ca9e4801460010e53f1c..46d7034397c1bae8e48f5d7751b39e8325b0db35 100644 (file)
@@ -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
index 24167a135c020b9629181bb01c369e762d293d80..874a2951f7053ef395cfee8ffe78464eee855039 100644 (file)
@@ -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)