Fix unchecked CreateDirectory calls

This commit is contained in:
Norbert Federa 2015-05-05 19:45:34 +02:00
parent e3fb908686
commit f9f59cd29b
6 changed files with 106 additions and 70 deletions

View File

@ -109,19 +109,16 @@ BOOL transport_connect_tls(rdpTransport* transport)
rdpContext* context = transport->context;
rdpSettings* settings = transport->settings;
if (transport->GatewayEnabled)
{
tls = transport->tls = tls_new(settings);
transport->layer = TRANSPORT_LAYER_TSG_TLS;
}
else
{
tls = transport->tls = tls_new(settings);
transport->layer = TRANSPORT_LAYER_TLS;
}
if (!(tls = tls_new(settings)))
return FALSE;
transport->tls = tls;
if (transport->GatewayEnabled)
transport->layer = TRANSPORT_LAYER_TSG_TLS;
else
transport->layer = TRANSPORT_LAYER_TLS;
tls->hostname = settings->ServerHostname;
tls->port = settings->ServerPort;

View File

@ -42,66 +42,75 @@ static const char certificate_known_hosts_file[] = "known_hosts";
#define TAG FREERDP_TAG("crypto")
int certificate_store_init(rdpCertificateStore* certificate_store)
BOOL certificate_store_init(rdpCertificateStore* certificate_store)
{
char* server_path;
char* server_path = NULL;
rdpSettings* settings;
settings = certificate_store->settings;
if (!PathFileExistsA(settings->ConfigPath))
{
CreateDirectoryA(settings->ConfigPath, 0);
if (!CreateDirectoryA(settings->ConfigPath, 0))
{
WLog_ERR(TAG, "error creating directory '%s'", settings->ConfigPath);
goto fail;
}
WLog_INFO(TAG, "creating directory %s", settings->ConfigPath);
}
certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir);
if (!certificate_store->path)
return -1;
if (!(certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir)))
goto fail;
if (!PathFileExistsA(certificate_store->path))
{
CreateDirectoryA(certificate_store->path, 0);
WLog_INFO(TAG, "creating directory %s", certificate_store->path);
if (!CreateDirectoryA(certificate_store->path, 0))
{
WLog_ERR(TAG, "error creating directory [%s]", certificate_store->path);
goto fail;
}
WLog_INFO(TAG, "creating directory [%s]", certificate_store->path);
}
server_path = GetCombinedPath(settings->ConfigPath, (char*) certificate_server_dir);
if (!server_path)
return -1;
if (!(server_path = GetCombinedPath(settings->ConfigPath, (char*) certificate_server_dir)))
goto fail;
if (!PathFileExistsA(server_path))
{
CreateDirectoryA(server_path, 0);
WLog_INFO(TAG, "creating directory %s", server_path);
if (!CreateDirectoryA(server_path, 0))
{
WLog_ERR(TAG, "error creating directory [%s]", server_path);
goto fail;
}
WLog_INFO(TAG, "created directory [%s]", server_path);
}
if (!(certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file)))
goto fail;
if (!PathFileExistsA(certificate_store->file))
certificate_store->fp = fopen((char*) certificate_store->file, "w+");
else
certificate_store->fp = fopen((char*) certificate_store->file, "r+");
if (!certificate_store->fp)
{
WLog_ERR(TAG, "error opening [%s]", certificate_store->file);
goto fail;
}
free(server_path);
certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file);
return TRUE;
if (!certificate_store->file)
return -1;
if (PathFileExistsA(certificate_store->file) == FALSE)
{
certificate_store->fp = fopen((char*) certificate_store->file, "w+");
if (!certificate_store->fp)
{
WLog_ERR(TAG, "certificate_store_open: error opening [%s] for writing", certificate_store->file);
return -1;
}
fflush(certificate_store->fp);
}
else
{
certificate_store->fp = fopen((char*) certificate_store->file, "r+");
}
return 1;
fail:
WLog_ERR(TAG, "certificate store initialization failed");
free(server_path);
free(certificate_store->path);
free(certificate_store->file);
certificate_store->path = NULL;
certificate_store->file = NULL;
return FALSE;
}
int certificate_data_match(rdpCertificateStore* certificate_store, rdpCertificateData* certificate_data)
@ -285,7 +294,11 @@ rdpCertificateStore* certificate_store_new(rdpSettings* settings)
certificate_store->settings = settings;
certificate_store_init(certificate_store);
if (!certificate_store_init(certificate_store))
{
free(certificate_store);
return NULL;
}
return certificate_store;
}

View File

@ -434,16 +434,25 @@ int shadow_server_init_config_path(rdpShadowServer* server)
if (userLibraryPath)
{
if (!PathFileExistsA(userLibraryPath))
CreateDirectoryA(userLibraryPath, 0);
if (!PathFileExistsA(userLibraryPath) &&
!CreateDirectoryA(userLibraryPath, 0))
{
free(userLibraryPath);
return -1;
}
userApplicationSupportPath = GetCombinedPath(userLibraryPath, "Application Support");
if (userApplicationSupportPath)
{
if (!PathFileExistsA(userApplicationSupportPath))
CreateDirectoryA(userApplicationSupportPath, 0);
if (!PathFileExistsA(userApplicationSupportPath) &&
!CreateDirectoryA(userApplicationSupportPath, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", userApplicationSupportPath);
free(userLibraryPath);
free(userApplicationSupportPath);
return -1;
}
server->ConfigPath = GetCombinedPath(userApplicationSupportPath, "freerdp");
}
@ -461,11 +470,14 @@ int shadow_server_init_config_path(rdpShadowServer* server)
if (configHome)
{
if (!PathFileExistsA(configHome))
CreateDirectoryA(configHome, 0);
if (!PathFileExistsA(configHome) &&
!CreateDirectoryA(configHome, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", configHome);
free(configHome);
return -1;
}
server->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
free(configHome);
}
}
@ -492,16 +504,23 @@ int shadow_server_init_certificate(rdpShadowServer* server)
int makecert_argc = (sizeof(makecert_argv) / sizeof(char*));
if (!PathFileExistsA(server->ConfigPath))
CreateDirectoryA(server->ConfigPath, 0);
if (!PathFileExistsA(server->ConfigPath) &&
!CreateDirectoryA(server->ConfigPath, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", server->ConfigPath);
return -1;
}
filepath = GetCombinedPath(server->ConfigPath, "shadow");
if (!filepath)
if (!(filepath = GetCombinedPath(server->ConfigPath, "shadow")))
return -1;
if (!PathFileExistsA(filepath))
CreateDirectoryA(filepath, 0);
if (!PathFileExistsA(filepath) &&
!CreateDirectoryA(filepath, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", filepath);
free(filepath);
return -1;
}
server->CertificateFile = GetCombinedPath(filepath, "shadow.crt");
server->PrivateKeyFile = GetCombinedPath(filepath, "shadow.key");

View File

@ -584,7 +584,11 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD
if (!PathFileExistsA(lpPipePath))
{
CreateDirectoryA(lpPipePath, 0);
if (!CreateDirectoryA(lpPipePath, 0))
{
free(lpPipePath);
goto out;
}
UnixChangeFileMode(lpPipePath, 0xFFFF);
}

View File

@ -1275,15 +1275,17 @@ void Inspect_InitLog()
if (g_Log)
return;
g_Log = WLog_Get("WinSCard");
if (!PathFileExistsA(filepath))
if (!CreateDirectoryA(filepath, NULL))
return;
if (!(g_Log = WLog_Get("WinSCard")))
return;
WLog_SetLogLevel(g_Log, WLOG_DEBUG);
WLog_SetLogAppenderType(g_Log, WLOG_APPENDER_FILE);
appender = (wLogFileAppender*) WLog_GetLogAppender(g_Log);
if (!PathFileExistsA(filepath))
CreateDirectoryA(filepath, NULL);
WLog_FileAppender_SetOutputFileName(g_Log, appender, "WinSCard.txt");
WLog_FileAppender_SetOutputFilePath(g_Log, appender, filepath);

View File

@ -96,7 +96,8 @@ int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
if (!PathFileExistsA(appender->FilePath))
{
CreateDirectoryA(appender->FilePath, 0);
if (!CreateDirectoryA(appender->FilePath, 0))
return -1;
UnixChangeFileMode(appender->FilePath, 0xFFFF);
}