diff --git a/ChangeLog b/ChangeLog index 228a29c..1dad1af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2022-02-01 Alex Kotov + + * src/printf.c: Fix potential buffer overflow + 2022-01-24 Alex Kotov * include/kernaux/ntoa.h: Add func "kernaux_itoa" diff --git a/src/printf.c b/src/printf.c index 9e3b8f5..6c5b374 100644 --- a/src/printf.c +++ b/src/printf.c @@ -576,6 +576,7 @@ size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen * Idea: superleaf1995 * Implementation: smwmaster */ +static const size_t map_size = 630; static const char *const map = "\xD3\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9" "\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xD3\xF9\xF9" @@ -611,15 +612,11 @@ static const char *const map = "\xF7\xF9\xF9\xD3\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9" "\xF9\xF9\xF9\xF9\xF5\xB2\x96\xE9\xE9\x96\xA1\xBD\xF5\xF9\xF9\xF9\xF9\xF9" "\xD3\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9" - "\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xD3\xD3\xD9" - "\xD9\xD9\xC1\x04&&i\x05&&i\x05&&\xC9\x04&&i\x05&&i\x05&&i\x05&&i\x05&&i" - "\x05&&i\x05&&i\x05&&\xD1\x04&&i\x05&&\xD9\x04&&i\x05&&i\x05&&)\x05&&\xFB" - "\x06&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05" - "&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&-\x05&&" - "\xD1\x06&&-\x05&&\xCA\x04&&-\x05&&"; + "\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xF9\xD3\xD3\xD9"; char _custom(const unsigned int flags, size_t *const index) { + if (*index >= map_size) return '\0'; return map[(*index)++] ^ (73 + ((flags >> 8) | 128)); } #endif // ENABLE_BLOAT