https://git.reactos.org/?p=reactos.git;a=commitdiff;h=166d83b2065c1b15051a6…
commit 166d83b2065c1b15051a68b8a6092e4d2727f63e
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Mon Feb 3 11:06:44 2025 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Wed Feb 12 16:54:45 2025 +0200
[CRT] Fix cvt to not overflow the buffer on NAN/INF
Fixes crash in msvcrt_winetest printf
---
sdk/lib/crt/stdlib/fcvtbuf.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/sdk/lib/crt/stdlib/fcvtbuf.c b/sdk/lib/crt/stdlib/fcvtbuf.c
index a76b27bc515..18966efcb0b 100644
--- a/sdk/lib/crt/stdlib/fcvtbuf.c
+++ b/sdk/lib/crt/stdlib/fcvtbuf.c
@@ -48,6 +48,21 @@ static char *cvt(double arg, int ndigits, int *decpt, int *sign, char
*buf, int
double fi, fj;
char *p, *p1;
+ if (_isnan(arg))
+ {
+ snprintf(buf, ndigits, "1.#QNAN");
+ *decpt = 0;
+ *sign = 0;
+ return buf;
+ }
+ if (!_finite(arg))
+ {
+ snprintf(buf, ndigits, "1.#INF");
+ *decpt = 0;
+ *sign = 0;
+ return buf;
+ }
+
if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
r2 = 0;
*sign = 0;