header.Flags = RTS_FLAG_NONE;
header.NumberOfCommands = 4;
WLog_DBG(TAG, "Sending CONN/A1 RTS PDU");
- VirtualConnectionCookie = (BYTE*) & (connection->Cookie);
- OUTChannelCookie = (BYTE*) & (outChannel->Cookie);
+ VirtualConnectionCookie = (BYTE*) &(connection->Cookie);
+ OUTChannelCookie = (BYTE*) &(outChannel->Cookie);
ReceiveWindowSize = outChannel->ReceiveWindow;
buffer = (BYTE*) malloc(header.frag_length);
header.Flags = RTS_FLAG_NONE;
header.NumberOfCommands = 6;
WLog_DBG(TAG, "Sending CONN/B1 RTS PDU");
- VirtualConnectionCookie = (BYTE*) & (connection->Cookie);
- INChannelCookie = (BYTE*) & (inChannel->Cookie);
- AssociationGroupId = (BYTE*) & (connection->AssociationGroupId);
+ VirtualConnectionCookie = (BYTE*) &(connection->Cookie);
+ INChannelCookie = (BYTE*) &(inChannel->Cookie);
+ AssociationGroupId = (BYTE*) &(connection->AssociationGroupId);
buffer = (BYTE*) malloc(header.frag_length);
if (!buffer)
WLog_DBG(TAG, "Sending FlowControlAck RTS PDU");
BytesReceived = outChannel->BytesReceived;
AvailableWindow = outChannel->AvailableWindowAdvertised;
- ChannelCookie = (BYTE*) & (outChannel->Cookie);
+ ChannelCookie = (BYTE*) &(outChannel->Cookie);
outChannel->ReceiverAvailableWindow = outChannel->AvailableWindowAdvertised;
buffer = (BYTE*) malloc(header.frag_length);
header.Flags = RTS_FLAG_OUT_CHANNEL;
header.NumberOfCommands = 3;
WLog_DBG(TAG, "Sending OUT_R2/A7 RTS PDU");
- SuccessorChannelCookie = (BYTE*) & (nextOutChannel->Cookie);
+ SuccessorChannelCookie = (BYTE*) &(nextOutChannel->Cookie);
buffer = (BYTE*) malloc(header.frag_length);
if (!buffer)
header.Flags = RTS_FLAG_RECYCLE_CHANNEL;
header.NumberOfCommands = 5;
WLog_DBG(TAG, "Sending OUT_R1/A3 RTS PDU");
- VirtualConnectionCookie = (BYTE*) & (connection->Cookie);
- PredecessorChannelCookie = (BYTE*) & (outChannel->Cookie);
- SuccessorChannelCookie = (BYTE*) & (nextOutChannel->Cookie);
+ VirtualConnectionCookie = (BYTE*) &(connection->Cookie);
+ PredecessorChannelCookie = (BYTE*) &(outChannel->Cookie);
+ SuccessorChannelCookie = (BYTE*) &(nextOutChannel->Cookie);
ReceiveWindowSize = outChannel->ReceiveWindow;
buffer = (BYTE*) malloc(header.frag_length);
if (!envlen)
return;
- env = calloc(1, envlen + 1);
+ env = calloc(1, envlen);
if (!env)
{
return;
}
- if (GetEnvironmentVariableA(envname, env, envlen) == envlen)
+ if (GetEnvironmentVariableA(envname, env, envlen) == envlen - 1)
proxy_parse_uri(settings, env);
free(env);
DWORD nSize;
int underscore;
char* env_lang = NULL;
+ LPCSTR lang = "LANG";
/* LANG = <language>_<country>.<encoding> */
- nSize = GetEnvironmentVariableA("LANG", NULL, 0);
+ nSize = GetEnvironmentVariableA(lang, NULL, 0);
if (!nSize)
return FALSE; /* LANG environment variable was not set */
if (!env_lang)
return FALSE;
- GetEnvironmentVariableA("LANG", env_lang, nSize); /* Get locale from environment variable LANG */
+ if (GetEnvironmentVariableA(lang, env_lang, nSize) != nSize - 1) /* Get locale from environment variable LANG */
+ {
+ free (env_lang);
+ return FALSE;
+ }
underscore = strcspn(env_lang, "_");
if ((length + 1 > nSize) || (!lpBuffer))
return length + 1;
- CopyMemory(lpBuffer, env, length + 1);
+ CopyMemory(lpBuffer, env, length);
+ lpBuffer[length] = '\0';
return length;
#else
if (length > 0)
{
- env = malloc(length + 1);
+ env = malloc(length);
if (!env)
return NULL;
- GetEnvironmentVariableA(lpName, env, length + 1);
- env[length] = '\0';
+ if (GetEnvironmentVariableA(lpName, env, length) != length - 1)
+ {
+ free(env);
+ return NULL;
+ }
}
return env;
if (!env)
return NULL;
- if (GetEnvironmentVariableA(name, env, nSize) != nSize)
+ if (GetEnvironmentVariableA(name, env, nSize) != nSize - 1)
{
free(env);
return NULL;
{
BOOL status = FALSE;
#ifdef _WIN32
+ LPCSTR sspi = "WINPR_NATIVE_SSPI";
DWORD nSize;
char* env = NULL;
- nSize = GetEnvironmentVariableA("WINPR_NATIVE_SSPI", NULL, 0);
+ nSize = GetEnvironmentVariableA(sspi, NULL, 0);
if (!nSize)
return TRUE;
if (!env)
return TRUE;
- nSize = GetEnvironmentVariableA("WINPR_NATIVE_SSPI", env, nSize);
+ if (GetEnvironmentVariableA(sspi, env, nSize) != nSize - 1)
+ {
+ free(env);
+ return TRUE;
+ }
if (strcmp(env, "0") == 0)
status = FALSE;
static char* FindApplicationPath(char* application)
{
+ LPCSTR pathName = "PATH";
char* path;
char* save;
DWORD nSize;
if (application[0] == '/')
return _strdup(application);
- nSize = GetEnvironmentVariableA("PATH", NULL, 0);
+ nSize = GetEnvironmentVariableA(pathName, NULL, 0);
if (!nSize)
return _strdup(application);
if (!lpSystemPath)
return NULL;
- nSize = GetEnvironmentVariableA("PATH", lpSystemPath, nSize);
+ if (GetEnvironmentVariableA(pathName, lpSystemPath, nSize) != nSize - 1)
+ {
+ free(lpSystemPath);
+ return NULL;
+ }
save = NULL;
path = strtok_s(lpSystemPath, ":", &save);
LPCSTR name;
DWORD nSize;
wLogFileAppender* FileAppender;
- BOOL status;
FileAppender = (wLogFileAppender*) calloc(1, sizeof(wLogFileAppender));
if (!FileAppender)
if (nSize)
{
+ BOOL status;
env = (LPSTR) malloc(nSize);
if (!env)
goto error_free;
- if (GetEnvironmentVariableA(name, env, nSize) != nSize)
+ if (GetEnvironmentVariableA(name, env, nSize) != nSize - 1)
{
free(env);
goto error_free;
if (nSize)
{
+ BOOL status = FALSE;
env = (LPSTR) malloc(nSize);
if (!env)
goto error_output_file_name;
- GetEnvironmentVariableA(name, env, nSize);
- status = WLog_FileAppender_SetOutputFileName(FileAppender, env);
+ if (GetEnvironmentVariableA(name, env, nSize) == nSize - 1)
+ status = WLog_FileAppender_SetOutputFileName(FileAppender, env);
free(env);
if (!status)
{
wLogJournaldAppender* appender;
DWORD nSize;
- LPCSTR name;
+ LPCSTR name = "WLOG_JOURNALD_ID";;
appender = (wLogJournaldAppender*) calloc(1, sizeof(wLogJournaldAppender));
if (!appender)
appender->Set = WLog_JournaldAppender_Set;
appender->Free = WLog_JournaldAppender_Free;
- name = "WLOG_JOURNALD_ID";
nSize = GetEnvironmentVariableA(name, NULL, 0);
if (nSize)
{
appender->identifier = (LPSTR) malloc(nSize);
if (!appender->identifier)
- goto error_env_malloc;
+ goto error_open;
- GetEnvironmentVariableA(name, appender->identifier, nSize);
+ if (GetEnvironmentVariableA(name, appender->identifier, nSize) != nSize -1)
+ goto error_open;
if (!WLog_JournaldAppender_Open(log, (wLogAppender *)appender))
goto error_open;
error_open:
free(appender->identifier);
-error_env_malloc:
free(appender);
return NULL;
}
wLogLayout* WLog_Layout_New(wLog* log)
{
+ LPCSTR prefix = "WLOG_PREFIX";
DWORD nSize;
char* env = NULL;
wLogLayout* layout;
if (!layout)
return NULL;
- nSize = GetEnvironmentVariableA("WLOG_PREFIX", NULL, 0);
+ nSize = GetEnvironmentVariableA(prefix, NULL, 0);
if (nSize)
{
return NULL;
}
- if (GetEnvironmentVariableA("WLOG_PREFIX", env, nSize) != nSize)
+ if (GetEnvironmentVariableA(prefix, env, nSize) != nSize - 1)
{
free(env);
free(layout);
{
appender->host = (LPSTR) malloc(nSize);
if (!appender->host)
- goto error_host_alloc;
+ goto error_open;
- GetEnvironmentVariableA(name, appender->host, nSize);
+ if (GetEnvironmentVariableA(name, appender->host, nSize) != nSize - 1)
+ goto error_open;
if (!WLog_UdpAppender_Open(log, (wLogAppender *)appender))
goto error_open;
{
appender->host = _strdup("127.0.0.1:20000");
if (!appender->host)
- goto error_host_alloc;
+ goto error_open;
}
return (wLogAppender*)appender;
error_open:
free(appender->host);
-error_host_alloc:
closesocket(appender->sock);
error_sock:
free(appender);
BOOL WLog_ParseFilters(void)
{
- BOOL res;
+ LPCSTR filter = "WLOG_FILTER";
+ BOOL res = FALSE;
char* env;
DWORD nSize;
g_Filters = NULL;
g_FilterCount = 0;
- nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
+ nSize = GetEnvironmentVariableA(filter, NULL, 0);
if (nSize < 1)
return TRUE;
if (!env)
return FALSE;
- if (!GetEnvironmentVariableA("WLOG_FILTER", env, nSize))
- return FALSE;
-
- res = WLog_AddStringLogFilters(env);
+ if (GetEnvironmentVariableA(filter, env, nSize) == nSize - 1)
+ res = WLog_AddStringLogFilters(env);
free(env);
return res;
}
}
else
{
+ LPCSTR level = "WLOG_LEVEL";
+
log->Level = WLOG_INFO;
- nSize = GetEnvironmentVariableA("WLOG_LEVEL", NULL, 0);
+ nSize = GetEnvironmentVariableA(level, NULL, 0);
if (nSize)
{
if (!env)
goto out_fail;
- if (!GetEnvironmentVariableA("WLOG_LEVEL", env, nSize))
+ if (GetEnvironmentVariableA(level, env, nSize) != nSize - 1)
{
- fprintf(stderr, "WLOG_LEVEL environment variable changed in my back !\n");
+ fprintf(stderr, "%s environment variable changed in my back !\n", level);
free(env);
goto out_fail;
}
if (!g_RootLog)
{
+ LPCSTR appender = "WLOG_APPENDER";
+
if (!(g_RootLog = WLog_New("", NULL)))
return NULL;
g_RootLog->IsRoot = TRUE;
WLog_ParseFilters();
logAppenderType = WLOG_APPENDER_CONSOLE;
- nSize = GetEnvironmentVariableA("WLOG_APPENDER", NULL, 0);
+ nSize = GetEnvironmentVariableA(appender, NULL, 0);
if (nSize)
{
if (!env)
goto fail;
- if (!GetEnvironmentVariableA("WLOG_APPENDER", env, nSize))
+ if (GetEnvironmentVariableA(appender, env, nSize) != nSize - 1)
{
- fprintf(stderr, "WLOG_APPENDER environment variable modified in my back");
+ fprintf(stderr, "%s environment variable modified in my back", appender);
free(env);
goto fail;
}
{
DWORD nSize;
char *env = NULL;
+ LPCSTR wts = "WTSAPI_LIBRARY";
if (g_WtsApi)
return;
- nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0);
+ nSize = GetEnvironmentVariableA(wts, NULL, 0);
if (!nSize)
return;
env = (LPSTR) malloc(nSize);
if (env)
{
- if (GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize))
+ if (GetEnvironmentVariableA(wts, env, nSize) == nSize - 1)
LoadAndInitialize(env);
free(env);
}