From 5c43ed4ea7c0da5f2af91f69f3e439edc0b86b02 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 19 Oct 2017 13:03:40 -0700 Subject: [PATCH] quotearg: pacify compiler re unsigned * lib/quotearg.c (quotearg_n_options): Rewrite to avoid diagnostic from overly-picky compiler. Problem reported by Sami Kerola in: https://lists.gnu.org/archive/html/bug-gnulib/2017-10/msg00060.html --- ChangeLog | 6 ++++++ lib/quotearg.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e662c02a5..ed34aa80f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2017-10-19 Paul Eggert + quotearg: pacify compiler re unsigned + * lib/quotearg.c (quotearg_n_options): + Rewrite to avoid diagnostic from overly-picky compiler. + Problem reported by Sami Kerola in: + https://lists.gnu.org/archive/html/bug-gnulib/2017-10/msg00060.html + glob: fix heap buffer overflow * lib/glob.c (glob): Fix off-by-one error introduced into glibc in commit dd7d45e838a42b0ed470c44b55901ea98d0c2bab diff --git a/lib/quotearg.c b/lib/quotearg.c index df602698e..8e432e134 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -887,8 +887,9 @@ quotearg_n_options (int n, char const *arg, size_t argsize, if (nslots <= n) { bool preallocated = (sv == &slotvec0); + int nmax = MIN (INT_MAX, MIN (PTRDIFF_MAX, SIZE_MAX) / sizeof *sv) - 1; - if (MIN (INT_MAX, MIN (PTRDIFF_MAX, SIZE_MAX) / sizeof *sv) <= n) + if (nmax < n) xalloc_die (); slotvec = sv = xrealloc (preallocated ? NULL : sv, (n + 1) * sizeof *sv); -- 2.13.6