Commit 91bbcfc3 authored by Kent Overstreet's avatar Kent Overstreet

bcache: Fix a format string overflow

Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarKent Overstreet <koverstreet@google.com>
parent 8ef74790
...@@ -76,7 +76,7 @@ STRTO_H(strtoull, unsigned long long) ...@@ -76,7 +76,7 @@ STRTO_H(strtoull, unsigned long long)
ssize_t bch_hprint(char *buf, int64_t v) ssize_t bch_hprint(char *buf, int64_t v)
{ {
static const char units[] = "?kMGTPEZY"; static const char units[] = "?kMGTPEZY";
char dec[3] = ""; char dec[4] = "";
int u, t = 0; int u, t = 0;
for (u = 0; v >= 1024 || v <= -1024; u++) { for (u = 0; v >= 1024 || v <= -1024; u++) {
...@@ -88,7 +88,7 @@ ssize_t bch_hprint(char *buf, int64_t v) ...@@ -88,7 +88,7 @@ ssize_t bch_hprint(char *buf, int64_t v)
return sprintf(buf, "%llu", v); return sprintf(buf, "%llu", v);
if (v < 100 && v > -100) if (v < 100 && v > -100)
sprintf(dec, ".%i", t / 100); snprintf(dec, sizeof(dec), ".%i", t / 100);
return sprintf(buf, "%lli%s%c", v, dec, units[u]); return sprintf(buf, "%lli%s%c", v, dec, units[u]);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment