Skip to content

Commit

Permalink
bcache: Fix a format string overflow
Browse files Browse the repository at this point in the history
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kent Overstreet <koverstreet@google.com>
  • Loading branch information
Kent Overstreet committed Apr 8, 2013
1 parent 8ef7479 commit 91bbcfc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/md/bcache/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ STRTO_H(strtoull, unsigned long long)
ssize_t bch_hprint(char *buf, int64_t v)
{
static const char units[] = "?kMGTPEZY";
char dec[3] = "";
char dec[4] = "";
int u, t = 0;

for (u = 0; v >= 1024 || v <= -1024; u++) {
Expand All @@ -88,7 +88,7 @@ ssize_t bch_hprint(char *buf, int64_t v)
return sprintf(buf, "%llu", v);

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]);
}
Expand Down

0 comments on commit 91bbcfc

Please sign in to comment.