Alexandre Julliard : server: Avoid mkstemps().
Alexandre Julliard
julliard at winehq.org
Tue Oct 5 15:51:41 CDT 2021
Module: wine
Branch: master
Commit: 93609869c89a589588fb5bb176a45ded3a1a05c9
URL: https://source.winehq.org/git/wine.git/?a=commit;h=93609869c89a589588fb5bb176a45ded3a1a05c9
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Oct 5 11:51:42 2021 +0200
server: Avoid mkstemps().
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
server/mapping.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/server/mapping.c b/server/mapping.c
index eb500ea67f4..8a53c2d89d3 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -263,14 +263,29 @@ int grow_file( int unix_fd, file_pos_t new_size )
return 0;
}
+/* simplified version of mkstemps() */
+static int make_temp_file( char name[16] )
+{
+ static unsigned int value;
+ int i, fd = -1;
+
+ value += (current_time >> 16) + current_time;
+ for (i = 0; i < 0x8000 && fd < 0; i++, value += 7777)
+ {
+ sprintf( name, "tmpmap-%08x", value );
+ fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0600 );
+ }
+ return fd;
+}
+
/* check if the current directory allows exec mappings */
static int check_current_dir_for_exec(void)
{
int fd;
- char tmpfn[] = "anonmap.XXXXXX";
+ char tmpfn[16];
void *ret = MAP_FAILED;
- fd = mkstemps( tmpfn, 0 );
+ fd = make_temp_file( tmpfn );
if (fd == -1) return 0;
if (grow_file( fd, 1 ))
{
@@ -286,7 +301,7 @@ static int check_current_dir_for_exec(void)
static int create_temp_file( file_pos_t size )
{
static int temp_dir_fd = -1;
- char tmpfn[] = "anonmap.XXXXXX";
+ char tmpfn[16];
int fd;
if (temp_dir_fd == -1)
@@ -304,7 +319,7 @@ static int create_temp_file( file_pos_t size )
}
else if (temp_dir_fd != server_dir_fd) fchdir( temp_dir_fd );
- fd = mkstemps( tmpfn, 0 );
+ fd = make_temp_file( tmpfn );
if (fd != -1)
{
if (!grow_file( fd, size ))
More information about the wine-cvs
mailing list