]> granicus.if.org Git - zfs/commitdiff
Fix possible future overflow in zfs_nicenum
authorChrister Ekholm <che@chrekh.se>
Thu, 19 Feb 2015 21:44:53 +0000 (22:44 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 24 Feb 2015 19:39:10 +0000 (11:39 -0800)
The function zfs_nicenum that converts number to human-readable output
uses a index to a string of letters. This patch limits the index to
the length of the string.

Signed-off-by: Christer Ekholm <che@chrekh.se>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3122

lib/libzfs/libzfs_util.c

index 7f947c186e1bcb11b5a4ade92526844e14ee3c83..d212858d5cd58a8794a47fe6627b84b58292f272 100644 (file)
@@ -571,7 +571,7 @@ zfs_nicenum(uint64_t num, char *buf, size_t buflen)
        int index = 0;
        char u;
 
-       while (n >= 1024) {
+       while (n >= 1024 && index < 6) {
                n /= 1024;
                index++;
        }