From 21ca32717faef7f9753a9443c2da47e32c8ad103 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Sun, 28 Feb 2016 13:33:55 +0000 Subject: [PATCH] Further small fix to regerror() overflow handling, to ensure identical output whether or not there is a zero at the end of the buffer. --- src/pcre2test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pcre2test.c b/src/pcre2test.c index 2ccde8c..100e1d2 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -4779,8 +4779,12 @@ if ((pat_patctl.control & CTL_POSIX) != 0) if (bsize + 8 < pbuffer8_size) memcpy(pbuffer8 + bsize, "DEADBEEF", 8); usize = regerror(rc, &preg, (char *)pbuffer8, bsize); + + /* Inside regerror(), snprintf() is used. If the buffer is too small, some + versions of snprintf() put a zero byte at the end, but others do not. + Therefore, we print a maximum of one less than the size of the buffer. */ - psize = (int)bsize; + psize = (int)bsize - 1; fprintf(outfile, "Failed: POSIX code %d: %.*s\n", rc, psize, pbuffer8); if (usize > bsize) {