diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2012-02-05 23:26:15 -0800 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2012-02-05 23:26:15 -0800 |
commit | f10e5bbfd57d491bf3a5f6521cb8c1c55b713772 (patch) | |
tree | b84455037ac3ae608e1ee65df4963d26241e1a59 /common | |
parent | b36f7d346ccb504547e675b6a0bf31bce75cc175 (diff) | |
download | xrdp-proprietary-f10e5bbfd57d491bf3a5f6521cb8c1c55b713772.tar.gz xrdp-proprietary-f10e5bbfd57d491bf3a5f6521cb8c1c55b713772.zip |
fix for https://bugzilla.redhat.com/show_bug.cgi?id=782619
Diffstat (limited to 'common')
-rw-r--r-- | common/os_calls.c | 78 | ||||
-rw-r--r-- | common/os_calls.h | 4 |
2 files changed, 59 insertions, 23 deletions
diff --git a/common/os_calls.c b/common/os_calls.c index 0993b650..c964a9ff 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010 Jay Sorg + Copyright (c) 2004-2012 Jay Sorg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -79,9 +79,11 @@ extern char** environ; #define INADDR_NONE ((unsigned long)-1) #endif +static char g_temp_base[64] = ""; + /*****************************************************************************/ void APP_CC -g_init(void) +g_init(const char* app_name) { #if defined(_WIN32) WSADATA wsadata; @@ -89,6 +91,17 @@ g_init(void) WSAStartup(2, &wsadata); #endif setlocale(LC_CTYPE, ""); + if (app_name != 0) + { + if (app_name[0] == 0) + { + snprintf(g_temp_base, sizeof(g_temp_base), "/tmp/%s-XXXXXX", app_name); + if (mkdtemp(g_temp_base) == 0) + { + printf("g_init: mkdtemp failed [%s]\n", g_temp_base); + } + } + } } /*****************************************************************************/ @@ -98,6 +111,7 @@ g_deinit(void) #if defined(_WIN32) WSACleanup(); #endif + g_remove_dir(g_temp_base); } /*****************************************************************************/ @@ -700,39 +714,61 @@ g_create_wait_obj(char* name) #else tbus obj; struct sockaddr_un sa; - size_t len = 0; - tbus sck = -1; - int i = 0; - - g_memset(&sa,0,sizeof(struct sockaddr_un)); + size_t len; + tbus sck; + int i; + int safety; + int unnamed; + if (g_temp_base[0] == 0) + { + return 0; + } sck = socket(PF_UNIX, SOCK_DGRAM, 0); if (sck < 0) { return 0; } - memset(&sa, 0, sizeof(sa)); + safety = 0; + g_memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; - if ((name == 0) || (strlen(name) == 0)) + unnamed = 1; + if (name != 0) { - g_random((char*)&i, sizeof(i)); - sprintf(sa.sun_path, "/tmp/auto%8.8x", i); - while (g_file_exist(sa.sun_path)) + if (name[0] != 0) { - g_random((char*)&i, sizeof(i)); - sprintf(sa.sun_path, "/tmp/auto%8.8x", i); + unnamed = 0; } } - else + if (unnamed) { - sprintf(sa.sun_path, "/tmp/%s", name); + do + { + if (safety > 100) + { + break; + } + safety++; + g_random((char*)&i, sizeof(i)); + len = sizeof(sa.sun_path); + g_snprintf(sa.sun_path, len, "%s/auto_%8.8x", g_temp_base, i); + len = sizeof(sa); + } while (bind(sck, (struct sockaddr*)&sa, len) < 0); } - unlink(sa.sun_path); - len = sizeof(sa); - if (bind(sck, (struct sockaddr*)&sa, len) < 0) + else { - close(sck); - return 0; + do + { + if (safety > 100) + { + break; + } + safety++; + g_random((char*)&i, sizeof(i)); + len = sizeof(sa.sun_path); + g_snprintf(sa.sun_path, len, "%s/%s_%8.8x", g_temp_base, name, i); + len = sizeof(sa); + } while (bind(sck, (struct sockaddr*)&sa, len) < 0); } obj = (tbus)sck; return obj; diff --git a/common/os_calls.h b/common/os_calls.h index 62f8b58f..e5625d16 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010 Jay Sorg + Copyright (c) 2004-2012 Jay Sorg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -32,7 +32,7 @@ #include "arch.h" void APP_CC -g_init(void); +g_init(const char* app_name); void APP_CC g_deinit(void); void* APP_CC |