rdpContext* context;
rdpSettings* settings;
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
+ int ret = 0;
ZeroMemory(&clientEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
clientEntryPoints.Size = sizeof(RDP_CLIENT_ENTRY_POINTS);
context->argc = __argc;
context->argv = (char**) malloc(sizeof(char*) * __argc);
+ if (!context->argv)
+ {
+ ret = 1;
+ goto out;
+ }
for (index = 0; index < context->argc; index++)
+ {
context->argv[index] = _strdup(__argv[index]);
+ if (!context->argv[index])
+ {
+ ret = 1;
+ free(context->argv);
+ context->argv = NULL;
+ goto out;
+ }
+
+ }
status = freerdp_client_settings_parse_command_line(settings, context->argc, context->argv, FALSE);
GetExitCodeThread(thread, &dwExitCode);
freerdp_client_stop(context);
-
+out:
freerdp_client_context_free(context);
- return 0;
+ return ret;
}
status = CredUIParseUserNameA(UserName, User, sizeof(User), Domain, sizeof(Domain));
//WLog_ERR(TAG, "User: %s Domain: %s Password: %s", User, Domain, Password);
*username = _strdup(User);
+ if (!(*username))
+ {
+ WLog_ERR(TAG, "strdup failed", status);
+ return FALSE;
+ }
if (strlen(Domain) > 0)
*domain = _strdup(Domain);
else
*domain = _strdup("\0");
+ if (!(*domain))
+ {
+ free(*username);
+ WLog_ERR(TAG, "strdup failed", status);
+ return FALSE;
+ }
+
*password = _strdup(Password);
+ if (!(*password))
+ {
+ free(*username);
+ free(*domain);
+ return FALSE;
+ }
return TRUE;
}
if (filename)
{
settings->ConnectionFile = _strdup(filename);
+ if (!settings->ConnectionFile)
+ {
+ return 3;
+ }
// free old settings file
freerdp_client_rdp_file_free(wfc->connectionRdpFile);
if (settings->WindowTitle)
{
windowTitle = _strdup(settings->WindowTitle);
+ if (!windowTitle)
+ return FALSE;
}
else if (settings->ServerPort == 3389)
{
if (login_name)
{
settings->Username = _strdup(login_name);
+ if (!settings->Username)
+ return FALSE;
WLog_INFO(TAG, "No user name set. - Using login name: %s", settings->Username);
}
}
if (!context->cache)
context->cache = cache_new(settings);
- xf_keyboard_init(xfc);
+ if (!xf_keyboard_init(xfc))
+ return FALSE;
xf_detect_monitors(xfc, &maxWidth, &maxHeight);
format = &formatList->formats[i];
clipboard->serverFormats[i].formatId = format->formatId;
clipboard->serverFormats[i].formatName = _strdup(format->formatName);
+ if (!clipboard->serverFormats[i].formatName)
+ {
+ for (--i; i >= 0; --i)
+ free(clipboard->serverFormats[i].formatName);
+
+ clipboard->numServerFormats = 0;
+ free(clipboard->serverFormats);
+ clipboard->serverFormats = NULL;
+ return -1;
+ }
}
clipboard->numTargets = 2;
clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "text/html", False);
clipboard->clientFormats[n].formatId = CB_FORMAT_HTML;
clipboard->clientFormats[n].formatName = _strdup("HTML Format");
+ if (!clipboard->clientFormats[n].formatName)
+ {
+ ClipboardDestroy(clipboard->system);
+ free(clipboard);
+ return NULL;
+ }
n++;
clipboard->numClientFormats = n;
BOOL xf_event_action_script_init(xfContext* xfc)
{
- int exitCode;
char* xevent;
FILE* actionScript;
char buffer[1024] = { 0 };
actionScript = popen(command, "r");
- if (actionScript < 0)
+ if (actionScript <= 0)
return FALSE;
while (fgets(buffer, sizeof(buffer), actionScript))
{
strtok(buffer, "\n");
xevent = _strdup(buffer);
- if (ArrayList_Add(xfc->xevents, xevent) < 0)
+ if (!xevent || ArrayList_Add(xfc->xevents, xevent) < 0)
+ {
+ ArrayList_Free(xfc->xevents);
+ xfc->xevents = NULL;
return FALSE;
+ }
}
- exitCode = pclose(actionScript);
+ pclose(actionScript);
return TRUE;
}
}
}
-int xf_event_execute_action_script(xfContext* xfc, XEvent* event)
+static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
{
int index;
int count;
char* name;
- int exitCode;
FILE* actionScript;
BOOL match = FALSE;
const char* xeventName;
char buffer[1024] = { 0 };
char command[1024] = { 0 };
- if (!xfc->actionScript)
- return 1;
+ if (!xfc->actionScript || !xfc->xevents)
+ return FALSE;
if (event->type > (sizeof(X11_EVENT_STRINGS) / sizeof(const char*)))
- return 1;
+ return FALSE;
xeventName = X11_EVENT_STRINGS[event->type];
}
if (!match)
- return 1;
+ return FALSE;
sprintf_s(command, sizeof(command), "%s xevent %s %d",
xfc->actionScript, xeventName, (int) xfc->window->handle);
actionScript = popen(command, "r");
if (actionScript < 0)
- return -1;
+ return FALSE;
while (fgets(buffer, sizeof(buffer), actionScript))
{
strtok(buffer, "\n");
}
- exitCode = pclose(actionScript);
+ pclose(actionScript);
- return 1;
+ return TRUE;
}
void xf_event_adjust_coordinates(xfContext* xfc, int* x, int *y)
xfc->actionScript = _strdup("/usr/share/freerdp/action.sh");
if (!xfc->actionScript)
- return 0;
+ return FALSE;
xfc->keyCombinations = ArrayList_New(TRUE);
if (!xfc->keyCombinations)
- return 0;
+ return FALSE;
ArrayList_Object(xfc->keyCombinations)->fnObjectFree = free;
{
free(xfc->actionScript);
xfc->actionScript = NULL;
- return 0;
+ return FALSE;
}
while (fgets(buffer, sizeof(buffer), keyScript) != NULL)
{
strtok(buffer, "\n");
keyCombination = _strdup(buffer);
- if (ArrayList_Add(xfc->keyCombinations, keyCombination) < 0)
- return 0;
+ if (!keyCombination || ArrayList_Add(xfc->keyCombinations, keyCombination) < 0)
+ {
+ ArrayList_Free(xfc->keyCombinations);
+ free(xfc->actionScript);
+ xfc->actionScript = NULL;
+ pclose(keyScript);
+ return FALSE;
+ }
}
- exitCode = pclose(keyScript);
-
+ pclose(keyScript);
return xf_event_action_script_init(xfc);
+
}
void xf_keyboard_action_script_free(xfContext* xfc)
}
}
-void xf_keyboard_init(xfContext* xfc)
+BOOL xf_keyboard_init(xfContext* xfc)
{
xf_keyboard_clear(xfc);
if (xfc->modifierMap)
XFreeModifiermap(xfc->modifierMap);
- xfc->modifierMap = XGetModifierMapping(xfc->display);
+ if (!(xfc->modifierMap = XGetModifierMapping(xfc->display)))
+ return FALSE;
xf_keyboard_action_script_init(xfc);
+ return TRUE;
}
void xf_keyboard_free(xfContext* xfc)
};
typedef struct _XF_MODIFIER_KEYS XF_MODIFIER_KEYS;
-void xf_keyboard_init(xfContext* xfc);
+BOOL xf_keyboard_init(xfContext* xfc);
void xf_keyboard_free(xfContext* xfc);
void xf_keyboard_clear(xfContext* xfc);
void xf_keyboard_key_press(xfContext* xfc, BYTE keycode, KeySym keysym);
{
appWindow->title = _strdup("RdpRailWindow");
}
+ if (!appWindow->title)
+ {
+ free(appWindow);
+ return FALSE;
+ }
HashTable_Add(xfc->railWindows, (void*) (UINT_PTR) orderInfo->windowId, (void*) appWindow);
int freerdp_client_settings_parse_connection_file(rdpSettings* settings, const char* filename)
{
rdpFile* file;
+ int ret = -1;
file = freerdp_client_rdp_file_new();
- freerdp_client_parse_rdp_file(file, filename);
- freerdp_client_populate_settings_from_rdp_file(file, settings);
- freerdp_client_rdp_file_free(file);
+ if (!file)
+ return -1;
+ if (!freerdp_client_parse_rdp_file(file, filename))
+ goto out;
+ if (!freerdp_client_populate_settings_from_rdp_file(file, settings))
+ goto out;
- return 0;
+ ret = 0;
+out:
+ freerdp_client_rdp_file_free(file);
+ return ret;
}
int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings, const BYTE* buffer, size_t size)
int status = -1;
file = freerdp_client_rdp_file_new();
+ if (!file)
+ return -1;
if (freerdp_client_parse_rdp_file_buffer(file, buffer, size)
&& freerdp_client_populate_settings_from_rdp_file(file, settings))
int freerdp_client_settings_write_connection_file(const rdpSettings* settings, const char* filename, BOOL unicode)
{
rdpFile* file;
+ int ret = -1;
file = freerdp_client_rdp_file_new();
+ if (!file)
+ return -1;
if (!freerdp_client_populate_rdp_file_from_settings(file, settings))
- return -1;
+ goto out;
if (!freerdp_client_write_rdp_file(file, filename, unicode))
- return -1;
+ goto out;
+ ret = 0;
+out:
freerdp_client_rdp_file_free(file);
- return 0;
+ return ret;
}
int freerdp_client_settings_parse_assistance_file(rdpSettings* settings, const char* filename)
RDP_KEYBOARD_LAYOUT* layouts;
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD);
+ if (!layouts)
+ return -1;
for (i = 0; layouts[i].code; i++)
{
return id;
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
+ if (!layouts)
+ return -1;
for (i = 0; layouts[i].code; i++)
{
return id;
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
+ if (!layouts)
+ return -1;
for (i = 0; layouts[i].code; i++)
{
RDP_KEYBOARD_LAYOUT* layouts;
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD);
+ //if (!layouts) /* FIXME*/
printf("\nKeyboard Layouts\n");
for (i = 0; layouts[i].code; i++)
printf("0x%08X\t%s\n", (int) layouts[i].code, layouts[i].name);
free(layouts);
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
+ //if (!layouts) /* FIXME*/
printf("\nKeyboard Layout Variants\n");
for (i = 0; layouts[i].code; i++)
printf("0x%08X\t%s\n", (int) layouts[i].code, layouts[i].name);
free(layouts);
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
+ //if (!layouts) /* FIXME*/
printf("\nKeyboard Input Method Editors (IMEs)\n");
for (i = 0; layouts[i].code; i++)
printf("0x%08X\t%s\n", (int) layouts[i].code, layouts[i].name);
if (id == 0)
{
id = (unsigned long int) freerdp_map_keyboard_layout_name_to_id(arg->Value);
-
- if (!id)
+ if (id == -1)
+ WLog_ERR(TAG, "A problem occured while mapping the layout name to id");
+ else if (id == 0)
{
WLog_ERR(TAG, "Could not identify keyboard layout: %s", arg->Value);
+ WLog_ERR(TAG, "Use /kbd-list to list available layouts");
}
+ if (id <= 0)
+ return COMMAND_LINE_STATUS_PRINT;
}
settings->KeyboardLayout = (UINT32) id;
#define INVALID_INTEGER_VALUE 0xFFFFFFFF
-BOOL freerdp_client_rdp_file_set_integer(rdpFile* file, const char* name, int value, int index)
+/*
+ * Set an integer in a rdpFile
+ *
+ * @return 0 if a standard name was set, 1 for a non-standard name, -1 on error
+ *
+ */
+
+static int freerdp_client_rdp_file_set_integer(rdpFile* file, const char* name, int value, int index)
{
- BOOL bStandard = TRUE;
+ int bStandard = 1;
#ifdef DEBUG_CLIENT_FILE
WLog_DBG(TAG, "%s:i:%d", name, value);
else if (_stricmp(name, "rdgiskdcproxy") == 0)
file->RdgIsKdcProxy = value;
else
- bStandard = FALSE;
+ bStandard = 1;
if (index >= 0)
{
file->lines[index].name = _strdup(name);
+ if (!file->lines[index].name)
+ return -1;
file->lines[index].iValue = (DWORD) value;
file->lines[index].flags = RDP_FILE_LINE_FLAG_FORMATTED;
return bStandard;
}
-void freerdp_client_parse_rdp_file_integer_unicode(rdpFile* file, WCHAR* name, WCHAR* value, int index)
+static BOOL freerdp_client_parse_rdp_file_integer_unicode(rdpFile* file, WCHAR* name, WCHAR* value, int index)
{
int length;
int ivalue;
char* nameA;
char* valueA;
+ BOOL ret = TRUE;
length = (int) _wcslen(name);
nameA = (char*) malloc(length + 1);
+ if (!nameA)
+ return FALSE;
WideCharToMultiByte(CP_UTF8, 0, name, length, nameA, length, NULL, NULL);
nameA[length] = '\0';
length = (int) _wcslen(value);
valueA = (char*) malloc(length + 1);
+ if (!valueA)
+ {
+ free(nameA);
+ return FALSE;
+ }
WideCharToMultiByte(CP_UTF8, 0, value, length, valueA, length, NULL, NULL);
valueA[length] = '\0';
ivalue = atoi(valueA);
- freerdp_client_rdp_file_set_integer(file, nameA, ivalue, index);
+ if (freerdp_client_rdp_file_set_integer(file, nameA, ivalue, index) < 0)
+ ret = FALSE;
free(nameA);
free(valueA);
+ return ret;
}
-void freerdp_client_parse_rdp_file_integer_ascii(rdpFile* file, const char* name, const char* value, int index)
+static BOOL freerdp_client_parse_rdp_file_integer_ascii(rdpFile* file, const char* name, const char* value, int index)
{
int ivalue = atoi(value);
- freerdp_client_rdp_file_set_integer(file, name, ivalue, index);
+ if (freerdp_client_rdp_file_set_integer(file, name, ivalue, index) < 0)
+ return FALSE;
+ return TRUE;
}
-BOOL freerdp_client_rdp_file_set_string(rdpFile* file, const char* name, const char* value, int index)
+/**
+ *
+ * @param file rdpFile
+ * @param name name of the string
+ * @param value value of the string to set
+ * @param index line index of the rdpFile
+ * @return 0 on success, 1 if the key wasn't found (not a standard key), -1 on error
+ */
+
+static int freerdp_client_rdp_file_set_string(rdpFile* file, const char* name, const char* value, int index)
{
- BOOL bStandard = TRUE;
+ int bStandard = 0;
+ LPSTR *tmp = NULL;
#ifdef DEBUG_CLIENT_FILE
WLog_DBG(TAG, "%s:s:%s", name, value);
#endif
if (_stricmp(name, "username") == 0)
- file->Username = _strdup(value);
+ tmp = &file->Username;
else if (_stricmp(name, "domain") == 0)
- file->Domain = _strdup(value);
+ tmp = &file->Domain;
else if (_stricmp(name, "full address") == 0)
- file->FullAddress = _strdup(value);
+ tmp = &file->FullAddress;
else if (_stricmp(name, "alternate full address") == 0)
- file->AlternateFullAddress = _strdup(value);
+ tmp = &file->AlternateFullAddress;
else if (_stricmp(name, "usbdevicestoredirect") == 0)
- file->UsbDevicesToRedirect = _strdup(value);
+ tmp = &file->UsbDevicesToRedirect;
else if (_stricmp(name, "loadbalanceinfo") == 0)
- file->LoadBalanceInfo = _strdup(value);
+ tmp = &file->LoadBalanceInfo;
else if (_stricmp(name, "remoteapplicationname") == 0)
- file->RemoteApplicationName = _strdup(value);
+ tmp = &file->RemoteApplicationName;
else if (_stricmp(name, "remoteapplicationicon") == 0)
- file->RemoteApplicationIcon = _strdup(value);
+ tmp = &file->RemoteApplicationIcon;
else if (_stricmp(name, "remoteapplicationprogram") == 0)
- file->RemoteApplicationProgram = _strdup(value);
+ tmp = &file->RemoteApplicationProgram;
else if (_stricmp(name, "remoteapplicationfile") == 0)
- file->RemoteApplicationFile = _strdup(value);
+ tmp = &file->RemoteApplicationFile;
else if (_stricmp(name, "remoteapplicationguid") == 0)
- file->RemoteApplicationGuid = _strdup(value);
+ tmp = &file->RemoteApplicationGuid;
else if (_stricmp(name, "remoteapplicationcmdline") == 0)
- file->RemoteApplicationCmdLine = _strdup(value);
+ tmp = &file->RemoteApplicationCmdLine;
else if (_stricmp(name, "alternate shell") == 0)
- file->AlternateShell = _strdup(value);
+ tmp = &file->AlternateShell;
else if (_stricmp(name, "shell working directory") == 0)
- file->ShellWorkingDirectory = _strdup(value);
+ tmp = &file->ShellWorkingDirectory;
else if (_stricmp(name, "gatewayhostname") == 0)
- file->GatewayHostname = _strdup(value);
+ tmp = &file->GatewayHostname;
else if (_stricmp(name, "kdcproxyname") == 0)
- file->KdcProxyName = _strdup(value);
+ tmp = &file->KdcProxyName;
else if (_stricmp(name, "drivestoredirect") == 0)
- file->DrivesToRedirect = _strdup(value);
+ tmp = &file->DrivesToRedirect;
else if (_stricmp(name, "devicestoredirect") == 0)
- file->DevicesToRedirect = _strdup(value);
+ tmp = &file->DevicesToRedirect;
else if (_stricmp(name, "winposstr") == 0)
- file->WinPosStr = _strdup(value);
+ tmp = &file->WinPosStr;
else
- bStandard = FALSE;
+ bStandard = 1;
+
+ if (tmp && !(*tmp = strdup(value)))
+ return -1;
if (index >= 0)
{
file->lines[index].name = _strdup(name);
file->lines[index].sValue = _strdup(value);
+ if (!file->lines[index].name || !file->lines[index].sValue)
+ {
+ free(file->lines[index].name);
+ free(file->lines[index].sValue);
+ return -1;
+ }
file->lines[index].flags = RDP_FILE_LINE_FLAG_FORMATTED;
file->lines[index].flags |= RDP_FILE_LINE_FLAG_TYPE_STRING;
- if (bStandard)
+ if (bStandard == 0)
file->lines[index].flags |= RDP_FILE_LINE_FLAG_STANDARD;
file->lines[index].valueLength = 0;
return bStandard;
}
-void freerdp_client_add_option(rdpFile* file, char* option)
+static BOOL freerdp_client_add_option(rdpFile* file, char* option)
{
while ((file->argc + 1) > file->argSize)
{
new_size = file->argSize * 2;
new_argv = (char**) realloc(file->argv, new_size * sizeof(char*));
if (!new_argv)
- return;
+ return FALSE;
file->argv = new_argv;
file->argSize = new_size;
}
file->argv[file->argc] = _strdup(option);
+ if (!file->argv[file->argc])
+ return FALSE;
(file->argc)++;
+ return TRUE;
}
-int freerdp_client_parse_rdp_file_add_line(rdpFile* file, char* line, int index)
+static int freerdp_client_parse_rdp_file_add_line(rdpFile* file, char* line, int index)
{
if (index < 0)
index = file->lineCount;
ZeroMemory(&(file->lines[file->lineCount]), sizeof(rdpFileLine));
file->lines[file->lineCount].text = _strdup(line);
+ if (!file->lines[file->lineCount].text)
+ return -1;
+
file->lines[file->lineCount].index = index;
(file->lineCount)++;
return index;
}
-void freerdp_client_parse_rdp_file_add_line_unicode(rdpFile* file, WCHAR* line, int index)
+static BOOL freerdp_client_parse_rdp_file_add_line_unicode(rdpFile* file, WCHAR* line, int index)
{
char* lineA = NULL;
+ BOOL ret = TRUE;
ConvertFromUnicode(CP_UTF8, 0, line, -1, &lineA, 0, NULL, NULL);
- freerdp_client_parse_rdp_file_add_line(file, lineA, index);
+ if (!lineA)
+ return FALSE;
+
+ if (freerdp_client_parse_rdp_file_add_line(file, lineA, index) == -1)
+ ret = FALSE;
free(lineA);
+ return ret;
}
-void freerdp_client_parse_rdp_file_add_line_ascii(rdpFile* file, char* line, int index)
+static BOOL freerdp_client_parse_rdp_file_add_line_ascii(rdpFile* file, char* line, int index)
{
- freerdp_client_parse_rdp_file_add_line(file, line, index);
+ if (freerdp_client_parse_rdp_file_add_line(file, line, index) == -1)
+ return FALSE;
+ return TRUE;
}
-void freerdp_client_parse_rdp_file_string_unicode(rdpFile* file, WCHAR* name, WCHAR* value, int index)
+static BOOL freerdp_client_parse_rdp_file_string_unicode(rdpFile* file, WCHAR* name, WCHAR* value, int index)
{
int length;
char* nameA;
char* valueA;
+ BOOL ret = TRUE;
length = (int) _wcslen(name);
nameA = (char*) malloc(length + 1);
+ if (!nameA)
+ return FALSE;
WideCharToMultiByte(CP_UTF8, 0, name, length, nameA, length, NULL, NULL);
nameA[length] = '\0';
length = (int) _wcslen(value);
valueA = (char*) malloc(length + 1);
+ if (!valueA)
+ {
+ free(nameA);
+ return FALSE;
+ }
WideCharToMultiByte(CP_UTF8, 0, value, length, valueA, length, NULL, NULL);
valueA[length] = '\0';
- freerdp_client_rdp_file_set_string(file, nameA, valueA, index);
+ if (freerdp_client_rdp_file_set_string(file, nameA, valueA, index) == -1)
+ ret = FALSE;
free(nameA);
free(valueA);
+ return ret;
}
-void freerdp_client_parse_rdp_file_string_ascii(rdpFile* file, char* name, char* value, int index)
+static BOOL freerdp_client_parse_rdp_file_string_ascii(rdpFile* file, char* name, char* value, int index)
{
+ BOOL ret = TRUE;
char* valueA = _strdup(value);
- freerdp_client_rdp_file_set_string(file, name, valueA, index);
+ if (!valueA)
+ return FALSE;
+
+ if (freerdp_client_rdp_file_set_string(file, name, valueA, index) == -1)
+ ret = FALSE;
+
free(valueA);
+ return ret;
}
-void freerdp_client_parse_rdp_file_option_unicode(rdpFile* file, WCHAR* option, int index)
+static BOOL freerdp_client_parse_rdp_file_option_unicode(rdpFile* file, WCHAR* option, int index)
{
char* optionA = NULL;
+ BOOL ret;
ConvertFromUnicode(CP_UTF8, 0, option, -1, &optionA, 0, NULL, NULL);
- freerdp_client_add_option(file, optionA);
+ if (!optionA)
+ return FALSE;
+ ret = freerdp_client_add_option(file, optionA);
free(optionA);
+
+ return ret;
}
-void freerdp_client_parse_rdp_file_option_ascii(rdpFile* file, char* option, int index)
+static BOOL freerdp_client_parse_rdp_file_option_ascii(rdpFile* file, char* option, int index)
{
- freerdp_client_add_option(file, option);
+ return freerdp_client_add_option(file, option);
}
-BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, const BYTE* buffer, size_t size)
+static BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, const BYTE* buffer, size_t size)
{
int index;
int length;
beg = line;
end = &line[length - 1];
- freerdp_client_parse_rdp_file_add_line_ascii(file, line, index);
+ if (!freerdp_client_parse_rdp_file_add_line_ascii(file, line, index))
+ return FALSE;
if (beg[0] == '/')
{
- freerdp_client_parse_rdp_file_option_ascii(file, line, index);
+ if (!freerdp_client_parse_rdp_file_option_ascii(file, line, index))
+ return FALSE;
+
goto next_line; /* FreeRDP option */
}
if (*type == 'i')
{
/* integer type */
- freerdp_client_parse_rdp_file_integer_ascii(file, name, value, index);
+ if (!freerdp_client_parse_rdp_file_integer_ascii(file, name, value, index))
+ return FALSE;
}
else if (*type == 's')
{
/* string type */
- freerdp_client_parse_rdp_file_string_ascii(file, name, value, index);
+ if (!freerdp_client_parse_rdp_file_string_ascii(file, name, value, index))
+ return FALSE;
}
else if (*type == 'b')
{
return TRUE;
}
-BOOL freerdp_client_parse_rdp_file_buffer_unicode(rdpFile* file, const BYTE* buffer, size_t size)
+static BOOL freerdp_client_parse_rdp_file_buffer_unicode(rdpFile* file, const BYTE* buffer, size_t size)
{
int index;
int length;
beg = line;
end = &line[length - 1];
- freerdp_client_parse_rdp_file_add_line_unicode(file, line, index);
+ if (!freerdp_client_parse_rdp_file_add_line_unicode(file, line, index))
+ return FALSE;
if (beg[0] == '/')
{
if (*type == 'i')
{
/* integer type */
- freerdp_client_parse_rdp_file_integer_unicode(file, name, value, index);
+ if (!freerdp_client_parse_rdp_file_integer_unicode(file, name, value, index))
+ return FALSE;
}
else if (*type == 's')
{
/* string type */
- freerdp_client_parse_rdp_file_string_unicode(file, name, value, index);
+ if (!freerdp_client_parse_rdp_file_string_unicode(file, name, value, index))
+ return FALSE;
}
else if (*type == 'b')
{
}
buffer = (BYTE*) malloc(file_size + 2);
+ if (!buffer)
+ {
+ fclose(fp);
+ return FALSE;
+ }
read_size = fread(buffer, file_size, 1, fp);
if (!read_size)
if (read_size < 1)
{
free(buffer);
- buffer = NULL;
return FALSE;
}
#define WRITE_ALL_SETTINGS TRUE
#define SETTING_MODIFIED(_settings, _field) (WRITE_ALL_SETTINGS || _settings->SettingsModified[FreeRDP_##_field])
#define SETTING_MODIFIED_SET(_target, _settings, _field) if SETTING_MODIFIED(_settings, _field) _target = _settings->_field
-#define SETTING_MODIFIED_SET_STRING(_target, _settings, _field) if SETTING_MODIFIED(_settings, _field) _target = _strdup(_settings->_field)
+#define SETTING_MODIFIED_SET_STRING(_target, _settings, _field) do { if SETTING_MODIFIED(_settings, _field) _target = _strdup(_settings->_field); \
+ if (!_target) return FALSE; \
+ } while (0)
BOOL freerdp_client_populate_rdp_file_from_settings(rdpFile* file, const rdpSettings* settings)
{
BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* settings)
{
if (~((size_t) file->Domain))
- freerdp_set_param_string(settings, FreeRDP_Domain, file->Domain);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_Domain, file->Domain) != 0)
+ return FALSE;
+ }
if (~((size_t) file->Username))
{
char* user = NULL;
char* domain = NULL;
- freerdp_parse_username(file->Username, &user, &domain);
- freerdp_set_param_string(settings, FreeRDP_Username, user);
+ if (freerdp_parse_username(file->Username, &user, &domain) != 0)
+ return FALSE;
+ if (freerdp_set_param_string(settings, FreeRDP_Username, user) != 0)
+ return FALSE;
if (domain)
- freerdp_set_param_string(settings, FreeRDP_Domain, domain);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_Domain, domain) != 0)
+ return FALSE;
+ }
free(user);
free(domain);
int port = -1;
char* host = NULL;
- freerdp_parse_hostname(file->FullAddress, &host, &port);
+ if (freerdp_parse_hostname(file->FullAddress, &host, &port) != 0)
+ return FALSE;
- freerdp_set_param_string(settings, FreeRDP_ServerHostname, host);
+ if (freerdp_set_param_string(settings, FreeRDP_ServerHostname, host) != 0)
+ return FALSE;
if (port > 0)
freerdp_set_param_uint32(settings, FreeRDP_ServerPort, (UINT32) port);
if (~file->EnableCredSSPSupport)
freerdp_set_param_bool(settings, FreeRDP_NlaSecurity, file->EnableCredSSPSupport);
if (~((size_t) file->AlternateShell))
- freerdp_set_param_string(settings, FreeRDP_AlternateShell, file->AlternateShell);
+ {
+ if(freerdp_set_param_string(settings, FreeRDP_AlternateShell, file->AlternateShell) != 0)
+ return FALSE;
+ }
if (~((size_t) file->ShellWorkingDirectory))
- freerdp_set_param_string(settings, FreeRDP_ShellWorkingDirectory, file->ShellWorkingDirectory);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_ShellWorkingDirectory, file->ShellWorkingDirectory) != 0)
+ return FALSE;
+ }
if (~file->ScreenModeId)
{
if (~((size_t) file->LoadBalanceInfo))
{
settings->LoadBalanceInfo = (BYTE*) _strdup(file->LoadBalanceInfo);
+ if (!settings->LoadBalanceInfo)
+ return FALSE;
settings->LoadBalanceInfoLength = (int) strlen((char*) settings->LoadBalanceInfo);
}
int port = -1;
char* host = NULL;
- freerdp_parse_hostname(file->GatewayHostname, &host, &port);
+ if (freerdp_parse_hostname(file->GatewayHostname, &host, &port) != 0)
+ return FALSE;
- freerdp_set_param_string(settings, FreeRDP_GatewayHostname, host);
+ if (freerdp_set_param_string(settings, FreeRDP_GatewayHostname, host) != 0)
+ return FALSE;
if (port > 0)
freerdp_set_param_uint32(settings, FreeRDP_GatewayPort, (UINT32) port);
if (~file->RemoteApplicationMode)
freerdp_set_param_bool(settings, FreeRDP_RemoteApplicationMode, file->RemoteApplicationMode);
if (~((size_t) file->RemoteApplicationProgram))
- freerdp_set_param_string(settings, FreeRDP_RemoteApplicationProgram, file->RemoteApplicationProgram);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_RemoteApplicationProgram, file->RemoteApplicationProgram) != 0)
+ return FALSE;
+ }
if (~((size_t) file->RemoteApplicationName))
- freerdp_set_param_string(settings, FreeRDP_RemoteApplicationName, file->RemoteApplicationName);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_RemoteApplicationName, file->RemoteApplicationName) != 0)
+ return FALSE;
+ }
if (~((size_t) file->RemoteApplicationIcon))
- freerdp_set_param_string(settings, FreeRDP_RemoteApplicationIcon, file->RemoteApplicationIcon);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_RemoteApplicationIcon, file->RemoteApplicationIcon) != 0)
+ return FALSE;
+ }
if (~((size_t) file->RemoteApplicationFile))
- freerdp_set_param_string(settings, FreeRDP_RemoteApplicationGuid, file->RemoteApplicationGuid);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_RemoteApplicationGuid, file->RemoteApplicationGuid) != 0)
+ return FALSE;
+ }
if (~((size_t) file->RemoteApplicationCmdLine))
- freerdp_set_param_string(settings, FreeRDP_RemoteApplicationCmdLine, file->RemoteApplicationCmdLine);
+ {
+ if (freerdp_set_param_string(settings, FreeRDP_RemoteApplicationCmdLine, file->RemoteApplicationCmdLine) != 0)
+ return FALSE;
+ }
if (~file->SpanMonitors)
freerdp_set_param_bool(settings, FreeRDP_SpanMonitors, file->SpanMonitors);
char* ConnectionFile = settings->ConnectionFile;
settings->ConnectionFile = NULL;
- freerdp_client_settings_parse_command_line(settings, file->argc, file->argv, FALSE);
+ if (freerdp_client_settings_parse_command_line(settings, file->argc, file->argv, FALSE) < 0)
+ return FALSE;
settings->ConnectionFile = ConnectionFile;
}
return TRUE;
}
-rdpFileLine* freerdp_client_rdp_file_find_line_index(rdpFile* file, int index)
+static rdpFileLine* freerdp_client_rdp_file_find_line_index(rdpFile* file, int index)
{
rdpFileLine* line;
return line;
}
-rdpFileLine* freerdp_client_rdp_file_find_line_by_name(rdpFile* file, const char* name)
+static rdpFileLine* freerdp_client_rdp_file_find_line_by_name(rdpFile* file, const char* name)
{
int index;
BOOL bFound = FALSE;
return (bFound) ? line : NULL;
}
+/**
+ * Set a string option to a rdpFile
+ * @param file rdpFile
+ * @param name name of the option
+ * @param value value of the option
+ * @return 0 on success
+ */
+
int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, const char* value)
{
int index;
char* text;
rdpFileLine* line;
- line = freerdp_client_rdp_file_find_line_by_name(file, name);
-
length = _scprintf("%s:s:%s", name, value);
text = (char*) malloc(length + 1);
+ if (!text)
+ return -1;
sprintf_s(text, length + 1, "%s:s:%s", name, value ? value : "");
text[length] = '\0';
+ line = freerdp_client_rdp_file_find_line_by_name(file, name);
if (line)
{
free(line->sValue);
line->sValue = _strdup(value);
+ if (!line->sValue)
+ goto out_fail;
free(line->text);
line->text = text;
else
{
index = freerdp_client_parse_rdp_file_add_line(file, text, -1);
- line = freerdp_client_rdp_file_find_line_index(file, index);
+ if (index == -1)
+ goto out_fail;
- freerdp_client_rdp_file_set_string(file, name, value, index);
+ if (!(line = freerdp_client_rdp_file_find_line_index(file, index)))
+ goto out_fail;
+
+ if (freerdp_client_rdp_file_set_string(file, name, value, index) == -1)
+ goto out_fail;
free(text);
}
return 0;
+
+out_fail:
+ free(text);
+ return -1;
+
}
const char* freerdp_client_rdp_file_get_string_option(rdpFile* file, const char* name)
else
{
index = freerdp_client_parse_rdp_file_add_line(file, text, -1);
+ if (index < 0)
+ {
+ free(text);
+ return -1;
+ }
line = freerdp_client_rdp_file_find_line_index(file, index);
- freerdp_client_rdp_file_set_integer(file, (char*) name, value, index);
+ if (freerdp_client_rdp_file_set_integer(file, (char*) name, value, index) < 0)
+ {
+ free(text);
+ return -1;
+ }
free(text);
}
return line->iValue;
}
-void freerdp_client_file_string_check_free(LPSTR str)
+static void freerdp_client_file_string_check_free(LPSTR str)
{
if (~((size_t) str))
free(str);
file->lineCount = 0;
file->lineSize = 32;
file->lines = (rdpFileLine*) malloc(file->lineSize * sizeof(rdpFileLine));
+ if (!file->lines)
+ {
+ free(file);
+ return NULL;
+ }
+
file->argc = 0;
file->argSize = 32;
file->argv = (char**) malloc(file->argSize * sizeof(char*));
+ if (!file->argv)
+ {
+ free(file->lines);
+ free(file);
+ return NULL;
+ }
- freerdp_client_add_option(file, "freerdp");
+ if (!freerdp_client_add_option(file, "freerdp"))
+ {
+ free(file->argv);
+ free(file->lines);
+ free(file);
+ return NULL;
+ }
}
return file;
/* Unicode */
file = freerdp_client_rdp_file_new();
+ if (!file)
+ {
+ printf("rdp_file_new failed\n");
+ return -1;
+ }
freerdp_client_parse_rdp_file_buffer(file, testRdpFileUTF16, sizeof(testRdpFileUTF16));
if (file->UseMultiMon != 0)
}
iValue = freerdp_client_rdp_file_get_integer_option(file, "vendor integer");
- freerdp_client_rdp_file_set_integer_option(file, "vendor integer", 456);
+ if (freerdp_client_rdp_file_set_integer_option(file, "vendor integer", 456) == -1)
+ {
+ printf("failed to set integer: vendor integer");
+ return -1;
+ }
+
iValue = freerdp_client_rdp_file_get_integer_option(file, "vendor integer");
sValue = (char*) freerdp_client_rdp_file_get_string_option(file, "vendor string");
sValue = (char*) freerdp_client_rdp_file_get_string_option(file, "vendor string");
freerdp_client_rdp_file_set_string_option(file, "fruits", "banana,oranges");
- freerdp_client_rdp_file_set_integer_option(file, "numbers", 123456789);
+ if (freerdp_client_rdp_file_set_integer_option(file, "numbers", 123456789) == -1)
+ {
+ printf("failed to set integer: numbers");
+ return -1;
+ }
for (index = 0; index < file->lineCount; index++)
{
#import <freerdp/channels/channels.h>
#import <freerdp/client/channels.h>
#import <freerdp/client/cmdline.h>
+#import <freerdp/freerdp.h>
#import "ios_freerdp.h"
#import "ios_freerdp_ui.h"
#import "RDPSession.h"
#import "Utils.h"
-
#pragma mark Connection helpers
static BOOL ios_pre_connect(freerdp* instance)
freerdp* ios_freerdp_new()
{
freerdp* inst = freerdp_new();
+ if (!inst)
+ return NULL;
inst->PreConnect = ios_pre_connect;
inst->PostConnect = ios_post_connect;
free(inst->settings->ConfigPath);
inst->settings->HomePath = strdup([home_path UTF8String]);
inst->settings->ConfigPath = strdup([[home_path stringByAppendingPathComponent:@".freerdp"] UTF8String]);
+ if (!inst->settings->HomePath || !inst->settings->ConfigPath)
+ {
+ free(inst->settings->HomePath);
+ free(inst->settings->ConfigPath);
+ freerdp_context_free(inst);
+ freerdp_free(inst);
+ return NULL;
+ }
return inst;
}
*username = strdup([[params objectForKey:@"username"] UTF8String]);
*password = strdup([[params objectForKey:@"password"] UTF8String]);
*domain = strdup([[params objectForKey:@"domain"] UTF8String]);
+
+ if (!(*username) || !(*password) || !(*domain))
+ {
+ free(*username);
+ free(*password);
+ free(*domain);
+ return FALSE;
+ }
return TRUE;
}
char* ms_sample_path;
ms_sample_path = _strdup("/tmp/EGFX_PROGRESSIVE_MS_SAMPLE");
+ if (!ms_sample_path)
+ {
+ printf("Memory allocation failed\n");
+ return -1;
+ }
if (PathFileExistsA(ms_sample_path))
return test_progressive_ms_sample(ms_sample_path);
cchPath = cchInstallPrefix + cchAddinPath + 2;
pszPath = (LPSTR) malloc(cchPath + 1);
+ if (!pszPath)
+ return NULL;
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
pszPath[cchInstallPrefix] = '\0';
}
pszAddinInstallPath = freerdp_get_dynamic_addin_install_path();
+ if (!pszAddinInstallPath)
+ return NULL;
cchAddinInstallPath = strlen(pszAddinInstallPath);
cchFilePath = cchAddinInstallPath + cchFileName + 32;
pszFilePath = (LPSTR) malloc(cchFilePath + 1);
+ if (!pszFilePath)
+ {
+ free(pszAddinInstallPath);
+ return NULL;
+ }
if (bHasExt)
{
pszAddinFile = _strdup(pszFileName);
+ if (!pszAddinFile)
+ {
+ free(pszAddinInstallPath);
+ free(pszFilePath);
+ return NULL;
+ }
cchAddinFile = strlen(pszAddinFile);
}
else
{
cchAddinFile = cchFileName + cchExt + 2 + sizeof(CMAKE_SHARED_LIBRARY_PREFIX);
pszAddinFile = (LPSTR) malloc(cchAddinFile + 1);
+ if (!pszAddinFile)
+ {
+ free(pszAddinInstallPath);
+ free(pszFilePath);
+ return NULL;
+ }
sprintf_s(pszAddinFile, cchAddinFile, CMAKE_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt);
cchAddinFile = strlen(pszAddinFile);
}
int count;
int length;
char** tokens;
+ int ret = -1;
count = 1;
str = _strdup(list);
}
tokens = (char**) malloc(sizeof(char*) * count);
-
if (!tokens)
+ {
+ free(str);
return -1;
+ }
count = 0;
tokens[count++] = str;
file->MachinePorts = (UINT32*) calloc(count, sizeof(UINT32));
if (!file->MachineAddresses || !file->MachinePorts)
- {
- free(file->MachineAddresses);
- free(file->MachinePorts);
- free(tokens);
- return -1;
- }
+ goto out;
for (i = 0; i < count; i++)
{
q = strchr(p, ':');
if (!q)
- {
- free(tokens);
- return -1;
- }
+ goto out;
q[0] = '\0';
q++;
q = strchr(p, ':');
if (!q)
- {
- free(tokens);
- return -1;
- }
+ goto out;
q[0] = '\0';
q++;
+ if (file->MachineAddress)
+ free(file->MachineAddress);
file->MachineAddress = _strdup(p);
+ if (!file->MachineAddress)
+ goto out;
file->MachinePort = (UINT32) atoi(q);
if (!file->MachineAddress)
- return -1;
+ goto out;
break;
}
+ ret = 1;
+out:
free(tokens);
-
- return 1;
+ free(str);
+ return ret;
}
int freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
int count;
int length;
char* tokens[8];
+ int ret;
/**
* <ProtocolVersion>,<protocolType>,<machineAddressList>,<assistantAccountPwd>,
if (!file->RASpecificParams)
return -1;
- freerdp_assistance_parse_address_list(file, tokens[2]);
+ ret = freerdp_assistance_parse_address_list(file, tokens[2]);
free(str);
+ if (ret != 1)
+ return -1;
+
return 1;
}
int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
{
- char* p;
- char* q;
- int port;
char* str;
- size_t length;
-
- str = _strdup(file->ConnectionString2);
+ char* tag;
+ char* end;
+ char* p;
+ int ret = -1;
- if (!str)
- return -1;
- p = strstr(str, "<E>");
+ str = file->ConnectionString2;
- if (!p)
+ if (!strstr(str, "<E>"))
return -1;
- p = strstr(str, "<C>");
-
- if (!p)
+ if (!strstr(str, "<C>"))
return -1;
- /* Auth String Node (<A>) */
+ str = _strdup(file->ConnectionString2);
+ if (!str)
+ return -1;
- p = strstr(str, "<A");
+ if (!(tag = strstr(str, "<A")))
+ goto out_fail;
- if (!p)
- return -1;
+ /* Parse Auth String Node (<A>) */
+ end = strstr(tag, "/>");
+ if (!end)
+ goto out_fail;
- p = strstr(p, "KH=\"");
+ *end = '\0';
+ p = strstr(tag, "KH=\"");
if (p)
{
+ char *q;
+ size_t length;
p += sizeof("KH=\"") - 1;
q = strchr(p, '"');
if (!q)
- return -1;
+ goto out_fail;
length = q - p;
free(file->RASpecificParams);
file->RASpecificParams = (char*) malloc(length + 1);
-
if (!file->RASpecificParams)
- return -1;
+ goto out_fail;
CopyMemory(file->RASpecificParams, p, length);
file->RASpecificParams[length] = '\0';
-
- p += length;
}
- if (p)
- p = strstr(p, "ID=\"");
- else
- p = _strdup("ID=\"");
-
+ p = strstr(tag, "ID=\"");
if (p)
{
+ char *q;
+ size_t length;
p += sizeof("ID=\"") - 1;
q = strchr(p, '"');
if (!q)
- return -1;
+ goto out_fail;
length = q - p;
free(file->RASessionId);
file->RASessionId = (char*) malloc(length + 1);
-
if (!file->RASessionId)
- return -1;
+ goto out_fail;
CopyMemory(file->RASessionId, p, length);
file->RASessionId[length] = '\0';
-
- p += length;
}
+ *end = '/';
- if (p)
- p = strstr(p, "<L P=\"");
- else
- p = _strdup("<L P=\"");
+ /* Parse <L last address is used */
+ p = strstr(str, "<L P=\"");
while (p)
{
+ char *q;
+ int port;
+ size_t length;
p += sizeof("<L P=\"") - 1;
q = strchr(p, '"');
if (!q)
- return -1;
+ goto out_fail;
q[0] = '\0';
q++;
p = strstr(q, " N=\"");
if (!p)
- return -1;
+ goto out_fail;
p += sizeof(" N=\"") - 1;
q = strchr(p, '"');
if (!q)
- return -1;
+ goto out_fail;
q[0] = '\0';
q++;
{
if (strncmp(p, "169.254.", 8) != 0)
{
+ if (file->MachineAddress)
+ free(file->MachineAddress);
file->MachineAddress = _strdup(p);
+ if (!file->MachineAddress)
+ goto out_fail;
file->MachinePort = (UINT32) port;
break;
}
p = strstr(q, "<L P=\"");
}
+ ret = 1;
+out_fail:
free(str);
+ return ret;
- return 1;
}
char* freerdp_assistance_construct_expert_blob(const char* name, const char* pass)
status = freerdp_assistance_parse_connection_string2(file);
WLog_DBG(TAG, "freerdp_assistance_parse_connection_string2: %d", status);
- return 1;
+ return status;
}
int freerdp_assistance_decrypt(rdpAssistanceFile* file, const char* password)
freerdp_set_param_bool(settings, FreeRDP_RemoteAssistanceMode, TRUE);
- if (!file->RASessionId)
+ if (!file->RASessionId || !file->MachineAddress)
return -1;
- freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceSessionId, file->RASessionId);
+ if (freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceSessionId, file->RASessionId) != 0)
+ return -1;
- if (file->RCTicket)
- freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceRCTicket, file->RCTicket);
+ if (file->RCTicket && (freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceRCTicket, file->RCTicket) != 0))
+ return -1;
- if (file->PassStub)
- freerdp_set_param_string(settings, FreeRDP_RemoteAssistancePassStub, file->PassStub);
+ if (file->PassStub && (freerdp_set_param_string(settings, FreeRDP_RemoteAssistancePassStub, file->PassStub) != 0))
+ return -1;
- if (!file->MachineAddress)
+ if (freerdp_set_param_string(settings, FreeRDP_ServerHostname, file->MachineAddress) != 0)
return -1;
- freerdp_set_param_string(settings, FreeRDP_ServerHostname, file->MachineAddress);
freerdp_set_param_uint32(settings, FreeRDP_ServerPort, file->MachinePort);
freerdp_target_net_addresses_free(settings);
rdpAssistanceFile* freerdp_assistance_file_new()
{
- rdpAssistanceFile* file;
-
- file = (rdpAssistanceFile*) calloc(1, sizeof(rdpAssistanceFile));
-
- if (file)
- {
-
- }
-
- return file;
+ return (rdpAssistanceFile*) calloc(1, sizeof(rdpAssistanceFile));
}
void freerdp_assistance_file_free(rdpAssistanceFile* file)
return -1;
args->argv = new_argv;
args->argc++;
- args->argv[args->argc - 1] = _strdup(argument);
+ if (!(args->argv[args->argc - 1] = _strdup(argument)))
+ return -1;
return 0;
}
if (strcmp(args->argv[i], previous) == 0)
{
free(args->argv[i]);
- args->argv[i] = _strdup(argument);
+ if (!(args->argv[i] = _strdup(argument)))
+ return -1;
return 1;
}
return -1;
args->argv = new_argv;
args->argc++;
- args->argv[args->argc - 1] = _strdup(argument);
+ if (!(args->argv[args->argc - 1] = _strdup(argument)))
+ return -1;
return 0;
}
{
device = (RDPDR_DEVICE*) settings->DeviceArray[index];
+ if (!device)
+ continue;
+
free(device->Name);
if (settings->DeviceArray[index]->Type == RDPDR_DTYP_FILESYSTEM)
for (i = 0; i < settings->StaticChannelCount; i++)
{
+ if (!settings->StaticChannelArray[i])
+ continue;
+
for (j = 0; j < settings->StaticChannelArray[i]->argc; j++)
free(settings->StaticChannelArray[i]->argv[j]);
for (i = 0; i < settings->DynamicChannelCount; i++)
{
+ if (!settings->DynamicChannelArray[i])
+ continue;
+
for (j = 0; j < settings->DynamicChannelArray[i]->argc; j++)
free(settings->DynamicChannelArray[i]->argv[j]);
int freerdp_set_param_string(rdpSettings* settings, int id, const char* param)
{
+#define CHECKED_STRDUP(name) if (param && !(settings->name = _strdup(param))) return -1
switch (id)
{
case FreeRDP_ServerHostname:
free(settings->ServerHostname);
- settings->ServerHostname = _strdup(param);
+ CHECKED_STRDUP(ServerHostname);
break;
case FreeRDP_Username:
free(settings->Username);
- settings->Username = _strdup(param);
+ CHECKED_STRDUP(Username);
break;
case FreeRDP_Password:
free(settings->Password);
- settings->Password = _strdup(param);
+ CHECKED_STRDUP(Password);
break;
case FreeRDP_Domain:
free(settings->Domain);
- settings->Domain = _strdup(param);
+ CHECKED_STRDUP(Domain);
break;
case FreeRDP_PasswordHash:
free(settings->PasswordHash);
- settings->PasswordHash = _strdup(param);
+ CHECKED_STRDUP(PasswordHash);
break;
case FreeRDP_ClientHostname:
free(settings->ClientHostname);
- settings->ClientHostname = _strdup(param);
+ CHECKED_STRDUP(ClientHostname);
break;
case FreeRDP_ClientProductId:
free(settings->ClientProductId);
- settings->ClientProductId = _strdup(param);
+ CHECKED_STRDUP(ClientProductId);
break;
case FreeRDP_AlternateShell:
free(settings->AlternateShell);
- settings->AlternateShell = _strdup(param);
+ CHECKED_STRDUP(AlternateShell);
break;
case FreeRDP_ShellWorkingDirectory:
free(settings->ShellWorkingDirectory);
- settings->ShellWorkingDirectory = _strdup(param);
+ CHECKED_STRDUP(ShellWorkingDirectory);
break;
case FreeRDP_ClientAddress:
free(settings->ClientAddress);
- settings->ClientAddress = _strdup(param);
+ CHECKED_STRDUP(ClientAddress);
break;
case FreeRDP_ClientDir:
free(settings->ClientDir);
- settings->ClientDir = _strdup(param);
+ CHECKED_STRDUP(ClientDir);
break;
case FreeRDP_DynamicDSTTimeZoneKeyName:
free(settings->DynamicDSTTimeZoneKeyName);
- settings->DynamicDSTTimeZoneKeyName = _strdup(param);
+ CHECKED_STRDUP(DynamicDSTTimeZoneKeyName);
break;
case FreeRDP_RemoteAssistanceSessionId:
free(settings->RemoteAssistanceSessionId);
- settings->RemoteAssistanceSessionId = _strdup(param);
+ CHECKED_STRDUP(RemoteAssistanceSessionId);
break;
case FreeRDP_RemoteAssistancePassStub:
free(settings->RemoteAssistancePassStub);
- settings->RemoteAssistancePassStub = _strdup(param);
+ CHECKED_STRDUP(RemoteAssistancePassStub);
break;
case FreeRDP_RemoteAssistancePassword:
free(settings->RemoteAssistancePassword);
- settings->RemoteAssistancePassword = _strdup(param);
+ CHECKED_STRDUP(RemoteAssistancePassword);
break;
case FreeRDP_RemoteAssistanceRCTicket:
free(settings->RemoteAssistanceRCTicket);
- settings->RemoteAssistanceRCTicket = _strdup(param);
+ CHECKED_STRDUP(RemoteAssistanceRCTicket);
break;
case FreeRDP_AuthenticationServiceClass:
free(settings->AuthenticationServiceClass);
- settings->AuthenticationServiceClass = _strdup(param);
+ CHECKED_STRDUP(AuthenticationServiceClass);
break;
case FreeRDP_PreconnectionBlob:
free(settings->PreconnectionBlob);
- settings->PreconnectionBlob = _strdup(param);
+ CHECKED_STRDUP(PreconnectionBlob);
break;
case FreeRDP_KerberosKdc:
free(settings->KerberosKdc);
- settings->KerberosKdc = _strdup(param);
+ CHECKED_STRDUP(KerberosKdc);
break;
case FreeRDP_KerberosRealm:
free(settings->KerberosRealm);
- settings->KerberosRealm = _strdup(param);
+ CHECKED_STRDUP(KerberosRealm);
break;
case FreeRDP_CertificateName:
free(settings->CertificateName);
- settings->CertificateName = _strdup(param);
+ CHECKED_STRDUP(CertificateName);
break;
case FreeRDP_CertificateFile:
free(settings->CertificateFile);
- settings->CertificateFile = _strdup(param);
+ CHECKED_STRDUP(CertificateFile);
break;
case FreeRDP_PrivateKeyFile:
free(settings->PrivateKeyFile);
- settings->PrivateKeyFile = _strdup(param);
+ CHECKED_STRDUP(PrivateKeyFile);
break;
case FreeRDP_RdpKeyFile:
free(settings->RdpKeyFile);
- settings->RdpKeyFile = _strdup(param);
+ CHECKED_STRDUP(RdpKeyFile);
break;
case FreeRDP_WindowTitle:
free(settings->WindowTitle);
- settings->WindowTitle = _strdup(param);
+ CHECKED_STRDUP(WindowTitle);
break;
case FreeRDP_ComputerName:
free(settings->ComputerName);
- settings->ComputerName = _strdup(param);
+ CHECKED_STRDUP(ComputerName);
break;
case FreeRDP_ConnectionFile:
free(settings->ConnectionFile);
- settings->ConnectionFile = _strdup(param);
+ CHECKED_STRDUP(ConnectionFile);
break;
case FreeRDP_AssistanceFile:
free(settings->AssistanceFile);
- settings->AssistanceFile = _strdup(param);
+ CHECKED_STRDUP(AssistanceFile);
break;
case FreeRDP_HomePath:
free(settings->HomePath);
- settings->HomePath = _strdup(param);
+ CHECKED_STRDUP(HomePath);
break;
case FreeRDP_ConfigPath:
free(settings->ConfigPath);
- settings->ConfigPath = _strdup(param);
+ CHECKED_STRDUP(ConfigPath);
break;
case FreeRDP_CurrentPath:
free(settings->CurrentPath);
- settings->CurrentPath = _strdup(param);
+ CHECKED_STRDUP(CurrentPath);
break;
case FreeRDP_DumpRemoteFxFile:
free(settings->DumpRemoteFxFile);
- settings->DumpRemoteFxFile = _strdup(param);
+ CHECKED_STRDUP(DumpRemoteFxFile);
break;
case FreeRDP_PlayRemoteFxFile:
free(settings->PlayRemoteFxFile);
- settings->PlayRemoteFxFile = _strdup(param);
+ CHECKED_STRDUP(PlayRemoteFxFile);
break;
case FreeRDP_GatewayHostname:
free(settings->GatewayHostname);
- settings->GatewayHostname = _strdup(param);
+ CHECKED_STRDUP(GatewayHostname);
break;
case FreeRDP_GatewayUsername:
free(settings->GatewayUsername);
- settings->GatewayUsername = _strdup(param);
+ CHECKED_STRDUP(GatewayUsername);
break;
case FreeRDP_GatewayPassword:
free(settings->GatewayPassword);
- settings->GatewayPassword = _strdup(param);
+ CHECKED_STRDUP(GatewayPassword);
break;
case FreeRDP_GatewayDomain:
free(settings->GatewayDomain);
- settings->GatewayDomain = _strdup(param);
+ CHECKED_STRDUP(GatewayDomain);
break;
case FreeRDP_RemoteApplicationName:
free(settings->RemoteApplicationName);
- settings->RemoteApplicationName = _strdup(param);
+ CHECKED_STRDUP(RemoteApplicationName);
break;
case FreeRDP_RemoteApplicationIcon:
free(settings->RemoteApplicationIcon);
- settings->RemoteApplicationIcon = _strdup(param);
+ CHECKED_STRDUP(RemoteApplicationIcon);
break;
case FreeRDP_RemoteApplicationProgram:
free(settings->RemoteApplicationProgram);
- settings->RemoteApplicationProgram = _strdup(param);
+ CHECKED_STRDUP(RemoteApplicationProgram);
break;
case FreeRDP_RemoteApplicationFile:
free(settings->RemoteApplicationFile);
- settings->RemoteApplicationFile = _strdup(param);
+ CHECKED_STRDUP(RemoteApplicationFile);
break;
case FreeRDP_RemoteApplicationGuid:
free(settings->RemoteApplicationGuid);
- settings->RemoteApplicationGuid = _strdup(param);
+ CHECKED_STRDUP(RemoteApplicationGuid);
break;
case FreeRDP_RemoteApplicationCmdLine:
free(settings->RemoteApplicationCmdLine);
- settings->RemoteApplicationCmdLine = _strdup(param);
+ CHECKED_STRDUP(RemoteApplicationCmdLine);
break;
case FreeRDP_ImeFileName:
free(settings->ImeFileName);
- settings->ImeFileName = _strdup(param);
+ CHECKED_STRDUP(ImeFileName);
break;
case FreeRDP_DrivesToRedirect:
free(settings->DrivesToRedirect);
- settings->DrivesToRedirect = _strdup(param);
+ CHECKED_STRDUP(DrivesToRedirect);
break;
default:
file = freerdp_assistance_file_new();
+ if (!file)
+ return -1;
+
status = freerdp_assistance_parse_file_buffer(file,
TEST_MSRC_INCIDENT_FILE_TYPE1, sizeof(TEST_MSRC_INCIDENT_FILE_TYPE1));
file = freerdp_assistance_file_new();
+ if (!file)
+ return -1;
+
status = freerdp_assistance_parse_file_buffer(file,
TEST_MSRC_INCIDENT_FILE_TYPE2, sizeof(TEST_MSRC_INCIDENT_FILE_TYPE2));
int TestCommonAssistance(int argc, char* argv[])
{
- test_msrsc_incident_file_type1();
+ if (test_msrsc_incident_file_type1() != 0)
+ {
+ printf("test_msrsc_incident_file_type1 failed\n");
+ return -1;
+ }
- test_msrsc_incident_file_type2();
+ if (test_msrsc_incident_file_type2() != 0)
+ {
+ printf("test_msrsc_incident_file_type1 failed\n");
+ return -1;
+ }
return 0;
}
if (certificate->cert_info.ModulusLength)
{
_certificate->cert_info.Modulus = (BYTE*) malloc(certificate->cert_info.ModulusLength);
+ if (!_certificate->cert_info.Modulus)
+ goto out_fail;
CopyMemory(_certificate->cert_info.Modulus, certificate->cert_info.Modulus, certificate->cert_info.ModulusLength);
_certificate->cert_info.ModulusLength = certificate->cert_info.ModulusLength;
}
if (certificate->x509_cert_chain)
{
_certificate->x509_cert_chain = (rdpX509CertChain*) malloc(sizeof(rdpX509CertChain));
+ if (!_certificate->x509_cert_chain)
+ goto out_fail;
CopyMemory(_certificate->x509_cert_chain, certificate->x509_cert_chain, sizeof(rdpX509CertChain));
if (certificate->x509_cert_chain->count)
{
_certificate->x509_cert_chain->array = (rdpCertBlob*) calloc(certificate->x509_cert_chain->count, sizeof(rdpCertBlob));
+ if (!_certificate->x509_cert_chain->array)
+ goto out_fail;
for (index = 0; index < certificate->x509_cert_chain->count; index++)
{
if (certificate->x509_cert_chain->array[index].length)
{
_certificate->x509_cert_chain->array[index].data = (BYTE*) malloc(certificate->x509_cert_chain->array[index].length);
+ if (!_certificate->x509_cert_chain->array[index].data)
+ {
+ for (--index; index >= 0; --index)
+ {
+ if (certificate->x509_cert_chain->array[index].length)
+ free(_certificate->x509_cert_chain->array[index].data);
+ }
+ goto out_fail;
+ }
CopyMemory(_certificate->x509_cert_chain->array[index].data, certificate->x509_cert_chain->array[index].data,
_certificate->x509_cert_chain->array[index].length);
}
}
return _certificate;
+
+out_fail:
+ if (certificate->x509_cert_chain->count)
+ {
+ free(_certificate->x509_cert_chain->array);
+ }
+ free(_certificate->x509_cert_chain);
+ free(_certificate->cert_info.Modulus);
+ free(_certificate);
+ return NULL;
}
/**
rdpSettings* settings = rdp->settings;
rdp_client_disconnect(rdp);
- rdp_redirection_apply_settings(rdp);
+ if (rdp_redirection_apply_settings(rdp) != 0)
+ return FALSE;
if (settings->RedirectionFlags & LB_LOAD_BALANCE_INFO)
{
- nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength);
+ if (!nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength))
+ return FALSE;
}
else
{
{
free(settings->ServerHostname);
settings->ServerHostname = _strdup(settings->RedirectionTargetFQDN);
+ if (!settings->ServerHostname)
+ return FALSE;
}
else if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS)
{
free(settings->ServerHostname);
settings->ServerHostname = _strdup(settings->TargetNetAddress);
+ if (!settings->ServerHostname)
+ return FALSE;
}
else if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME)
{
free(settings->ServerHostname);
settings->ServerHostname = _strdup(settings->RedirectionTargetNetBiosName);
+ if (!settings->ServerHostname)
+ return FALSE;
}
}
{
free(settings->Username);
settings->Username = _strdup(settings->RedirectionUsername);
+ if (!settings->Username)
+ return FALSE;
}
if (settings->RedirectionFlags & LB_DOMAIN)
{
free(settings->Domain);
settings->Domain = _strdup(settings->RedirectionDomain);
+ if (!settings->Domain)
+ return FALSE;
}
status = rdp_client_connect(rdp);
if (settings->GatewayUseSameCredentials)
{
- settings->Username = _strdup(settings->GatewayUsername);
- settings->Domain = _strdup(settings->GatewayDomain);
- settings->Password = _strdup(settings->GatewayPassword);
+ if (settings->GatewayUsername)
+ {
+ free(settings->Username);
+ if (!(settings->Username = _strdup(settings->GatewayUsername)))
+ return -1;
+ }
+ if (settings->GatewayDomain)
+ {
+ free(settings->Domain);
+ if (!(settings->Domain = _strdup(settings->GatewayDomain)))
+ return -1;
+ }
+ if (settings->GatewayPassword)
+ {
+ free(settings->Password);
+ if (!(settings->Password = _strdup(settings->GatewayPassword)))
+ return -1;
+ }
}
}
}
if (settings->GatewayUseSameCredentials)
{
- settings->Username = _strdup(settings->GatewayUsername);
- settings->Domain = _strdup(settings->GatewayDomain);
- settings->Password = _strdup(settings->GatewayPassword);
+ if (settings->GatewayUsername)
+ {
+ free(settings->Username);
+ if (!(settings->Username = _strdup(settings->GatewayUsername)))
+ return FALSE;
+ }
+ if (settings->GatewayDomain)
+ {
+ free(settings->Domain);
+ if (!(settings->Domain = _strdup(settings->GatewayDomain)))
+ return FALSE;
+ }
+ if (settings->GatewayPassword)
+ {
+ free(settings->Password);
+ if (!(settings->Password = _strdup(settings->GatewayPassword)))
+ return FALSE;
+ }
}
}
}
hostnameX = _strdup(hostname);
ServiceClassX = _strdup(ServiceClass);
#endif
+ if (!hostnameX || !ServiceClassX)
+ {
+ free(hostnameX);
+ free(ServiceClassX);
+ return NULL;
+ }
if (!ServiceClass)
{
{
free(settings->RedirectionTargetFQDN);
settings->RedirectionTargetFQDN = _strdup(redirection->TargetFQDN);
+ if (!settings->RedirectionTargetFQDN)
+ return -1;
}
else if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS)
{
free(settings->TargetNetAddress);
settings->TargetNetAddress = _strdup(redirection->TargetNetAddress);
+ if (!settings->TargetNetAddress)
+ return -1;
}
else if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME)
{
free(settings->RedirectionTargetNetBiosName);
settings->RedirectionTargetNetBiosName = _strdup(redirection->TargetNetBiosName);
+ if (!settings->RedirectionTargetNetBiosName)
+ return -1;
}
if (settings->RedirectionFlags & LB_USERNAME)
{
free(settings->RedirectionUsername);
settings->RedirectionUsername = _strdup(redirection->Username);
+ if (!settings->RedirectionUsername)
+ return -1;
}
if (settings->RedirectionFlags & LB_DOMAIN)
{
free(settings->RedirectionDomain);
settings->RedirectionDomain = _strdup(redirection->Domain);
+ if (!settings->RedirectionDomain)
+ return -1;
}
if (settings->RedirectionFlags & LB_PASSWORD)
free(settings->RedirectionPassword);
settings->RedirectionPasswordLength = redirection->PasswordLength;
settings->RedirectionPassword = (BYTE*) malloc(settings->RedirectionPasswordLength);
+ if (!settings->RedirectionPassword)
+ return -1;
CopyMemory(settings->RedirectionPassword, redirection->Password, settings->RedirectionPasswordLength);
}
free(settings->RedirectionTsvUrl);
settings->RedirectionTsvUrlLength = redirection->TsvUrlLength;
settings->RedirectionTsvUrl = (BYTE*) malloc(settings->RedirectionTsvUrlLength);
+ if (!settings->RedirectionTsvUrl)
+ return -1;
CopyMemory(settings->RedirectionTsvUrl, redirection->TsvUrl, settings->RedirectionTsvUrlLength);
}
freerdp_target_net_addresses_free(settings);
settings->TargetNetAddressCount = redirection->TargetNetAddressesCount;
settings->TargetNetAddresses = (char**) malloc(sizeof(char*) * settings->TargetNetAddressCount);
+ if (!settings->TargetNetAddresses)
+ {
+ settings->TargetNetAddressCount = 0;
+ return -1;
+ }
for (i = 0; i < settings->TargetNetAddressCount; i++)
{
settings->TargetNetAddresses[i] = _strdup(redirection->TargetNetAddresses[i]);
+ if (!settings->TargetNetAddresses[i])
+ {
+ for (--i; i >= 0; --i)
+ free(settings->TargetNetAddresses[i]);
+ return -1;
+ }
}
}
{
CopyMemory(_settings, settings, sizeof(rdpSettings));
- /**
- * Generated Code
- */
-
/* char* values */
-
- _settings->ServerHostname = _strdup(settings->ServerHostname); /* 20 */
- _settings->Username = _strdup(settings->Username); /* 21 */
- _settings->Password = _strdup(settings->Password); /* 22 */
- _settings->Domain = _strdup(settings->Domain); /* 23 */
- _settings->PasswordHash = _strdup(settings->PasswordHash); /* 24 */
+#define CHECKED_STRDUP(name) if (settings->name && !(_settings->name = _strdup(settings->name))) goto out_fail
+ CHECKED_STRDUP(ServerHostname); /* 20 */
+ CHECKED_STRDUP(Username); /* 21 */
+ CHECKED_STRDUP(Password); /* 22 */
+ CHECKED_STRDUP(Domain); /* 23 */
+ CHECKED_STRDUP(PasswordHash); /* 24 */
_settings->ClientHostname = NULL; /* 134 */
_settings->ClientProductId = NULL; /* 135 */
- _settings->AlternateShell = _strdup(settings->AlternateShell); /* 640 */
- _settings->ShellWorkingDirectory = _strdup(settings->ShellWorkingDirectory); /* 641 */
- _settings->ClientAddress = _strdup(settings->ClientAddress); /* 769 */
- _settings->ClientDir = _strdup(settings->ClientDir); /* 770 */
- _settings->DynamicDSTTimeZoneKeyName = _strdup(settings->DynamicDSTTimeZoneKeyName); /* 897 */
- _settings->RemoteAssistanceSessionId = _strdup(settings->RemoteAssistanceSessionId); /* 1025 */
- _settings->RemoteAssistancePassStub = _strdup(settings->RemoteAssistancePassStub); /* 1026 */
- _settings->RemoteAssistancePassword = _strdup(settings->RemoteAssistancePassword); /* 1027 */
- _settings->RemoteAssistanceRCTicket = _strdup(settings->RemoteAssistanceRCTicket); /* 1028 */
- _settings->AuthenticationServiceClass = _strdup(settings->AuthenticationServiceClass); /* 1098 */
- _settings->AllowedTlsCiphers = _strdup(settings->AllowedTlsCiphers); /* 1101 */
- _settings->PreconnectionBlob = _strdup(settings->PreconnectionBlob); /* 1155 */
- _settings->KerberosKdc = _strdup(settings->KerberosKdc); /* 1344 */
- _settings->KerberosRealm = _strdup(settings->KerberosRealm); /* 1345 */
- _settings->CertificateName = _strdup(settings->CertificateName); /* 1409 */
- _settings->CertificateFile = _strdup(settings->CertificateFile); /* 1410 */
- _settings->PrivateKeyFile = _strdup(settings->PrivateKeyFile); /* 1411 */
- _settings->RdpKeyFile = _strdup(settings->RdpKeyFile); /* 1412 */
- _settings->WindowTitle = _strdup(settings->WindowTitle); /* 1542 */
- _settings->WmClass = _strdup(settings->WmClass); /* 1549 */
- _settings->ComputerName = _strdup(settings->ComputerName); /* 1664 */
- _settings->ConnectionFile = _strdup(settings->ConnectionFile); /* 1728 */
- _settings->AssistanceFile = _strdup(settings->AssistanceFile); /* 1729 */
- _settings->HomePath = _strdup(settings->HomePath); /* 1792 */
- _settings->ConfigPath = _strdup(settings->ConfigPath); /* 1793 */
- _settings->CurrentPath = _strdup(settings->CurrentPath); /* 1794 */
- _settings->DumpRemoteFxFile = _strdup(settings->DumpRemoteFxFile); /* 1858 */
- _settings->PlayRemoteFxFile = _strdup(settings->PlayRemoteFxFile); /* 1859 */
- _settings->GatewayHostname = _strdup(settings->GatewayHostname); /* 1986 */
- _settings->GatewayUsername = _strdup(settings->GatewayUsername); /* 1987 */
- _settings->GatewayPassword = _strdup(settings->GatewayPassword); /* 1988 */
- _settings->GatewayDomain = _strdup(settings->GatewayDomain); /* 1989 */
- _settings->RemoteApplicationName = _strdup(settings->RemoteApplicationName); /* 2113 */
- _settings->RemoteApplicationIcon = _strdup(settings->RemoteApplicationIcon); /* 2114 */
- _settings->RemoteApplicationProgram = _strdup(settings->RemoteApplicationProgram); /* 2115 */
- _settings->RemoteApplicationFile = _strdup(settings->RemoteApplicationFile); /* 2116 */
- _settings->RemoteApplicationGuid = _strdup(settings->RemoteApplicationGuid); /* 2117 */
- _settings->RemoteApplicationCmdLine = _strdup(settings->RemoteApplicationCmdLine); /* 2118 */
- _settings->ImeFileName = _strdup(settings->ImeFileName); /* 2628 */
- _settings->DrivesToRedirect = _strdup(settings->DrivesToRedirect); /* 4290 */
+ CHECKED_STRDUP(AlternateShell); /* 640 */
+ CHECKED_STRDUP(ShellWorkingDirectory); /* 641 */
+ CHECKED_STRDUP(ClientAddress); /* 769 */
+ CHECKED_STRDUP(ClientDir); /* 770 */
+ CHECKED_STRDUP(DynamicDSTTimeZoneKeyName); /* 897 */
+ CHECKED_STRDUP(RemoteAssistanceSessionId); /* 1025 */
+ CHECKED_STRDUP(RemoteAssistancePassStub); /* 1026 */
+ CHECKED_STRDUP(RemoteAssistancePassword); /* 1027 */
+ CHECKED_STRDUP(RemoteAssistanceRCTicket); /* 1028 */
+ CHECKED_STRDUP(AuthenticationServiceClass); /* 1098 */
+ CHECKED_STRDUP(AllowedTlsCiphers); /* 1101 */
+ CHECKED_STRDUP(PreconnectionBlob); /* 1155 */
+ CHECKED_STRDUP(KerberosKdc); /* 1344 */
+ CHECKED_STRDUP(KerberosRealm); /* 1345 */
+ CHECKED_STRDUP(CertificateName); /* 1409 */
+ CHECKED_STRDUP(CertificateFile); /* 1410 */
+ CHECKED_STRDUP(PrivateKeyFile); /* 1411 */
+ CHECKED_STRDUP(RdpKeyFile); /* 1412 */
+ CHECKED_STRDUP(WindowTitle); /* 1542 */
+ CHECKED_STRDUP(WmClass); /* 1549 */
+ CHECKED_STRDUP(ComputerName); /* 1664 */
+ CHECKED_STRDUP(ConnectionFile); /* 1728 */
+ CHECKED_STRDUP(AssistanceFile); /* 1729 */
+ CHECKED_STRDUP(HomePath); /* 1792 */
+ CHECKED_STRDUP(ConfigPath); /* 1793 */
+ CHECKED_STRDUP(CurrentPath); /* 1794 */
+ CHECKED_STRDUP(DumpRemoteFxFile); /* 1858 */
+ CHECKED_STRDUP(PlayRemoteFxFile); /* 1859 */
+ CHECKED_STRDUP(GatewayHostname); /* 1986 */
+ CHECKED_STRDUP(GatewayUsername); /* 1987 */
+ CHECKED_STRDUP(GatewayPassword); /* 1988 */
+ CHECKED_STRDUP(GatewayDomain); /* 1989 */
+ CHECKED_STRDUP(RemoteApplicationName); /* 2113 */
+ CHECKED_STRDUP(RemoteApplicationIcon); /* 2114 */
+ CHECKED_STRDUP(RemoteApplicationProgram); /* 2115 */
+ CHECKED_STRDUP(RemoteApplicationFile); /* 2116 */
+ CHECKED_STRDUP(RemoteApplicationGuid); /* 2117 */
+ CHECKED_STRDUP(RemoteApplicationCmdLine); /* 2118 */
+ CHECKED_STRDUP(ImeFileName); /* 2628 */
+ CHECKED_STRDUP(DrivesToRedirect); /* 4290 */
/**
* Manual Code
_settings->ChannelCount = settings->ChannelCount;
_settings->ChannelDefArraySize = settings->ChannelDefArraySize;
_settings->ChannelDefArray = (CHANNEL_DEF*) malloc(sizeof(CHANNEL_DEF) * settings->ChannelDefArraySize);
+
if (!_settings->ChannelDefArray && _settings->ChannelDefArraySize)
goto out_fail;
+
CopyMemory(_settings->ChannelDefArray, settings->ChannelDefArray, sizeof(CHANNEL_DEF) * settings->ChannelDefArraySize);
_settings->MonitorCount = settings->MonitorCount;
_settings->MonitorDefArraySize = settings->MonitorDefArraySize;
_settings->MonitorDefArray = (rdpMonitor*) malloc(sizeof(rdpMonitor) * settings->MonitorDefArraySize);
+
if (!_settings->MonitorDefArray && _settings->MonitorDefArraySize)
goto out_fail;
+
CopyMemory(_settings->MonitorDefArray, settings->MonitorDefArray, sizeof(rdpMonitor) * settings->MonitorDefArraySize);
_settings->MonitorIds = (UINT32*) calloc(16, sizeof(UINT32));
CopyMemory(_settings->MonitorIds, settings->MonitorIds, 16 * sizeof(UINT32));
_settings->ReceivedCapabilities = malloc(32);
- if (!_settings->ReceivedCapabilities)
- goto out_fail;
_settings->OrderSupport = malloc(32);
- if (!_settings->OrderSupport)
+
+ if (!_settings->ReceivedCapabilities || !_settings->OrderSupport)
goto out_fail;
+
CopyMemory(_settings->ReceivedCapabilities, settings->ReceivedCapabilities, 32);
CopyMemory(_settings->OrderSupport, settings->OrderSupport, 32);
if (settings->TargetNetAddressCount > 0)
{
_settings->TargetNetAddresses = (char**) calloc(settings->TargetNetAddressCount, sizeof(char*));
-
if (!_settings->TargetNetAddresses)
+ {
+ _settings->TargetNetAddressCount = 0;
goto out_fail;
+ }
for (index = 0; index < settings->TargetNetAddressCount; index++)
{
_settings->TargetNetAddresses[index] = _strdup(settings->TargetNetAddresses[index]);
-
if (!_settings->TargetNetAddresses[index])
+ {
+ for (--index; index >= 0; --index)
+ free(_settings->TargetNetAddresses[index]);
+ free(_settings->TargetNetAddresses);
+ _settings->TargetNetAddresses = NULL;
+ _settings->TargetNetAddressCount = 0;
goto out_fail;
+ }
}
if (settings->TargetNetPorts)
_settings->DeviceCount = settings->DeviceCount;
_settings->DeviceArraySize = settings->DeviceArraySize;
_settings->DeviceArray = (RDPDR_DEVICE**) calloc(_settings->DeviceArraySize, sizeof(RDPDR_DEVICE*));
-
if (!_settings->DeviceArray && _settings->DeviceArraySize)
+ {
+ _settings->DeviceCount = 0;
+ _settings->DeviceArraySize = 0;
goto out_fail;
+ }
for (index = 0; index < _settings->DeviceCount; index++)
{
_settings->DeviceArray[index] = freerdp_device_clone(settings->DeviceArray[index]);
+ if (!_settings->DeviceArray[index])
+ goto out_fail;
}
_settings->StaticChannelCount = settings->StaticChannelCount;
_settings->StaticChannelArraySize = settings->StaticChannelArraySize;
_settings->StaticChannelArray = (ADDIN_ARGV**) calloc(_settings->StaticChannelArraySize, sizeof(ADDIN_ARGV*));
-
if (!_settings->StaticChannelArray && _settings->StaticChannelArraySize)
+ {
+ _settings->StaticChannelArraySize = 0;
+ _settings->ChannelCount = 0;
goto out_fail;
+ }
for (index = 0; index < _settings->StaticChannelCount; index++)
{
_settings->StaticChannelArray[index] = freerdp_static_channel_clone(settings->StaticChannelArray[index]);
+ if (!_settings->StaticChannelArray[index])
+ goto out_fail;
}
_settings->DynamicChannelCount = settings->DynamicChannelCount;
_settings->DynamicChannelArraySize = settings->DynamicChannelArraySize;
_settings->DynamicChannelArray = (ADDIN_ARGV**) calloc(_settings->DynamicChannelArraySize, sizeof(ADDIN_ARGV*));
-
if (!_settings->DynamicChannelArray && _settings->DynamicChannelArraySize)
+ {
+ _settings->DynamicChannelCount = 0;
+ _settings->DynamicChannelArraySize = 0;
goto out_fail;
+ }
for (index = 0; index < _settings->DynamicChannelCount; index++)
{
_settings->DynamicChannelArray[index] = freerdp_dynamic_channel_clone(settings->DynamicChannelArray[index]);
+ if (!_settings->DynamicChannelArray[index])
+ goto out_fail;
}
_settings->SettingsModified = (BYTE*) calloc(1, sizeof(rdpSettings) / 8);
if (!_settings->SettingsModified)
goto out_fail;
}
-
return _settings;
+
out_fail:
- freerdp_settings_free(_settings);
+ /* In case any memory allocation failed during clone, some bytes might leak.
+ *
+ * freerdp_settings_free can't be reliable used at this point since it could
+ * free memory of pointers copied by CopyMemory and detecting and freeing
+ * each allocation separately is quite painful.
+ */
+ free(_settings);
return NULL;
}
if (!freerdp_tcp_connect_timeout(sockfd, addr->ai_addr, addr->ai_addrlen, timeout))
{
- fprintf(stderr, "failed to connect to %s\n", hostname);
freeaddrinfo(result);
+ close(sockfd);
+ WLog_ERR(TAG, "failed to connect to %s", hostname);
return -1;
}
free(settings->ClientAddress);
settings->ClientAddress = freerdp_tcp_get_ip_address(sockfd);
+ if (!settings->ClientAddress)
+ {
+ close(sockfd);
+ WLog_ERR(TAG, "Couldn't get socket ip address");
+ return -1;
+ }
optval = 1;
optlen = sizeof(optval);
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &optval, optlen) < 0)
{
+ close(sockfd);
WLog_ERR(TAG, "unable to set receive buffer len");
return -1;
}
if (!ipcSocket)
{
if (!freerdp_tcp_set_keep_alive_mode(sockfd))
+ {
+ close(sockfd);
+ WLog_ERR(TAG, "Couldn't set keep alive mode.");
return -1;
+ }
}
return sockfd;
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
- TestVersion.c)
+ TestVersion.c
+ TestSettings.c)
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
--- /dev/null
+#include <freerdp/settings.h>
+
+int TestSettings(int argc, char* argv[])
+{
+ rdpSettings *settings = NULL;
+ rdpSettings *cloned;
+
+ settings = freerdp_settings_new(0);
+ if (!settings)
+ {
+ printf("Couldn't create settings\n");
+ return -1;
+ }
+ settings->Username = strdup("abcdefg");
+ settings->Password = strdup("xyz");
+ cloned = freerdp_settings_clone(settings);
+ if (!cloned)
+ {
+ printf("Problem cloning settings\n");
+ freerdp_settings_free(settings);
+ return -1;
+ }
+
+ freerdp_settings_free(cloned);
+ freerdp_settings_free(settings);
+ return 0;
+}
+
{
layouts[num].code = RDP_KEYBOARD_LAYOUT_TABLE[i].code;
layouts[num].name = _strdup(RDP_KEYBOARD_LAYOUT_TABLE[i].name);
+ if (!layouts[num].name)
+ {
+ for (--i; i >=0; --i)
+ free(layouts[num].name);
+
+ free(layouts);
+ return NULL;
+ }
}
}
if ((types & RDP_KEYBOARD_LAYOUT_TYPE_VARIANT) != 0)
{
layouts[num].code = RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].code;
layouts[num].name = _strdup(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].name);
+ if (!layouts[num].name)
+ {
+ for (--i; i >=0; --i)
+ free(layouts[num].name);
+
+ free(layouts);
+ return NULL;
+ }
}
}
if ((types & RDP_KEYBOARD_LAYOUT_TYPE_IME) != 0)
{
layouts[num].code = RDP_KEYBOARD_IME_TABLE[i].code;
layouts[num].name = _strdup(RDP_KEYBOARD_IME_TABLE[i].name);
+ if (!layouts[num].name)
+ {
+ for (--i; i >=0; --i)
+ free(layouts[num].name);
+
+ free(layouts);
+ return NULL;
+ }
}
}
char* list_copy;
list_copy = _strdup(list);
+ if (!list_copy)
+ return FALSE;
p = strtok(list_copy, " ");
#include <freerdp/listener.h>
#include <freerdp/codec/rfx.h>
#include <winpr/stream.h>
+#include <freerdp/peer.h>
#include <winpr/crt.h>
/* Initialize the real server settings here */
client->settings->CertificateFile = _strdup("server.crt");
client->settings->PrivateKeyFile = _strdup("server.key");
+ if (!client->settings->CertificateFile || !client->settings->PrivateKeyFile)
+ {
+ freerdp_peer_free(client);
+ return NULL;
+ }
+
+
client->settings->NlaSecurity = FALSE;
client->settings->RemoteFxCodec = TRUE;
client->settings->ColorDepth = 32;
context->frame_id++;
}
-static void test_peer_draw_background(freerdp_peer* client)
+static BOOL test_peer_draw_background(freerdp_peer* client)
{
int size;
wStream* s;
rdpUpdate* update = client->update;
SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;
testPeerContext* context = (testPeerContext*) client->context;
+ BOOL ret= FALSE;
if (!client->settings->RemoteFxCodec && !client->settings->NSCodec)
- return;
+ return FALSE;
s = test_peer_stream_init(context);
size = rect.width * rect.height * 3;
if (!(rgb_data = malloc(size)))
- return;
+ {
+ WLog_ERR(TAG, "Problem allocating memory");
+ return FALSE;
+ }
memset(rgb_data, 0xA0, size);
update->SurfaceBits(update->context, cmd);
test_peer_end_frame(client);
+ ret = TRUE;
out:
free(rgb_data);
+ return ret;
}
-static void test_peer_load_icon(freerdp_peer* client)
+static BOOL test_peer_load_icon(freerdp_peer* client)
{
testPeerContext* context = (testPeerContext*) client->context;
FILE* fp;
int c;
if (!client->settings->RemoteFxCodec && !client->settings->NSCodec)
- return;
+ {
+ WLog_ERR(TAG, "Client doesn't support RemoteFX or NSCodec");
+ return FALSE;
+ }
if ((fp = fopen("test_icon.ppm", "r")) == NULL)
- return;
+ {
+ WLog_ERR(TAG, "Unable to open test icon");
+ return FALSE;
+ }
/* P3 */
fgets(line, sizeof(line), fp);
fgets(line, sizeof(line), fp);
/* width height */
fgets(line, sizeof(line), fp);
- sscanf(line, "%d %d", &context->icon_width, &context->icon_height);
+ if (sscanf(line, "%d %d", &context->icon_width, &context->icon_height) < 2)
+ {
+ WLog_ERR(TAG, "Problem while extracting width/height from the icon file");
+ goto out_fail;
+ }
/* Max */
fgets(line, sizeof(line), fp);
- rgb_data = malloc(context->icon_width * context->icon_height * 3);
+ if (!(rgb_data = malloc(context->icon_width * context->icon_height * 3)))
+ goto out_fail;
for (i = 0; i < context->icon_width * context->icon_height * 3; i++)
{
- if (fgets(line, sizeof(line), fp))
- {
- sscanf(line, "%d", &c);
- rgb_data[i] = (BYTE)c;
- }
+ if (!fgets(line, sizeof(line), fp) || (sscanf(line, "%d", &c) != 1))
+ goto out_fail;
+
+ rgb_data[i] = (BYTE)c;
}
- context->icon_data = rgb_data;
/* background with same size, which will be used to erase the icon from old position */
- context->bg_data = malloc(context->icon_width * context->icon_height * 3);
+ if (!(context->bg_data = malloc(context->icon_width * context->icon_height * 3)))
+ goto out_fail;
memset(context->bg_data, 0xA0, context->icon_width * context->icon_height * 3);
+ context->icon_data = rgb_data;
+
+ fclose(fp);
+ return TRUE;
+
+out_fail:
+ free(rgb_data);
+ context->bg_data = NULL;
+ fclose(fp);
+ return FALSE;
}
static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
return TRUE;
}
-void tf_peer_dump_rfx(freerdp_peer* client)
+BOOL tf_peer_dump_rfx(freerdp_peer* client)
{
wStream* s;
UINT32 prev_seconds;
pcap_record record;
s = Stream_New(NULL, 512);
- update = client->update;
- client->update->pcap_rfx = pcap_open(test_pcap_file, FALSE);
- pcap_rfx = client->update->pcap_rfx;
+ if (!s)
+ return FALSE;
- if (pcap_rfx == NULL)
- return;
+ update = client->update;
+ if (!(pcap_rfx = pcap_open(test_pcap_file, FALSE)))
+ return FALSE;
prev_seconds = prev_useconds = 0;
while (pcap_has_next_record(pcap_rfx))
{
- pcap_get_next_record_header(pcap_rfx, &record);
+ BYTE* tmp = NULL;
+ if (!pcap_get_next_record_header(pcap_rfx, &record))
+ break;
+
+ tmp = realloc(Stream_Buffer(s), record.length);
+ if (!tmp)
+ break;
- Stream_Buffer(s) = realloc(Stream_Buffer(s), record.length);
+ Stream_Buffer(s) = tmp;
record.data = Stream_Buffer(s);
Stream_Capacity(s) = record.length;
if (client->CheckFileDescriptor(client) != TRUE)
break;
}
+
+
+ Stream_Free(s, TRUE);
+ pcap_close(pcap_rfx);
+ return TRUE;
}
static void* tf_debug_channel_thread_func(void* arg)
#endif
/* A real server should tag the peer as activated here and start sending updates in main loop. */
- test_peer_load_icon(client);
+ if (!test_peer_load_icon(client))
+ {
+ WLog_DBG(TAG, "Unable to load icon");
+ return FALSE;
+ }
+
if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpdbg"))
{
if (test_pcap_file != NULL)
{
client->update->dump_rfx = TRUE;
- tf_peer_dump_rfx(client);
+ if (!tf_peer_dump_rfx(client))
+ return FALSE;
}
else
- {
test_peer_draw_background(client);
- }
return TRUE;
}
client->settings->CertificateFile = _strdup("server.crt");
client->settings->PrivateKeyFile = _strdup("server.key");
client->settings->RdpKeyFile = _strdup("server.key");
+ if (!client->settings->CertificateFile || !client->settings->PrivateKeyFile || !client->settings->RdpKeyFile)
+ {
+ WLog_ERR(TAG, "Memory allocation failed (strdup)");
+ freerdp_peer_free(client);
+ return NULL;
+ }
client->settings->RdpSecurity = TRUE;
client->settings->TlsSecurity = TRUE;
client->settings->NlaSecurity = FALSE;
#include "wf_rdpsnd.h"
#include "wf_peer.h"
+#include <freerdp/peer.h>
BOOL wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
return 0;
}
-void wf_peer_read_settings(freerdp_peer* client)
+BOOL wf_peer_read_settings(freerdp_peer* client)
{
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("CertificateFile"), &(client->settings->CertificateFile)))
+ {
client->settings->CertificateFile = _strdup("server.crt");
+ if (!client->settings->CertificateFile)
+ return FALSE;
+ }
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("PrivateKeyFile"), &(client->settings->PrivateKeyFile)))
+ {
client->settings->PrivateKeyFile = _strdup("server.key");
+ if (!client->settings->PrivateKeyFile)
+ return FALSE;
+ }
+
+ return TRUE;
}
DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
settings->ColorDepth = 32;
settings->NSCodec = FALSE;
settings->JpegCodec = FALSE;
- wf_peer_read_settings(client);
+ if (!wf_peer_read_settings(client))
+ goto fail_peer_init;
client->PostConnect = wf_peer_post_connect;
client->Activate = wf_peer_activate;
int x11_shadow_pam_conv(int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr)
{
int index;
- int pam_status = PAM_SUCCESS;
+ int pam_status = PAM_BUF_ERR;
SHADOW_PAM_AUTH_DATA* appdata;
struct pam_response* response;
appdata = (SHADOW_PAM_AUTH_DATA*) appdata_ptr;
- response = (struct pam_response*) calloc(num_msg, sizeof(struct pam_response));
-
- if (!response)
- return PAM_CONV_ERR;
+ if (!(response = (struct pam_response*) calloc(num_msg, sizeof(struct pam_response))))
+ return PAM_BUF_ERR;
for (index = 0; index < num_msg; index++)
{
{
case PAM_PROMPT_ECHO_ON:
response[index].resp = _strdup(appdata->user);
+ if (!response[index].resp)
+ goto out_fail;
response[index].resp_retcode = PAM_SUCCESS;
break;
case PAM_PROMPT_ECHO_OFF:
response[index].resp = _strdup(appdata->password);
+ if (!response[index].resp)
+ goto out_fail;
response[index].resp_retcode = PAM_SUCCESS;
break;
default:
pam_status = PAM_CONV_ERR;
- break;
+ goto out_fail;
}
}
- if (pam_status != PAM_SUCCESS)
- {
- free(response);
- return pam_status;
- }
-
*resp = response;
+ return PAM_SUCCESS;
- return pam_status;
+out_fail:
+ for (index = 0; index < num_msg; ++index)
+ {
+ if (response[index].resp)
+ {
+ memset(response[index].resp, 0, strlen(response[index].resp));
+ free(response[index].resp);
+ }
+ }
+ memset(response, 0, sizeof(struct pam_response) * num_msg);
+ free(response);
+ *resp = NULL;
+ return PAM_CONV_ERR;
}
int x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info)
return -1;
}
+ if (!info->service_name)
+ return -1;
+
return 1;
}
totalBitmapSize = 0;
bitmapUpdate.count = bitmapUpdate.number = rows * cols;
- bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * bitmapUpdate.number);
- bitmapUpdate.rectangles = bitmapData;
-
- if (!bitmapData)
+ if (!(bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * bitmapUpdate.number)))
return -1;
+ bitmapUpdate.rectangles = bitmapData;
if ((nWidth % 4) != 0)
{
{
length = (int) (strlen(arg->Name) + strlen(arg->Format) + 2);
str = (char*) malloc(length + 1);
+ if (str)
+ return -1;
sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format);
WLog_INFO(TAG, "%-20s", str);
free(str);
{
length = (int) strlen(arg->Name) + 32;
str = (char*) malloc(length + 1);
+ if (!str)
+ return -1;
sprintf_s(str, length + 1, "%s (default:%s)", arg->Name,
arg->Default ? "on" : "off");
}
else if (status < 0)
{
- shadow_server_print_command_line_help(argc, argv);
+ if (shadow_server_print_command_line_help(argc, argv) < 0)
+ return -1;
return COMMAND_LINE_STATUS_PRINT_HELP;
}
CommandLineSwitchCase(arg, "ipc-socket")
{
server->ipcSocket = _strdup(arg->Value);
+ if (!server->ipcSocket)
+ return -1;
}
CommandLineSwitchCase(arg, "may-view")
{
char* tok[4];
int x, y, w, h;
char* str = _strdup(arg->Value);
-
if (!str)
return -1;
return 1;
}
-int shadow_server_init_certificate(rdpShadowServer* server)
+static BOOL shadow_server_init_certificate(rdpShadowServer* server)
{
char* filepath;
- MAKECERT_CONTEXT* makecert;
+ MAKECERT_CONTEXT* makecert = NULL;
+ BOOL ret = FALSE;
const char* makecert_argv[6] =
{
!PathMakePathA(server->ConfigPath, 0))
{
WLog_ERR(TAG, "Failed to create directory '%s'", server->ConfigPath);
- return -1;
+ return FALSE;
}
if (!(filepath = GetCombinedPath(server->ConfigPath, "shadow")))
- return -1;
+ return FALSE;
if (!PathFileExistsA(filepath) &&
!PathMakePathA(filepath, 0))
{
- WLog_ERR(TAG, "Failed to create directory '%s'", filepath);
- free(filepath);
- return -1;
+ if (!CreateDirectoryA(filepath, 0))
+ {
+ WLog_ERR(TAG, "Failed to create directory '%s'", filepath);
+ goto out_fail;
+ }
}
server->CertificateFile = GetCombinedPath(filepath, "shadow.crt");
server->PrivateKeyFile = GetCombinedPath(filepath, "shadow.key");
+ if (!server->CertificateFile || !server->PrivateKeyFile)
+ goto out_fail;
if ((!PathFileExistsA(server->CertificateFile)) ||
(!PathFileExistsA(server->PrivateKeyFile)))
{
makecert = makecert_context_new();
+ if (!makecert)
+ goto out_fail;
- makecert_context_process(makecert, makecert_argc, (char**) makecert_argv);
+ if (makecert_context_process(makecert, makecert_argc, (char**) makecert_argv) != 1)
+ goto out_fail;
- makecert_context_set_output_file_name(makecert, "shadow");
+ if (!makecert_context_set_output_file_name(makecert, "shadow") != 1)
+ goto out_fail;
if (!PathFileExistsA(server->CertificateFile))
- makecert_context_output_certificate_file(makecert, filepath);
+ {
+ if (makecert_context_output_certificate_file(makecert, filepath) != 1)
+ goto out_fail;
+ }
if (!PathFileExistsA(server->PrivateKeyFile))
- makecert_context_output_private_key_file(makecert, filepath);
-
- makecert_context_free(makecert);
+ {
+ if (makecert_context_output_private_key_file(makecert, filepath) != 1)
+ goto out_fail;
+ }
}
-
+ ret = TRUE;
+out_fail:
+ makecert_context_free(makecert);
free(filepath);
- return 1;
+ return ret;
}
int shadow_server_init(rdpShadowServer* server)
WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
-WINPR_API void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
-WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
+WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
+WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
CallbackAppenderData_t data);
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
-WINPR_API void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
+WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
WINPR_API wLog* WLog_GetRoot(void);
WINPR_API wLog* WLog_Get(LPCSTR name);
format->formatName = _strdup(CF_STANDARD_STRINGS[formatId]);
if (!format->formatName)
+ {
+ for (--formatId; formatId >= 0; --formatId)
+ free((void *)format->formatName);
+ clipboard->numFormats = 0;
return FALSE;
+ }
}
ClipboardInitSynthesizers(clipboard);
clipboard->nextFormatId = 0xC000;
clipboard->sequenceNumber = 0;
- InitializeCriticalSectionAndSpinCount(&(clipboard->lock), 4000);
+ if (!InitializeCriticalSectionAndSpinCount(&(clipboard->lock), 4000))
+ {
+ free(clipboard);
+ return NULL;
+ }
clipboard->numFormats = 0;
clipboard->maxFormats = 64;
if (!clipboard->formats)
{
+ DeleteCriticalSection(&(clipboard->lock));
free(clipboard);
return NULL;
}
- ClipboardInitFormats(clipboard);
+ if(!ClipboardInitFormats(clipboard))
+ {
+ DeleteCriticalSection(&(clipboard->lock));
+ free(clipboard);
+ return NULL;
+ }
}
return clipboard;
char* pDstData;
pSrcData = _strdup("this is a test string");
+ if (!pSrcData)
+ {
+ fprintf(stderr, "Memory allocation failed\n");
+ return -1;
+ }
SrcSize = (UINT32) (strlen(pSrcData) + 1);
bSuccess = ClipboardSetData(clipboard, utf8StringFormatId, (void*) pSrcData, SrcSize);
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+ if (!BasePath)
+ {
+ printf("Unable to allocate memory\n");
+ return -1;
+ }
length = strlen(BasePath);
#endif
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+ if (!BasePath)
+ {
+ printf("Unable to allocate memory");
+ return -1;
+ }
length = strlen(BasePath);
#endif
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
char* GetDeviceFileUnixDomainSocketFilePathA(LPCSTR lpName)
{
- char* lpPipePath;
- char* lpFileName;
- char* lpFilePath;
+ char* lpPipePath = NULL;
+ char* lpFileName = NULL;
+ char* lpFilePath = NULL;
lpPipePath = GetDeviceFileUnixDomainSocketBaseFilePathA();
+ if (!lpPipePath)
+ return NULL;
lpFileName = GetDeviceFileNameWithoutPrefixA(lpName);
+ if (!lpFileName)
+ {
+ free(lpFilePath);
+ return NULL;
+ }
+
lpFilePath = GetCombinedPath(lpPipePath, (char*) lpFileName);
free(lpPipePath);
DeviceBasePath = GetDeviceFileUnixDomainSocketBaseFilePathA();
+ if (!DeviceBasePath)
+ return STATUS_NO_MEMORY;
+
if (!PathFileExistsA(DeviceBasePath))
{
if (!mkdir(DeviceBasePath, S_IRUSR | S_IWUSR | S_IXUSR))
return STATUS_ACCESS_DENIED;
}
}
+ free(DeviceBasePath);
- pDeviceObjectEx = (DEVICE_OBJECT_EX*) malloc(sizeof(DEVICE_OBJECT_EX));
+ pDeviceObjectEx = (DEVICE_OBJECT_EX*) calloc(1, sizeof(DEVICE_OBJECT_EX));
if (!pDeviceObjectEx)
- {
return STATUS_NO_MEMORY;
- }
-
- ZeroMemory(pDeviceObjectEx, sizeof(DEVICE_OBJECT_EX));
ConvertFromUnicode(CP_UTF8, 0, DeviceName->Buffer, DeviceName->Length / 2, &(pDeviceObjectEx->DeviceName), 0, NULL, NULL);
+ if (!pDeviceObjectEx->DeviceName)
+ {
+ free(pDeviceObjectEx);
+ return STATUS_NO_MEMORY;
+ }
pDeviceObjectEx->DeviceFileName = GetDeviceFileUnixDomainSocketFilePathA(pDeviceObjectEx->DeviceName);
+ if (!pDeviceObjectEx->DeviceFileName)
+ {
+ free(pDeviceObjectEx->DeviceName);
+ free(pDeviceObjectEx);
+ return STATUS_NO_MEMORY;
+ }
if (PathFileExistsA(pDeviceObjectEx->DeviceFileName))
{
- unlink(pDeviceObjectEx->DeviceFileName);
+ if (unlink(pDeviceObjectEx->DeviceFileName) == -1)
+ {
+ free(pDeviceObjectEx->DeviceName);
+ free(pDeviceObjectEx->DeviceFileName);
+ free(pDeviceObjectEx);
+ return STATUS_ACCESS_DENIED;
+ }
+
}
status = mkfifo(pDeviceObjectEx->DeviceFileName, 0666);
+ if (status != 0)
+ {
+ free(pDeviceObjectEx->DeviceName);
+ free(pDeviceObjectEx->DeviceFileName);
+ free(pDeviceObjectEx);
+ switch (errno)
+ {
+ case EACCES:
+ return STATUS_ACCESS_DENIED;
+ case EEXIST:
+ return STATUS_OBJECT_NAME_EXISTS;
+ case ENAMETOOLONG:
+ return STATUS_NAME_TOO_LONG;
+ case ENOENT:
+ case ENOTDIR:
+ return STATUS_NOT_A_DIRECTORY;
+ case ENOSPC:
+ return STATUS_DISK_FULL;
+ default:
+ return STATUS_INTERNAL_ERROR;
+ }
+ }
*((ULONG_PTR*) (DeviceObject)) = (ULONG_PTR) pDeviceObjectEx;
&uString, FILE_DEVICE_UNKNOWN,
0, FALSE, &pDeviceObject);
+ if (NtStatus != STATUS_SUCCESS)
+ return -1;
+
_IoDeleteDeviceEx(pDeviceObject);
_RtlFreeUnicodeString(&uString);
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+ if (!BasePath)
+ {
+ printf("Memory allocation failed");
+ return -1;
+ }
length = strlen(BasePath);
#endif
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+ if (!BasePath)
+ {
+ printf("Memory allocation failed");
+ return -1;
+ }
length = strlen(BasePath);
#endif
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+ if (!BasePath)
+ {
+ printf("Memory allocation failed");
+ return -1;
+ }
+
length = strlen(BasePath);
#endif
case KNOWN_PATH_TEMP:
path = GetPath_TEMP();
+
break;
case KNOWN_PATH_XDG_DATA_HOME:
CopyMemory(path, basePath, basePathLength);
path[basePathLength] = '\0';
- PathCchConvertStyleA(path, basePathLength, PATH_STYLE_NATIVE);
+ if (PathCchConvertStyleA(path, basePathLength, PATH_STYLE_NATIVE) != S_OK)
+ {
+ free(path);
+ return NULL;
+ }
if (!subPath)
return path;
subPathCpy = _strdup(subPath);
- PathCchConvertStyleA(subPathCpy, subPathLength, PATH_STYLE_NATIVE);
+ if (!subPathCpy)
+ {
+ free(path);
+ return NULL;
+ }
+ if (PathCchConvertStyleA(subPathCpy, subPathLength, PATH_STYLE_NATIVE) != S_OK)
+ {
+ free(path);
+ free(subPathCpy);
+ return NULL;
+ }
status = NativePathCchAppendA(path, length + 1, subPathCpy);
free(subPathCpy);
- return path;
+ if (status != S_OK)
+ {
+ free(path);
+ return NULL;
+ }
+ else
+ return path;
}
BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes)
char* path;
path = GetKnownPath(KNOWN_PATH_HOME);
+ if (!path)
+ return -1;
printf("KNOWN_PATH_HOME: %s\n", path);
path = GetKnownPath(KNOWN_PATH_TEMP);
+ if (!path)
+ return -1;
printf("KNOWN_PATH_TEMP: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_DATA_HOME);
+ if (!path)
+ return -1;
printf("KNOWN_PATH_DATA: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME);
+ if (!path)
+ return -1;
printf("KNOWN_PATH_CONFIG: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_CACHE_HOME);
+ if (!path)
+ return -1;
printf("KNOWN_PATH_CACHE: %s\n", path);
path = GetKnownPath(KNOWN_PATH_XDG_RUNTIME_DIR);
+ if (!path)
+ return -1;
printf("KNOWN_PATH_RUNTIME: %s\n", path);
path = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
+ if (!path)
+ return -1;
printf("KNOWN_PATH_CONFIG SubPath: %s\n", path);
return 0;
p[4] = strchr(data, '"');
p[4][0] = '\0';
value->data.string = _strdup(data);
+ if (!value->data.string)
+ {
+ free(value);
+ free(name);
+ return NULL;
+ }
}
else
{
char* save;
int length;
path = _strdup(subkey->name);
+ if (!path)
+ return;
name = strtok_s(path, "\\", &save);
while (name != NULL)
length = strlen(name);
name += length + 1;
subkey->subname = _strdup(name);
+ /* TODO: free allocated memory in error case */
+ if (!subkey->subname)
+ {
+ free(path);
+ return;
+ }
}
name = strtok_s(NULL, "\\", &save);
reader = (PCSC_READER*) calloc(1, sizeof(PCSC_READER));
if (!reader)
- goto error_reader;
+ return FALSE;
reader->namePCSC = _strdup(namePCSC);
if (!reader->namePCSC)
free(reader->namePCSC);
error_namePSC:
free(reader);
-error_reader:
return FALSE;
-
}
static int PCSC_AtoiWithLength(const char* str, int length)
pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
+ if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
+ {
+ sspi_ContextBufferFree(pPackageInfo);
+ return SEC_E_INSUFFICIENT_MEMORY;
+ }
}
*(pcPackages) = cPackages;
pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
+ if (!pPackageInfo->Name || !pPackageInfo->Comment)
+ {
+ sspi_ContextBufferFree(pPackageInfo);
+ return SEC_E_INSUFFICIENT_MEMORY;
+ }
*(ppPackageInfo) = pPackageInfo;
table = InitSecurityInterface();
identity.User = (UINT16*) _strdup(test_User);
- identity.UserLength = sizeof(test_User);
identity.Domain = (UINT16*) _strdup(test_Domain);
- identity.DomainLength = sizeof(test_Domain);
identity.Password = (UINT16*) _strdup(test_Password);
+ if (!identity.User || !identity.Domain || !identity.Password)
+ {
+ free(identity.User);
+ free(identity.Domain);
+ free(identity.Password);
+ fprintf(stderr, "Memory allocation failed\n");
+ return -1;
+ }
+ identity.UserLength = sizeof(test_User);
+ identity.DomainLength = sizeof(test_Domain);
identity.PasswordLength = sizeof(test_Password);
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
cbMaxLen = pPackageInfo->cbMaxToken;
identity.User = (UINT16*) _strdup(test_User);
- identity.UserLength = sizeof(test_User);
identity.Domain = (UINT16*) _strdup(test_Domain);
- identity.DomainLength = sizeof(test_Domain);
identity.Password = (UINT16*) _strdup(test_Password);
+ if (!identity.User || !identity.Domain || !identity.Password)
+ {
+ free(identity.User);
+ free(identity.Domain);
+ free(identity.Password);
+ fprintf(stderr, "Memory allocation failed\n");
+ return -1;
+ }
+
+ identity.UserLength = sizeof(test_User);
+ identity.DomainLength = sizeof(test_Domain);
identity.PasswordLength = sizeof(test_Password);
identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
token->ops = &ops;
token->Username = _strdup(lpszUsername);
+ if (!token->Username)
+ {
+ free(token);
+ return FALSE;
+ }
if (lpszDomain)
+ {
token->Domain = _strdup(lpszDomain);
+ if (!token->Domain)
+ {
+ free(token->Username);
+ free(token);
+ return FALSE;
+ }
+ }
pw = getpwnam(lpszUsername);
{
key->name = _strdup(name);
key->value = _strdup(value);
+ if (!key->name || !key->value)
+ {
+ free(key->name);
+ free(key->value);
+ free(key);
+ return NULL;
+ }
}
return key;
{
wIniFileKey* key;
- if (!section)
+ if (!section || !name)
return NULL;
- if (!name)
- return NULL;
-
key = IniFile_GetKey(ini, section, name);
if (!key)
}
key = IniFile_Key_New(name, value);
+ if (!key)
+ return NULL;
section->keys[section->nKeys] = key;
section->nKeys++;
}
{
free(key->value);
key->value = _strdup(value);
+ if (!key->value)
+ return NULL;
}
return key;
value = beg;
- IniFile_AddKey(ini, section, name, value);
+ if (!IniFile_AddKey(ini, section, name, value))
+ {
+ return -1;
+ }
+
key = NULL;
if (section && section->keys)
key = section->keys[section->nKeys - 1];
free(ini->filename);
ini->filename = _strdup(filename);
+ if (!ini->filename)
+ return -1;
status = IniFile_Load_File(ini, filename);
* Binary Appender
*/
-void WLog_BinaryAppender_SetOutputFileName(wLog* log, wLogBinaryAppender* appender, const char* filename)
+BOOL WLog_BinaryAppender_SetOutputFileName(wLog* log, wLogBinaryAppender* appender, const char* filename)
{
- if (!appender)
- return;
+ if (!appender || !filename)
+ return FALSE;
if (appender->Type != WLOG_APPENDER_BINARY)
- return;
-
- if (!filename)
- return;
+ return FALSE;
appender->FileName = _strdup(filename);
+ if (!appender->FileName)
+ return FALSE;
+ return TRUE;
}
-void WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* appender, const char* filepath)
+BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* appender, const char* filepath)
{
- if (!appender)
- return;
+ if (!appender || !filepath)
+ return FALSE;
if (appender->Type != WLOG_APPENDER_BINARY)
- return;
-
- if (!filepath)
- return;
+ return FALSE;
appender->FilePath = _strdup(filepath);
+ if (!appender->FilePath)
+ return FALSE;
+ return TRUE;
}
int WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
* File Appender
*/
-void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename)
+BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename)
{
- if (!appender)
- return;
+ if (!appender || !filename)
+ return FALSE;
if (appender->Type != WLOG_APPENDER_FILE)
- return;
-
- if (!filename)
- return;
+ return FALSE;
appender->FileName = _strdup(filename);
+ if (!appender->FileName)
+ return FALSE;
+
+ return TRUE;
}
-void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath)
+BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath)
{
- if (!appender)
- return;
+ if (!appender || !filepath)
+ return FALSE;
if (appender->Type != WLOG_APPENDER_FILE)
- return;
-
- if (!filepath)
- return;
+ return FALSE;
appender->FilePath = _strdup(filepath);
+ if (!appender->FilePath)
+ return FALSE;
+
+ return TRUE;
}
int WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender)
return appender->Layout;
}
-void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format)
+BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format)
{
free(layout->FormatString);
layout->FormatString = NULL;
if (format)
+ {
layout->FormatString = _strdup(format);
+ if (!layout->FormatString)
+ return FALSE;
+ }
+ return TRUE;
}
wLogLayout* WLog_Layout_New(wLog* log)
_lpwcx->lpszClassName = _strdup(lpwcx->lpszClassName);
_lpwcx->lpszMenuName = _strdup(lpwcx->lpszMenuName);
+ if (!_lpwcx->lpszClassName || !_lpwcx->lpszMenuName)
+ {
+ free((LPSTR)_lpwcx->lpszClassName);
+ free((LPSTR)_lpwcx->lpszMenuName);
+ free(_lpwcx);
+ return NULL;
+ }
return _lpwcx;
}
pWnd->nWidth = nWidth;
pWnd->nHeight = nHeight;
pWnd->lpClassName = _strdup(lpClassName);
+ if (!pWnd->lpClassName)
+ goto out_fail;
if (lpWindowName)
+ {
pWnd->lpWindowName = _strdup(lpWindowName);
+ if (!pWnd->lpWindowName)
+ goto out_fail;
+ }
pWnd->hWndParent = hWndParent;
pWnd->hMenu = hMenu;
pWnd->lpwcx = lpwcx;
return hWnd;
+
+out_fail:
+ free(pWnd->lpClassName);
+ free(pWnd->lpWindowName);
+ free(pWnd);
+ return NULL;
}
HWND WINAPI CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName,
pChannel->SessionId = SessionId;
pChannel->hFile = hFile;
pChannel->VirtualName = _strdup(pVirtualName);
+ if (!pChannel->VirtualName)
+ {
+ CloseHandle(hFile);
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ free(pChannel);
+ return NULL;
+ }
pChannel->flags = flags;
pChannel->dynamic = (flags & WTS_CHANNEL_OPTION_DYNAMIC) ? TRUE : FALSE;
int main(int argc, char* argv[])
{
MAKECERT_CONTEXT* context;
+ int ret = 0;
context = makecert_context_new();
+ if (!context)
+ return 1;
- makecert_context_process(context, argc, argv);
+ if (makecert_context_process(context, argc, argv) < 0)
+ ret = 1;
makecert_context_free(context);
- return 0;
+ return ret;
}
context->pemFormat = FALSE;
context->pfxFormat = TRUE;
}
+ else
+ return -1;
}
CommandLineSwitchCase(arg, "path")
{
continue;
context->output_path = _strdup(arg->Value);
+ if (!context->output_path)
+ return -1;
}
CommandLineSwitchCase(arg, "p")
{
continue;
context->password = _strdup(arg->Value);
+ if (!context->password)
+ return -1;
}
CommandLineSwitchCase(arg, "n")
{
continue;
context->common_name = _strdup(arg->Value);
+ if (!context->common_name)
+ return -1;
}
CommandLineSwitchCase(arg, "y")
{
{
free(context->output_file);
context->output_file = _strdup(name);
+ if (!context->output_file)
+ return -1;
return 1;
}
int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* path)
{
- FILE* fp;
+ FILE* fp = NULL;
int status;
int length;
int offset;
- char* filename;
- char* fullpath;
+ char* filename = NULL;
+ char* fullpath = NULL;
+ int ret = -1;
+ BIO* bio = NULL;
+ BYTE* x509_str = NULL;
if (!context->output_file)
{
else
fullpath = _strdup(filename);
+ if (!fullpath)
+ goto out_fail;
+
fp = fopen(fullpath, "w+");
if (fp)
{
- BIO* bio;
- BYTE* x509_str = NULL;
if (context->pfxFormat)
{
if (!context->password)
{
context->password = _strdup("password");
+ if (!context->password)
+ goto out_fail;
printf("Using default export password \"password\"\n");
}
context->pkcs12 = PKCS12_create(context->password, context->default_name,
context->pkey, context->x509, NULL, 0, 0, 0, 0, 0);
+ if (!context->pkcs12)
+ goto out_fail;
bio = BIO_new(BIO_s_mem());
if (!bio)
- {
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
+ goto out_fail;
status = i2d_PKCS12_bio(bio, context->pkcs12);
+ if (status != 1)
+ goto out_fail;
offset = 0;
length = 2048;
x509_str = (BYTE*) malloc(length);
if (!x509_str)
- {
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
+ goto out_fail;
status = BIO_read(bio, x509_str, length);
if (status < 0)
- {
- free(x509_str);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
-
+ goto out_fail;
+
offset += status;
while (offset >= length)
}
if (status < 0)
- {
- free(x509_str);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
+ goto out_fail;
length = offset;
fwrite((void*) x509_str, length, 1, fp);
- free(x509_str);
- BIO_free(bio);
}
else
{
bio = BIO_new(BIO_s_mem());
if (!bio)
- {
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
+ goto out_fail;
- status = PEM_write_bio_X509(bio, context->x509);
+ if (!PEM_write_bio_X509(bio, context->x509))
+ goto out_fail;
offset = 0;
length = 2048;
x509_str = (BYTE*) malloc(length);
if (!x509_str)
- {
- BIO_free(bio);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
+ goto out_fail;
status = BIO_read(bio, x509_str, length);
if (status < 0)
- {
- BIO_free(bio);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
-
+ goto out_fail;
+
offset += status;
while (offset >= length)
}
if (status < 0)
- {
- free (x509_str);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
-
+ goto out_fail;
+
length = offset;
fwrite((void*) x509_str, length, 1, fp);
free(x509_str);
+ x509_str = NULL;
BIO_free(bio);
+ bio = NULL;
if (context->pemFormat)
{
bio = BIO_new(BIO_s_mem());
if (!bio)
- {
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
+ goto out_fail;
status = PEM_write_bio_PrivateKey(bio, context->pkey, NULL, NULL, 0, NULL, NULL);
offset = 0;
length = 2048;
if (!(x509_str = (BYTE*) malloc(length)))
- {
- BIO_free(bio);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
-
- }
+ goto out_fail;
status = BIO_read(bio, x509_str, length);
if (status < 0)
- {
- free(x509_str);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
-
+ goto out_fail;
+
offset += status;
while (offset >= length)
}
if (status < 0)
- {
- free(x509_str);
- free(filename);
- free(fullpath);
- fclose (fp);
- return -1;
- }
-
+ goto out_fail;
+
length = offset;
fwrite((void*) x509_str, length, 1, fp);
-
- free(x509_str);
- BIO_free(bio);
}
}
- fclose(fp);
}
+ ret = 1;
+out_fail:
+ if (bio)
+ BIO_free(bio);
+ if (fp)
+ fclose(fp);
+ free(x509_str);
free(filename);
free(fullpath);
- return 1;
+ return ret;
}
int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* path)
else
fullpath = _strdup(filename);
+ if (!fullpath)
+ {
+ free(filename);
+ return -1;
+ }
+
fp = fopen(fullpath, "w+");
if (fp)
X509_NAME* name = NULL;
const EVP_MD* md = NULL;
COMMAND_LINE_ARGUMENT_A* arg;
+ int ret;
- if (makecert_context_parse_arguments(context, argc, argv) < 1)
- return 0;
+ ret = makecert_context_parse_arguments(context, argc, argv);
+ if (ret < 1)
+ return ret;
if (!context->default_name && !context->common_name)
+ {
context->default_name = x509_get_default_name();
+ if (!context->default_name)
+ return -1;
+ }
else
+ {
context->default_name = _strdup(context->common_name);
+ if (!context->default_name)
+ return -1;
+ }
if (!context->common_name)
+ {
context->common_name = _strdup(context->default_name);
+ if (!context->common_name)
+ return -1;
+ }
if (!context->pkey)
context->pkey = EVP_PKEY_new();
free(context->default_name);
free(context->common_name);
+ free(context->output_file);
+ free(context->output_path);
CRYPTO_cleanup_all_ex_data();