Commit 4e04b2d5 authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

server: Replace some malloc/sprintf/strcpy calls with asprintf.

parent d7cf25dc
...@@ -601,9 +601,8 @@ static void create_dir( const char *name, struct stat *st ) ...@@ -601,9 +601,8 @@ static void create_dir( const char *name, struct stat *st )
static char *create_server_dir( int force ) static char *create_server_dir( int force )
{ {
const char *prefix = getenv( "WINEPREFIX" ); const char *prefix = getenv( "WINEPREFIX" );
char *p, *config_dir; char *p, *config_dir, *base_dir;
struct stat st, st2; struct stat st, st2;
size_t len = sizeof("/server-") + 2 * sizeof(st.st_dev) + 2 * sizeof(st.st_ino) + 2;
/* open the configuration directory */ /* open the configuration directory */
...@@ -646,23 +645,19 @@ static char *create_server_dir( int force ) ...@@ -646,23 +645,19 @@ static char *create_server_dir( int force )
/* create the base directory if needed */ /* create the base directory if needed */
#ifdef __ANDROID__ /* there's no /tmp dir on Android */ #ifdef __ANDROID__ /* there's no /tmp dir on Android */
len += strlen( config_dir ) + sizeof("/.wineserver"); if (asprintf( &base_dir, "%s/.wineserver", config_dir ) == -1)
if (!(server_dir = malloc( len ))) fatal_error( "out of memory\n" ); fatal_error( "out of memory\n" );
strcpy( server_dir, config_dir );
strcat( server_dir, "/.wineserver" );
#else #else
len += sizeof("/tmp/.wine-") + 12; if (asprintf( &base_dir, "/tmp/.wine-%u", getuid() ) == -1)
if (!(server_dir = malloc( len ))) fatal_error( "out of memory\n" ); fatal_error( "out of memory\n" );
sprintf( server_dir, "/tmp/.wine-%u", getuid() );
#endif #endif
create_dir( server_dir, &st2 ); create_dir( base_dir, &st2 );
/* now create the server directory */ /* now create the server directory */
strcat( server_dir, "/server-" ); if (asprintf( &server_dir, "%s/server-%llx-%llx", base_dir,
p = server_dir + strlen(server_dir); (unsigned long long)st.st_dev, (unsigned long long)st.st_ino ) == -1)
fatal_error( "out of memory\n" );
sprintf( p, "%llx-%llx", (unsigned long long)st.st_dev, (unsigned long long)st.st_ino );
create_dir( server_dir, &st ); create_dir( server_dir, &st );
...@@ -675,6 +670,7 @@ static char *create_server_dir( int force ) ...@@ -675,6 +670,7 @@ static char *create_server_dir( int force )
if (st.st_dev != st2.st_dev || st.st_ino != st2.st_ino) if (st.st_dev != st2.st_dev || st.st_ino != st2.st_ino)
fatal_error( "chdir did not end up in %s\n", server_dir ); fatal_error( "chdir did not end up in %s\n", server_dir );
free( base_dir );
free( config_dir ); free( config_dir );
return server_dir; return server_dir;
} }
......
...@@ -265,11 +265,7 @@ static char *get_nls_dir(void) ...@@ -265,11 +265,7 @@ static char *get_nls_dir(void)
} }
*(++p) = 0; *(++p) = 0;
if (p > dir + 8 && !strcmp( p - 8, "/server/" )) nlsdir = "../nls"; /* inside build tree */ if (p > dir + 8 && !strcmp( p - 8, "/server/" )) nlsdir = "../nls"; /* inside build tree */
if ((ret = malloc( strlen(dir) + strlen( nlsdir ) + 1 ))) asprintf( &ret, "%s%s", dir, nlsdir );
{
strcpy( ret, dir );
strcat( ret, nlsdir );
}
free( dir ); free( dir );
return ret; return ret;
} }
...@@ -292,9 +288,7 @@ struct fd *load_intl_file(void) ...@@ -292,9 +288,7 @@ struct fd *load_intl_file(void)
for (i = 0; i < ARRAY_SIZE( nls_dirs ); i++) for (i = 0; i < ARRAY_SIZE( nls_dirs ); i++)
{ {
if (!nls_dirs[i]) continue; if (!nls_dirs[i]) continue;
if (!(path = malloc( strlen(nls_dirs[i]) + sizeof("/l_intl.nls" )))) continue; if (asprintf( &path, "%s/l_intl.nls", nls_dirs[i] ) == -1) continue;
strcpy( path, nls_dirs[i] );
strcat( path, "/l_intl.nls" );
if ((fd = open_fd( NULL, path, nt_name, O_RDONLY, &mode, FILE_READ_DATA, if ((fd = open_fd( NULL, path, nt_name, O_RDONLY, &mode, FILE_READ_DATA,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ))) break; FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ))) break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment