summaryrefslogtreecommitdiff
path: root/lib/human.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-12-31 13:16:55 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2015-12-31 13:17:37 -0800
commit92bbc1b583743b7e463cdfbcd048d9d52063b8c4 (patch)
treef3e34dd1933a83ad32ee9e381004200d75e06c65 /lib/human.c
parentc86965970adb66e17d5d9a39574b75fc25c56784 (diff)
downloadgnulib-92bbc1b583743b7e463cdfbcd048d9d52063b8c4.tar.gz
human: fix output buffer overrun by 1
* lib/human.c (human_readable): Fix off-by-one typo in buffer calculation that could lead to a one-byte buffer overrun.
Diffstat (limited to 'lib/human.c')
-rw-r--r--lib/human.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/human.c b/lib/human.c
index 7863f9c7d8..767aaec760 100644
--- a/lib/human.c
+++ b/lib/human.c
@@ -185,7 +185,8 @@ human_readable (uintmax_t n, char *buf, int opts,
if (strlen (l->thousands_sep) <= MB_LEN_MAX)
thousands_sep = l->thousands_sep;
- psuffix = buf + LONGEST_HUMAN_READABLE - HUMAN_READABLE_SUFFIX_LENGTH_MAX;
+ /* Leave room for a trailing space and following suffix. */
+ psuffix = buf + LONGEST_HUMAN_READABLE - 1 - HUMAN_READABLE_SUFFIX_LENGTH_MAX;
p = psuffix;
/* Adjust AMT out of FROM_BLOCK_SIZE units and into TO_BLOCK_SIZE