aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2026-04-29 14:00:08 +0200
committerWerner Koch <[email protected]>2026-04-29 14:00:08 +0200
commitf7ded3ce666ca8e27226dfa05b1e6b8636728441 (patch)
tree9e856de5844763ca1869332ecca7817a8ade380b /tests
parentFix out-of-bounds read in vfnameconcat. (diff)
downloadlibgpg-error-f7ded3ce666ca8e27226dfa05b1e6b8636728441.tar.gz
libgpg-error-f7ded3ce666ca8e27226dfa05b1e6b8636728441.zip
Fix possible stack overflow in es_printf for %.100f format.
* configure.ac: Add test for snprintf. * src/gpgrt-int.h: Do not re-map snprintf if KEEP_SYSTEM_SNPRINTF is defined. * src/estream-printf.c (KEEP_SYSTEM_SNPRINTF): Define. (pr_float): Increase static buffer size. Use snprintf for long double. * tests/t-printf.c: Include float.h. (check_large_float): New. -- GnuPG-bug-id: 8240 Reported-by: Dirk Mueller <[email protected]> (AI)
Diffstat (limited to 'tests')
-rw-r--r--tests/t-printf.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/t-printf.c b/tests/t-printf.c
index eb54750..6cbd03f 100644
--- a/tests/t-printf.c
+++ b/tests/t-printf.c
@@ -31,6 +31,7 @@
#include <assert.h>
#include <errno.h>
#include <locale.h>
+#include <float.h>
#define PGM "t-printf"
@@ -418,9 +419,73 @@ check_snprintf (void)
(unsigned int)tmplen, rc, rc2,
(unsigned int)blen, (unsigned int)blen2);
}
+
}
+static void
+check_large_float (void)
+{
+ char *buf, *buf2;
+ double d = DBL_MAX;
+#ifdef HAVE_LONG_DOUBLE
+ long double ld;
+#endif
+
+ errno = ENOENT;
+ buf = gpgrt_bsprintf ("%.100f\n", d);
+ if (!buf)
+ {
+ fail ("format \"%%.100f\" with DBL_MAX failed: errno=%d (%s)\n",
+ errno, strerror (errno));
+ }
+ else if (verbose)
+ show ("format \"%%.100f\" with DBL_MAX: ->%s<-\n", buf);
+
+ buf2 = gpgrt_bsprintf ("%.101f\n", d);
+ if (!buf2)
+ {
+ fail ("format \"%%.101f\" with DBL_MAX failed: errno=%d (%s)\n",
+ errno, strerror (errno));
+ }
+ else if (verbose)
+ show ("format \"%%.100f\" with DBL_MAX: ->%s<-\n", buf2);
+
+ if (strcmp (buf, buf2))
+ fail ("format \"%%.100f\" does not match \"%%.101f\"\n" );
+ gpgrt_free (buf);
+ gpgrt_free (buf2);
+
+#ifdef HAVE_LONG_DOUBLE
+
+ ld = DBL_MAX;
+ buf = gpgrt_bsprintf ("%.100Lf\n", ld);
+ if (!buf)
+ {
+ fail ("format \"%%.100Lf\" with DBL_MAX failed: errno=%d (%s)\n",
+ errno, strerror (errno));
+ }
+ else if (verbose)
+ show ("format \"%%.100Lf\" with DBL_MAX: ->%s<-\n", buf);
+ gpgrt_free (buf);
+
+ ld = LDBL_MAX;
+ buf = gpgrt_bsprintf ("%.100Lf\n", ld);
+ if (buf)
+ {
+ fail ("format \"%%.100Lf\" with LDBL_MAX unexpectly did not fail\n");
+ }
+ else if (verbose)
+ show ("format \"%%.100Lf\" with LDBL_MAX failed as expected\n");
+ gpgrt_free (buf);
+
+#endif /*HAVE_LONG_DOUBLE*/
+}
+
+
+
+
+
struct sfstate_s
{
char *last_result;
@@ -584,6 +649,7 @@ main (int argc, char **argv)
run_tests ();
check_snprintf ();
+ check_large_float ();
check_fprintf_sf ();
check_fwrite ();