Re: [Mingw-w64-public] [PATCH] Fix UB in mkstemp retry loop

2024-03-23 Thread LIU Hao

在 2024-03-23 06:36, Mateusz Mikuła 写道:

Signed-off-by: Mateusz Mikuła 
---
  mingw-w64-crt/misc/mkstemp.c | 12 +---
  1 file changed, 5 insertions(+), 7 deletions(-)



Thanks for the patch. Pushed to master now.


--
Best regards,
LIU Hao



OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH] Fix UB in mkstemp retry loop

2024-03-22 Thread Mateusz Mikuła
Signed-off-by: Mateusz Mikuła 
---
 mingw-w64-crt/misc/mkstemp.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/mingw-w64-crt/misc/mkstemp.c b/mingw-w64-crt/misc/mkstemp.c
index 3b6246540..7291efcc8 100644
--- a/mingw-w64-crt/misc/mkstemp.c
+++ b/mingw-w64-crt/misc/mkstemp.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 

 /*
 The mkstemp() function generates a unique temporary filename from template,
@@ -25,8 +26,8 @@
  */
 int __cdecl mkstemp (char *template_name)
 {
-int i, j, fd, len, index;
-unsigned int r;
+int j, fd, len, index;
+unsigned int i, r;

 /* These are the (62) characters used in temporary filenames. */
 static const char letters[] = 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@@ -41,11 +42,8 @@ int __cdecl mkstemp (char *template_name)
 /* User may supply more than six trailing Xs */
 for (index = len - 6; index > 0 && template_name[index - 1] == 'X'; 
index--);

-/*
-Like OpenBSD, mkstemp() will try at least 2 ** 31 combinations before
-giving up.
- */
-for (i = 0; i >= 0; i++) {
+/* Like OpenBSD, mkstemp() will try 2 ** 31 combinations before giving up. 
*/
+for (i = 0; i <= INT_MAX; i++) {
 for(j = index; j < len; j++) {
 if (rand_s())
 r = rand();
--
2.44.0.windows.1


___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public