From: Jens Axboe Date: Mon, 14 Apr 2014 16:21:11 +0000 (-0600) Subject: num2str: ensure we never access postfix[] out-of-bounds X-Git-Tag: fio-2.1.9~42 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=b7e147d1552c022838f4b9d8f02c477b6f906084 num2str: ensure we never access postfix[] out-of-bounds Signed-off-by: Jens Axboe --- diff --git a/lib/num2str.c b/lib/num2str.c index 12d6f39a..89618688 100644 --- a/lib/num2str.c +++ b/lib/num2str.c @@ -4,6 +4,8 @@ #include "../fio.h" +#define ARRAY_LENGTH(arr) sizeof(arr) / sizeof((arr)[0]) + /* * Cheesy number->string conversion, complete with carry rounding error. */ @@ -46,6 +48,9 @@ char *num2str(unsigned long num, int maxlen, int base, int pow2, int unit_base) if (modulo == -1U) { done: + if (post_index >= ARRAY_LENGTH(postfix)) + post_index = 0; + sprintf(buf, "%lu%s%s", num, postfix[post_index], byte_postfix[byte_post_index]); return buf;