Merge pull request #2708 from bmiklautz/dupdup

alloc and strdup checks
This commit is contained in:
Norbert Federa 2015-06-23 11:18:19 +02:00
commit e8d194c743
153 changed files with 3254 additions and 1586 deletions

4
.gitignore vendored
View File

@ -94,6 +94,7 @@ client/X11/xfreerdp
client/Mac/xcode
client/Sample/sfreerdp
client/DirectFB/dfreerdp
client/Wayland/wlfreerdp
server/Sample/sfreerdp-server
server/X11/xfreerdp-server
xcode
@ -132,6 +133,9 @@ TAGS
# packaging related files
!packaging/scripts/prepare_deb_freerdp-nightly.sh
packaging/deb/freerdp-nightly/freerdp-nightly
packaging/deb/freerdp-nightly/freerdp-nightly-dev
packaging/deb/freerdp-nightly/freerdp-nightly-dbg
#
.idea

View File

@ -161,7 +161,9 @@ static void audin_opensles_free(IAudinDevice* device)
static BOOL audin_opensles_format_supported(IAudinDevice* device, audinFormat* format)
{
#ifdef WITH_DEBUG_DVC
AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
#endif
DEBUG_DVC("device=%p, format=%p", opensles, format);

View File

@ -851,6 +851,8 @@ static int rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
}
s = Stream_New(pDstData, DstSize);
if (!s)
return 0;
while (((size_t) Stream_GetPosition(s)) < Stream_Length(s))
{

View File

@ -77,7 +77,7 @@ typedef struct opensl_stream {
/*
* Set the volume input level.
*/
void android_SetOutputVolume(OPENSL_STREAM *p, int level);
void android_SetInputVolume(OPENSL_STREAM *p, int level);
/*
* Get the current output mute setting.
*/

1
client/.gitignore vendored
View File

@ -7,4 +7,5 @@
!/Sample
!/Windows
!/X11
!/Wayland
!/CMakeLists.txt

View File

@ -69,20 +69,20 @@ void android_clear_event(ANDROID_EVENT_QUEUE * queue)
}
}
void android_push_event(freerdp * inst, ANDROID_EVENT* event)
BOOL android_push_event(freerdp * inst, ANDROID_EVENT* event)
{
androidContext* aCtx = (androidContext*)inst->context;
if (aCtx->event_queue->count >= aCtx->event_queue->size)
{
int new_size;
int new_events;
void* new_events;
new_size = aCtx->event_queue->size * 2;
new_events = realloc((void*) aCtx->event_queue->events,
sizeof(ANDROID_EVENT*) * new_size);
if (!new_events)
return;
return FALSE;
aCtx->event_queue->events = new_events;
aCtx->event_queue->size = new_size;
}
@ -90,6 +90,7 @@ void android_push_event(freerdp * inst, ANDROID_EVENT* event)
aCtx->event_queue->events[(aCtx->event_queue->count)++] = event;
android_set_event(aCtx->event_queue);
return TRUE;
}
ANDROID_EVENT* android_peek_event(ANDROID_EVENT_QUEUE * queue)
@ -226,8 +227,9 @@ ANDROID_EVENT_KEY* android_event_key_new(int flags, UINT16 scancode)
{
ANDROID_EVENT_KEY* event;
event = (ANDROID_EVENT_KEY*) malloc(sizeof(ANDROID_EVENT_KEY));
memset(event, 0, sizeof(ANDROID_EVENT_KEY));
event = (ANDROID_EVENT_KEY*) calloc(1, sizeof(ANDROID_EVENT_KEY));
if (!event)
return NULL;
event->type = EVENT_TYPE_KEY;
event->flags = flags;
@ -245,8 +247,9 @@ ANDROID_EVENT_KEY* android_event_unicodekey_new(UINT16 key)
{
ANDROID_EVENT_KEY* event;
event = (ANDROID_EVENT_KEY*) malloc(sizeof(ANDROID_EVENT_KEY));
memset(event, 0, sizeof(ANDROID_EVENT_KEY));
event = (ANDROID_EVENT_KEY*) calloc(1, sizeof(ANDROID_EVENT_KEY));
if (!event)
return NULL;
event->type = EVENT_TYPE_KEY_UNICODE;
event->scancode = key;
@ -263,8 +266,9 @@ ANDROID_EVENT_CURSOR* android_event_cursor_new(UINT16 flags, UINT16 x, UINT16 y)
{
ANDROID_EVENT_CURSOR* event;
event = (ANDROID_EVENT_CURSOR*) malloc(sizeof(ANDROID_EVENT_CURSOR));
memset(event, 0, sizeof(ANDROID_EVENT_CURSOR));
event = (ANDROID_EVENT_CURSOR*) calloc(1, sizeof(ANDROID_EVENT_CURSOR));
if (!event)
return NULL;
event->type = EVENT_TYPE_CURSOR;
event->x = x;
@ -283,8 +287,9 @@ ANDROID_EVENT* android_event_disconnect_new()
{
ANDROID_EVENT* event;
event = (ANDROID_EVENT*) malloc(sizeof(ANDROID_EVENT));
memset(event, 0, sizeof(ANDROID_EVENT));
event = (ANDROID_EVENT*) calloc(1, sizeof(ANDROID_EVENT));
if (!event)
return NULL;
event->type = EVENT_TYPE_DISCONNECT;
return event;
@ -299,13 +304,19 @@ ANDROID_EVENT_CLIPBOARD* android_event_clipboard_new(void* data, int data_length
{
ANDROID_EVENT_CLIPBOARD* event;
event = (ANDROID_EVENT_CLIPBOARD*) malloc(sizeof(ANDROID_EVENT_CLIPBOARD));
memset(event, 0, sizeof(ANDROID_EVENT_CLIPBOARD));
event = (ANDROID_EVENT_CLIPBOARD*) calloc(1, sizeof(ANDROID_EVENT_CLIPBOARD));
if (!event)
return NULL;
event->type = EVENT_TYPE_CLIPBOARD;
if (data)
{
event->data = malloc(data_length);
if (!event->data)
{
free(event);
return NULL;
}
memcpy(event->data, data, data_length);
event->data_length = data_length;
}
@ -322,12 +333,16 @@ void android_event_clipboard_free(ANDROID_EVENT_CLIPBOARD* event)
}
}
void android_event_queue_init(freerdp * inst)
BOOL android_event_queue_init(freerdp * inst)
{
androidContext* aCtx = (androidContext*)inst->context;
aCtx->event_queue = (ANDROID_EVENT_QUEUE*) malloc(sizeof(ANDROID_EVENT_QUEUE));
memset(aCtx->event_queue, 0, sizeof(ANDROID_EVENT_QUEUE));
aCtx->event_queue = (ANDROID_EVENT_QUEUE*) calloc(1, sizeof(ANDROID_EVENT_QUEUE));
if (!aCtx->event_queue)
{
WLog_ERR(TAG, "android_event_queue_init: memory allocation failed");
return FALSE;
}
aCtx->event_queue->pipe_fd[0] = -1;
aCtx->event_queue->pipe_fd[1] = -1;
@ -335,9 +350,21 @@ void android_event_queue_init(freerdp * inst)
aCtx->event_queue->size = 16;
aCtx->event_queue->count = 0;
aCtx->event_queue->events = (ANDROID_EVENT**) malloc(sizeof(ANDROID_EVENT*) * aCtx->event_queue->size);
if (!aCtx->event_queue->events)
{
WLog_ERR(TAG, "android_event_queue_init: memory allocation failed");
free(aCtx->event_queue);
return FALSE;
}
if (pipe(aCtx->event_queue->pipe_fd) < 0)
WLog_ERR(TAG, "android_pre_connect: pipe failed");
{
WLog_ERR(TAG, "android_event_queue_init: pipe creation failed");
free(aCtx->event_queue->events);
free(aCtx->event_queue);
return FALSE;
}
return TRUE;
}
void android_event_queue_uninit(freerdp * inst)

View File

@ -62,7 +62,7 @@ typedef struct _ANDROID_EVENT_QUEUE ANDROID_EVENT_QUEUE;
int android_is_event_set(ANDROID_EVENT_QUEUE * queue);
void android_set_event(ANDROID_EVENT_QUEUE * queue);
void android_clear_event(ANDROID_EVENT_QUEUE * queue);
void android_push_event(freerdp * inst, ANDROID_EVENT* event);
BOOL android_push_event(freerdp * inst, ANDROID_EVENT* event);
ANDROID_EVENT* android_peek_event(ANDROID_EVENT_QUEUE * queue);
ANDROID_EVENT* android_pop_event(ANDROID_EVENT_QUEUE * queue);
int android_process_event(ANDROID_EVENT_QUEUE * queue, freerdp * inst);
@ -79,7 +79,7 @@ void android_event_unicodekey_free(ANDROID_EVENT_KEY* event);
void android_event_cursor_free(ANDROID_EVENT_CURSOR* event);
void android_event_disconnect_free(ANDROID_EVENT* event);
void android_event_clipboard_free(ANDROID_EVENT_CLIPBOARD* event);
void android_event_queue_init(freerdp * inst);
BOOL android_event_queue_init(freerdp * inst);
void android_event_queue_uninit(freerdp * inst);
#endif /* FREERDP_ANDROID_EVENT_H */

View File

@ -4,6 +4,7 @@
Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
Copyright 2013 Thincast Technologies GmbH, Author: Armin Novak
Copyright 2015 Bernhard Miklautz <bernhard.miklautz@thincast.com>
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
@ -35,6 +36,7 @@
#include <freerdp/locale/keyboard.h>
#include <freerdp/primitives.h>
#include <freerdp/version.h>
#include <freerdp/settings.h>
#include <android/bitmap.h>
@ -48,15 +50,21 @@
#include "jni/prof.h"
#endif
BOOL android_context_new(freerdp* instance, rdpContext* context)
static BOOL android_context_new(freerdp* instance, rdpContext* context)
{
if (!(context->channels = freerdp_channels_new()))
return FALSE;
android_event_queue_init(instance);
if (!android_event_queue_init(instance))
{
freerdp_channels_free(context->channels);
return FALSE;
}
return TRUE;
}
void android_context_free(freerdp* instance, rdpContext* context)
static void android_context_free(freerdp* instance, rdpContext* context)
{
if (context && context->channels)
{
@ -67,14 +75,14 @@ void android_context_free(freerdp* instance, rdpContext* context)
android_event_queue_uninit(instance);
}
void android_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e)
static void android_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e)
{
rdpSettings* settings = context->settings;
androidContext* afc = (androidContext*) context;
if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0)
{
DEBUG_ANDROID("Unhandled case.. RDPEI_DVC_CHANNEL_NAME");
}
else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
{
@ -87,14 +95,14 @@ void android_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnecte
}
}
void android_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e)
static void android_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e)
{
rdpSettings* settings = context->settings;
androidContext* afc = (androidContext*) context;
if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0)
{
DEBUG_ANDROID("Unhandled case.. RDPEI_DVC_CHANNEL_NAME");
}
else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
{
@ -107,7 +115,7 @@ void android_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisco
}
}
BOOL android_begin_paint(rdpContext* context)
static BOOL android_begin_paint(rdpContext* context)
{
rdpGdi* gdi = context->gdi;
gdi->primary->hdc->hwnd->invalid->null = 1;
@ -115,7 +123,7 @@ BOOL android_begin_paint(rdpContext* context)
return TRUE;
}
BOOL android_end_paint(rdpContext* context)
static BOOL android_end_paint(rdpContext* context)
{
int i;
int ninvalid;
@ -158,7 +166,7 @@ BOOL android_end_paint(rdpContext* context)
return TRUE;
}
BOOL android_desktop_resize(rdpContext* context)
static BOOL android_desktop_resize(rdpContext* context)
{
DEBUG_ANDROID("ui_desktop_resize");
@ -172,7 +180,7 @@ BOOL android_desktop_resize(rdpContext* context)
return TRUE;
}
BOOL android_pre_connect(freerdp* instance)
static BOOL android_pre_connect(freerdp* instance)
{
DEBUG_ANDROID("android_pre_connect");
@ -233,7 +241,8 @@ static BOOL android_post_connect(freerdp* instance)
settings->DesktopWidth, settings->DesktopHeight,
settings->ColorDepth);
instance->context->cache = cache_new(settings);
if (!(instance->context->cache = cache_new(settings)))
return FALSE;
if (instance->settings->ColorDepth > 16)
gdi_flags = CLRBUF_32BPP | CLRCONV_ALPHA | CLRCONV_INVERT;
@ -247,7 +256,8 @@ static BOOL android_post_connect(freerdp* instance)
instance->update->EndPaint = android_end_paint;
instance->update->DesktopResize = android_desktop_resize;
freerdp_channels_post_connect(instance->context->channels, instance);
if (freerdp_channels_post_connect(instance->context->channels, instance) < 0)
return FALSE;
freerdp_callback("OnConnectionSuccess", "(I)V", instance);
@ -256,11 +266,12 @@ static BOOL android_post_connect(freerdp* instance)
static void android_post_disconnect(freerdp* instance)
{
DEBUG_ANDROID("android_post_disconnect");
gdi_free(instance);
cache_free(instance->context->cache);
}
BOOL android_authenticate(freerdp* instance, char** username, char** password, char** domain)
static BOOL android_authenticate(freerdp* instance, char** username, char** password, char** domain)
{
DEBUG_ANDROID("Authenticate user:");
DEBUG_ANDROID(" Username: %s", *username);
@ -293,7 +304,7 @@ BOOL android_authenticate(freerdp* instance, char** username, char** password, c
return ((res == JNI_TRUE) ? TRUE : FALSE);
}
BOOL android_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
static BOOL android_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
{
DEBUG_ANDROID("Certificate details:");
DEBUG_ANDROID("\tSubject: %s", subject);
@ -317,7 +328,7 @@ BOOL android_verify_certificate(freerdp* instance, char* subject, char* issuer,
return ((res == JNI_TRUE) ? TRUE : FALSE);
}
BOOL android_verify_changed_certificate(freerdp* instance, char* subject, char* issuer, char* new_fingerprint, char* old_fingerprint)
static BOOL android_verify_changed_certificate(freerdp* instance, char* subject, char* issuer, char* new_fingerprint, char* old_fingerprint)
{
return android_verify_certificate(instance, subject, issuer, new_fingerprint);
}
@ -332,7 +343,7 @@ static void* jni_input_thread(void* arg)
assert(NULL != instance);
assert(NULL != aCtx);
DEBUG_ANDROID("Start.");
DEBUG_ANDROID("input_thread Start.");
if (!(queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE)))
goto fail_get_message_queue;
@ -365,7 +376,7 @@ static void* jni_input_thread(void* arg)
}
while(1);
DEBUG_ANDROID("Quit.");
DEBUG_ANDROID("input_thread Quit.");
fail_get_message_queue_event:
CloseHandle(event[1]);
@ -388,7 +399,7 @@ static void* jni_channels_thread(void* arg)
assert(NULL != instance);
DEBUG_ANDROID("Start.");
DEBUG_ANDROID("Channels_thread Start.");
channels = instance->context->channels;
event = freerdp_channels_get_event_handle(instance);
@ -401,7 +412,7 @@ static void* jni_channels_thread(void* arg)
break;
}
DEBUG_ANDROID("Quit.");
DEBUG_ANDROID("channels_thread Quit.");
ExitThread(0);
return NULL;
@ -613,11 +624,11 @@ disconnect:
CloseHandle(input_thread);
}
DEBUG_ANDROID("Disconnecting...");
DEBUG_ANDROID("run Disconnecting...");
freerdp_disconnect(instance);
freerdp_callback("OnDisconnected", "(I)V", instance);
DEBUG_ANDROID("Quit.");
DEBUG_ANDROID("run Quit.");
return 0;
}
@ -626,13 +637,13 @@ static void* android_thread_func(void* param)
{
freerdp* instance = param;
DEBUG_ANDROID("Start.");
DEBUG_ANDROID("android_thread_func Start.");
assert(instance);
android_freerdp_run(instance);
DEBUG_ANDROID("Quit.");
DEBUG_ANDROID("android_thread_func Quit.");
ExitThread(0);
return NULL;
@ -649,7 +660,7 @@ JNIEXPORT jint JNICALL jni_freerdp_new(JNIEnv *env, jclass cls)
// create instance
if (!(instance = freerdp_new()))
return NULL;
return (jint)NULL;
instance->PreConnect = android_pre_connect;
instance->PostConnect = android_post_connect;
instance->PostDisconnect = android_post_disconnect;
@ -705,12 +716,20 @@ JNIEXPORT jboolean JNICALL jni_freerdp_disconnect(JNIEnv *env, jclass cls, jint
freerdp* inst = (freerdp*)instance;
androidContext* ctx = (androidContext*)inst->context;
ANDROID_EVENT* event = (ANDROID_EVENT*)android_event_disconnect_new();
if (!event)
return JNI_FALSE;
DEBUG_ANDROID("DISCONNECT!");
assert(inst);
assert(ctx);
assert(event);
android_push_event(inst, event);
if (!android_push_event(inst, event))
{
android_event_disconnect_free(event);
return JNI_FALSE;
}
WaitForSingleObject(ctx->thread, INFINITE);
CloseHandle(ctx->thread);
@ -721,43 +740,71 @@ JNIEXPORT jboolean JNICALL jni_freerdp_disconnect(JNIEnv *env, jclass cls, jint
return (jboolean) JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_cancel_connection(JNIEnv *env, jclass cls, jint instance)
JNIEXPORT jboolean JNICALL jni_freerdp_cancel_connection(JNIEnv *env, jclass cls, jint instance)
{
jni_freerdp_disconnect(env, cls, instance);
return jni_freerdp_disconnect(env, cls, instance);
}
JNIEXPORT void JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, jint instance, jstring jdirectory)
JNIEXPORT jboolean JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, jint instance, jstring jdirectory)
{
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
const jbyte *directory = (*env)->GetStringUTFChars(env, jdirectory, NULL);
const jbyte* directory = (*env)->GetStringUTFChars(env, jdirectory, NULL);
if (!directory)
return JNI_FALSE;
free(settings->HomePath);
free(settings->ConfigPath);
settings->HomePath = settings->ConfigPath = NULL;
int config_dir_len = strlen(directory) + 10; /* +9 chars for /.freerdp and +1 for \0 */
char* config_dir_buf = (char*)malloc(config_dir_len);
if (!config_dir_buf)
goto out_malloc_fail;
strcpy(config_dir_buf, directory);
strcat(config_dir_buf, "/.freerdp");
settings->HomePath = strdup(directory);
if (!settings->HomePath)
goto out_strdup_fail;
settings->ConfigPath = config_dir_buf; /* will be freed by freerdp library */
(*env)->ReleaseStringUTFChars(env, jdirectory, directory);
return JNI_TRUE;
out_strdup_fail:
free(config_dir_buf);
out_malloc_fail:
(*env)->ReleaseStringUTFChars(env, jdirectory, directory);
return JNI_FALSE;
}
JNIEXPORT void JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, jint instance,
JNIEXPORT jboolean JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, jint instance,
jstring jhostname, jstring jusername, jstring jpassword, jstring jdomain, jint width, jint height,
jint color_depth, jint port, jboolean console, jint security, jstring jcertname)
{
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
const jbyte *hostname = (*env)->GetStringUTFChars(env, jhostname, NULL);
const jbyte *username = (*env)->GetStringUTFChars(env, jusername, NULL);
const jbyte *password = (*env)->GetStringUTFChars(env, jpassword, NULL);
const jbyte *domain = (*env)->GetStringUTFChars(env, jdomain, NULL);
const jbyte *certname = (*env)->GetStringUTFChars(env, jcertname, NULL);
const jbyte *hostname;
const jbyte *username;
const jbyte *password;
const jbyte *domain;
const jbyte *certname;
if(!(hostname = (*env)->GetStringUTFChars(env, jhostname, NULL)))
return JNI_FALSE;
if (!(username = (*env)->GetStringUTFChars(env, jusername, NULL)))
goto out_fail_username;
if (!(password = (*env)->GetStringUTFChars(env, jpassword, NULL)))
goto out_fail_password;
if (!(domain = (*env)->GetStringUTFChars(env, jdomain, NULL)))
goto out_fail_domain;
if (!(certname = (*env)->GetStringUTFChars(env, jcertname, NULL)))
goto out_fail_certname;
DEBUG_ANDROID("hostname: %s", (char*) hostname);
DEBUG_ANDROID("username: %s", (char*) username);
@ -779,21 +826,30 @@ JNIEXPORT void JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls,
if (color_depth <= 16)
settings->DesktopWidth &= (~1);
settings->ServerHostname = strdup(hostname);
if (!(settings->ServerHostname = strdup(hostname)))
goto out_fail_strdup;
if (username && strlen(username) > 0)
settings->Username = strdup(username);
{
if (!(settings->Username = strdup(username)))
goto out_fail_strdup;
}
if (password && strlen(password) > 0)
{
settings->Password = strdup(password);
if (!(settings->Password = strdup(password)))
goto out_fail_strdup;
settings->AutoLogonEnabled = TRUE;
}
settings->Domain = strdup(domain);
if (!(settings->Domain = strdup(domain)))
goto out_fail_strdup;
if (certname && strlen(certname) > 0)
settings->CertificateName = strdup(certname);
{
if (!(settings->CertificateName = strdup(certname)))
goto out_fail_strdup;
}
settings->ConsoleSession = (console == JNI_TRUE) ? TRUE : FALSE;
@ -840,7 +896,20 @@ JNIEXPORT void JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls,
(*env)->ReleaseStringUTFChars(env, jdomain, domain);
(*env)->ReleaseStringUTFChars(env, jcertname, certname);
return;
return JNI_TRUE;
out_fail_strdup:
(*env)->ReleaseStringUTFChars(env, jcertname, certname);
out_fail_certname:
(*env)->ReleaseStringUTFChars(env, jdomain, domain);
out_fail_domain:
(*env)->ReleaseStringUTFChars(env, jpassword, password);
out_fail_password:
(*env)->ReleaseStringUTFChars(env, jusername, username);
out_fail_username:
(*env)->ReleaseStringUTFChars(env, jhostname, hostname);
return JNI_FALSE;
}
JNIEXPORT void JNICALL jni_freerdp_set_performance_flags(
@ -881,16 +950,23 @@ JNIEXPORT void JNICALL jni_freerdp_set_performance_flags(
DEBUG_ANDROID("performance_flags: %04X", settings->PerformanceFlags);
}
JNIEXPORT void JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls,
JNIEXPORT jboolean JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls,
jint instance, jstring jRemoteProgram, jstring jWorkDir,
jboolean async_channel, jboolean async_transport, jboolean async_input,
jboolean async_update)
{
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
jboolean ret = JNI_FALSE;
const jbyte *remote_program = (*env)->GetStringUTFChars(env, jRemoteProgram, NULL);
const jbyte *work_dir = (*env)->GetStringUTFChars(env, jWorkDir, NULL);
const jbyte *remote_program;
const jbyte *work_dir;
if (!(remote_program = (*env)->GetStringUTFChars(env, jRemoteProgram, NULL)))
return JNI_FALSE;
if (!(work_dir = (*env)->GetStringUTFChars(env, jWorkDir, NULL)))
goto out_fail_work_dir;
DEBUG_ANDROID("Remote Program: %s", (char*) remote_program);
DEBUG_ANDROID("Work Dir: %s", (char*) work_dir);
@ -902,36 +978,56 @@ JNIEXPORT void JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls
settings->AsyncInput = async_input;
if (remote_program && strlen(remote_program) > 0)
settings->AlternateShell = strdup(remote_program);
{
if (!(settings->AlternateShell = strdup(remote_program)))
goto out_fail_strdup;
}
if (work_dir && strlen(work_dir) > 0)
settings->ShellWorkingDirectory = strdup(work_dir);
{
if (!(settings->ShellWorkingDirectory = strdup(work_dir)))
goto out_fail_strdup;
}
(*env)->ReleaseStringUTFChars(env, jRemoteProgram, remote_program);
ret = JNI_TRUE;
out_fail_strdup:
(*env)->ReleaseStringUTFChars(env, jWorkDir, work_dir);
out_fail_work_dir:
(*env)->ReleaseStringUTFChars(env, jRemoteProgram, remote_program);
return ret;
}
JNIEXPORT void JNICALL jni_freerdp_set_drive_redirection(JNIEnv *env, jclass cls, jint instance, jstring jpath)
JNIEXPORT jboolean JNICALL jni_freerdp_set_drive_redirection(JNIEnv *env, jclass cls, jint instance, jstring jpath)
{
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
char* args[] = {"drive", "Android", ""};
jboolean ret = JNI_FALSE;
const jbyte *path = (*env)->GetStringUTFChars(env, jpath, NULL);
if (!path)
return JNI_FALSE;
DEBUG_ANDROID("drive redirect: %s", (char*)path);
args[2] = (char*)path;
freerdp_client_add_device_channel(settings, 3, args);
if (freerdp_client_add_device_channel(settings, 3, args) == -1)
{
settings->DeviceRedirection = FALSE;
goto out_fail;
}
settings->DeviceRedirection = TRUE;
ret = JNI_TRUE;
out_fail:
(*env)->ReleaseStringUTFChars(env, jpath, path);
return ret;
}
JNIEXPORT void JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env,
JNIEXPORT jboolean JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env,
jclass cls, jint instance, jint redirect)
{
char** p;
int count = 1;
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
@ -939,23 +1035,24 @@ JNIEXPORT void JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env,
redirect ? ((redirect == 1) ? "Server" : "Redirect") : "None");
settings->AudioPlayback = (redirect == 2) ? TRUE : FALSE;
settings->RemoteConsoleAudio = (redirect == 1) ? TRUE : FALSE;
if (settings->AudioPlayback)
{
p = malloc(sizeof(char*));
p[0] = "rdpsnd";
int ret;
char* p[1] = {"rdpsnd"};
int count = 1;
freerdp_client_add_static_channel(settings, count, p);
ret = freerdp_client_add_static_channel(settings, count, p);
free(p);
if(ret == -1)
return JNI_FALSE;
}
settings->RemoteConsoleAudio = (redirect == 1) ? TRUE : FALSE;
return JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env,
JNIEXPORT jboolean JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env,
jclass cls, jint instance, jboolean enable)
{
char** p;
int count = 1;
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
@ -964,13 +1061,17 @@ JNIEXPORT void JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env,
settings->AudioCapture = enable;
if (enable)
{
p = malloc(sizeof(char*));
p[0] = "audin";
int ret;
char* p[1] = {"audin"};
int count = 1;
freerdp_client_add_dynamic_channel(settings, count, p);
ret = freerdp_client_add_dynamic_channel(settings, count, p);
if (ret == -1)
return JNI_FALSE;
free(p);
}
return JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_set_clipboard_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable)
@ -983,16 +1084,26 @@ JNIEXPORT void JNICALL jni_freerdp_set_clipboard_redirection(JNIEnv *env, jclass
settings->RedirectClipboard = enable ? TRUE : FALSE;
}
JNIEXPORT void JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jint instance, jstring jgatewayhostname, jint port,
JNIEXPORT jboolean JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jint instance, jstring jgatewayhostname, jint port,
jstring jgatewayusername, jstring jgatewaypassword, jstring jgatewaydomain)
{
freerdp* inst = (freerdp*)instance;
rdpSettings * settings = inst->settings;
jboolean ret = JNI_FALSE;
const jbyte *gatewayhostname = (*env)->GetStringUTFChars(env, jgatewayhostname, NULL);
const jbyte *gatewayusername = (*env)->GetStringUTFChars(env, jgatewayusername, NULL);
const jbyte *gatewaypassword = (*env)->GetStringUTFChars(env, jgatewaypassword, NULL);
const jbyte *gatewaydomain = (*env)->GetStringUTFChars(env, jgatewaydomain, NULL);
const jbyte *gatewayhostname;
const jbyte *gatewayusername;
const jbyte *gatewaypassword;
const jbyte *gatewaydomain;
if (!(gatewayhostname = (*env)->GetStringUTFChars(env, jgatewayhostname, NULL)))
return JNI_FALSE;
if (!(gatewayusername = (*env)->GetStringUTFChars(env, jgatewayusername, NULL)))
goto out_fail_username;
if (!(gatewaypassword = (*env)->GetStringUTFChars(env, jgatewaypassword, NULL)))
goto out_fail_password;
if (!(gatewaydomain = (*env)->GetStringUTFChars(env, jgatewaydomain, NULL)))
goto out_fail_domain;
DEBUG_ANDROID("gatewayhostname: %s", (char*) gatewayhostname);
DEBUG_ANDROID("gatewayport: %d", port);
@ -1000,19 +1111,33 @@ JNIEXPORT void JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jin
DEBUG_ANDROID("gatewaypassword: %s", (char*) gatewaypassword);
DEBUG_ANDROID("gatewaydomain: %s", (char*) gatewaydomain);
settings->GatewayHostname = strdup(gatewayhostname);
settings->GatewayPort = port;
settings->GatewayUsername = strdup(gatewayusername);
settings->GatewayPassword = strdup(gatewaypassword);
settings->GatewayDomain = strdup(gatewaydomain);
settings->GatewayUsageMethod = TSC_PROXY_MODE_DIRECT;
settings->GatewayEnabled = TRUE;
settings->GatewayUseSameCredentials = FALSE;
settings->GatewayHostname = strdup(gatewayhostname);
settings->GatewayUsername = strdup(gatewayusername);
settings->GatewayPassword = strdup(gatewaypassword);
settings->GatewayDomain = strdup(gatewaydomain);
if (!settings->GatewayHostname || !settings->GatewayUsername ||
!settings->GatewayPassword || !settings->GatewayDomain)
{
goto out_fail_strdup;
}
(*env)->ReleaseStringUTFChars(env, jgatewayhostname, gatewayhostname);
(*env)->ReleaseStringUTFChars(env, jgatewayusername, gatewayusername);
(*env)->ReleaseStringUTFChars(env, jgatewaypassword, gatewaypassword);
ret = JNI_TRUE;
out_fail_strdup:
(*env)->ReleaseStringUTFChars(env, jgatewaydomain, gatewaydomain);
out_fail_domain:
(*env)->ReleaseStringUTFChars(env, jgatewaypassword, gatewaypassword);
out_fail_password:
(*env)->ReleaseStringUTFChars(env, jgatewayusername, gatewayusername);
out_fail_username:
(*env)->ReleaseStringUTFChars(env, jgatewayhostname, gatewayhostname);
return ret;
}
static void copy_pixel_buffer(UINT8* dstBuf, UINT8* srcBuf, int x, int y, int width, int height, int wBuf, int hBuf, int bpp)
@ -1065,7 +1190,7 @@ JNIEXPORT jboolean JNICALL jni_freerdp_update_graphics(
return JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_send_key_event(
JNIEXPORT jboolean JNICALL jni_freerdp_send_key_event(
JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down)
{
DWORD scancode;
@ -1077,54 +1202,86 @@ JNIEXPORT void JNICALL jni_freerdp_send_key_event(
int flags = (down == JNI_TRUE) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE;
flags |= (scancode & KBDEXT) ? KBD_FLAGS_EXTENDED : 0;
event = (ANDROID_EVENT*) android_event_key_new(flags, scancode & 0xFF);
if (!event)
return JNI_FALSE;
android_push_event(inst, event);
if (!android_push_event(inst, event))
{
android_event_key_free((ANDROID_EVENT_KEY *)event);
return JNI_FALSE;
}
DEBUG_ANDROID("send_key_event: %d, %d", (int)scancode, flags);
return JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_send_unicodekey_event(
JNIEXPORT jboolean JNICALL jni_freerdp_send_unicodekey_event(
JNIEnv *env, jclass cls, jint instance, jint keycode)
{
ANDROID_EVENT* event;
freerdp* inst = (freerdp*)instance;
event = (ANDROID_EVENT*) android_event_unicodekey_new(keycode);
android_push_event(inst, event);
if (!event)
return JNI_FALSE;
if (!android_push_event(inst, event))
{
android_event_unicodekey_free((ANDROID_EVENT_KEY *)event);
return JNI_FALSE;
}
DEBUG_ANDROID("send_unicodekey_event: %d", keycode);
return JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_send_cursor_event(
JNIEXPORT jboolean JNICALL jni_freerdp_send_cursor_event(
JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags)
{
ANDROID_EVENT* event;
freerdp* inst = (freerdp*)instance;
event = (ANDROID_EVENT*) android_event_cursor_new(flags, x, y);
android_push_event(inst, event);
if (!event)
return JNI_FALSE;
if (!android_push_event(inst, event))
{
android_event_cursor_free((ANDROID_EVENT_CURSOR *)event);
return JNI_FALSE;
}
DEBUG_ANDROID("send_cursor_event: (%d, %d), %d", x, y, flags);
return JNI_TRUE;
}
JNIEXPORT void JNICALL jni_freerdp_send_clipboard_data(JNIEnv *env, jclass cls, jint instance, jstring jdata)
JNIEXPORT jboolean JNICALL jni_freerdp_send_clipboard_data(JNIEnv *env, jclass cls, jint instance, jstring jdata)
{
ANDROID_EVENT* event;
freerdp* inst = (freerdp*)instance;
const jbyte *data = jdata != NULL ? (*env)->GetStringUTFChars(env, jdata, NULL) : NULL;
int data_length = data ? strlen(data) : 0;
jboolean ret = JNI_FALSE;;
event = (ANDROID_EVENT*) android_event_clipboard_new((void*)data, data_length);
android_push_event(inst, event);
if (!event)
goto out_fail;
if (!android_push_event(inst, event))
{
android_event_clipboard_free((ANDROID_EVENT_CLIPBOARD *)event);
goto out_fail;
}
DEBUG_ANDROID("send_clipboard_data: (%s)", data);
ret = JNI_TRUE;
out_fail:
if (data)
(*env)->ReleaseStringUTFChars(env, jdata, data);
return ret;
}
JNIEXPORT jstring JNICALL jni_freerdp_get_version(JNIEnv *env, jclass cls)
{
return (*env)->NewStringUTF(env, GIT_REVISION);
}

View File

@ -44,27 +44,27 @@ JNIEXPORT jint JNICALL jni_freerdp_new(JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL jni_freerdp_free(JNIEnv *env, jclass cls, jint instance);
JNIEXPORT jboolean JNICALL jni_freerdp_connect(JNIEnv *env, jclass cls, jint instance);
JNIEXPORT jboolean JNICALL jni_freerdp_disconnect(JNIEnv *env, jclass cls, jint instance);
JNIEXPORT void JNICALL jni_freerdp_cancel_connection(JNIEnv *env, jclass cls, jint instance);
JNIEXPORT void JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, jint instance,
JNIEXPORT jboolean JNICALL jni_freerdp_cancel_connection(JNIEnv *env, jclass cls, jint instance);
JNIEXPORT jboolean JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, jint instance,
jstring jhostname, jstring jusername, jstring jpassword, jstring jdomain, jint width,
jint height, jint color_depth, jint port, jboolean console, jint security, jstring jcertname);
JNIEXPORT void JNICALL jni_freerdp_set_performance_flags(JNIEnv *env, jclass cls, jint instance, jboolean remotefx, jboolean disableWallpaper, jboolean disableFullWindowDrag,
jboolean disableMenuAnimations, jboolean disableTheming, jboolean enableFontSmoothing, jboolean enableDesktopComposition);
JNIEXPORT void JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls,
JNIEXPORT jboolean JNICALL jni_freerdp_set_advanced_settings(JNIEnv *env, jclass cls,
jint instance, jstring jRemoteProgram, jstring jWorkDir,
jboolean async_channel, jboolean async_transport, jboolean async_input,
jboolean async_update);
JNIEXPORT void JNICALL jni_freerdp_set_drive_redirection(JNIEnv *env, jclass cls, jint instance, jstring jpath);
JNIEXPORT void JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env, jclass cls, jint instance, jint redirect);
JNIEXPORT void JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable);
JNIEXPORT jboolean JNICALL jni_freerdp_set_drive_redirection(JNIEnv *env, jclass cls, jint instance, jstring jpath);
JNIEXPORT jboolean JNICALL jni_freerdp_set_sound_redirection(JNIEnv *env, jclass cls, jint instance, jint redirect);
JNIEXPORT jboolean JNICALL jni_freerdp_set_microphone_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable);
JNIEXPORT void JNICALL jni_freerdp_set_clipboard_redirection(JNIEnv *env, jclass cls, jint instance, jboolean enable);
JNIEXPORT void JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jint instance, jstring jgatewayhostname, jint port, jstring jgatewayusername, jstring jgatewaypassword, jstring jgatewaydomain);
JNIEXPORT void JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, jint instance, jstring jdirectory);
JNIEXPORT jboolean JNICALL jni_freerdp_set_gateway_info(JNIEnv *env, jclass cls, jint instance, jstring jgatewayhostname, jint port, jstring jgatewayusername, jstring jgatewaypassword, jstring jgatewaydomain);
JNIEXPORT jboolean JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, jint instance, jstring jdirectory);
JNIEXPORT jboolean JNICALL jni_freerdp_update_graphics(JNIEnv *env, jclass cls, jint instance, jobject bitmap, jint x, jint y, jint width, jint height);
JNIEXPORT void JNICALL jni_freerdp_send_cursor_event(JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags);
JNIEXPORT void JNICALL jni_freerdp_send_key_event(JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down);
JNIEXPORT void JNICALL jni_freerdp_send_unicodekey_event(JNIEnv *env, jclass cls, jint instance, jint keycode);
JNIEXPORT void JNICALL jni_freerdp_send_clipboard_data(JNIEnv *env, jclass cls, jint instance, jstring jdata);
JNIEXPORT jboolean JNICALL jni_freerdp_send_cursor_event(JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags);
JNIEXPORT jboolean JNICALL jni_freerdp_send_key_event(JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down);
JNIEXPORT jboolean JNICALL jni_freerdp_send_unicodekey_event(JNIEnv *env, jclass cls, jint instance, jint keycode);
JNIEXPORT jboolean JNICALL jni_freerdp_send_clipboard_data(JNIEnv *env, jclass cls, jint instance, jstring jdata);
JNIEXPORT jstring JNICALL jni_freerdp_get_version(JNIEnv *env, jclass cls);
#endif /* __ANDROID_FREERDP_H */

View File

@ -99,6 +99,8 @@ char* get_string_from_string_builder(JNIEnv* env, jobject strBuilder)
// read string
native_str = (*env)->GetStringUTFChars(env, strObj, NULL);
if (!native_str)
return NULL;
result = strdup(native_str);
(*env)->ReleaseStringUTFChars(env, strObj, native_str);

View File

@ -40,32 +40,32 @@ JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_free
return jni_freerdp_disconnect(env, cls, instance);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1cancel_1connection(JNIEnv *env, jclass cls, jint instance)
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1cancel_1connection(JNIEnv *env, jclass cls, jint instance)
{
jni_freerdp_cancel_connection(env, cls, instance);
return jni_freerdp_cancel_connection(env, cls, instance);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1connection_1info(JNIEnv *env, jclass cls, jint instance,
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1connection_1info(JNIEnv *env, jclass cls, jint instance,
jstring jhostname, jstring jusername, jstring jpassword, jstring jdomain, jint width, jint height, jint color_depth, jint port,
jboolean console, jint security, jstring certname)
{
jni_freerdp_set_connection_info(env, cls, instance, jhostname, jusername, jpassword, jdomain,
return jni_freerdp_set_connection_info(env, cls, instance, jhostname, jusername, jpassword, jdomain,
width, height, color_depth, port, console, security, certname);
}
JNIEXPORT void JNICALL
JNIEXPORT jboolean JNICALL
Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1advanced_1settings(
JNIEnv *env, jclass cls, jint instance, jstring remote_program, jstring work_dir,
jboolean async_channel, jboolean async_transport, jboolean async_input,
jboolean async_update)
{
jni_freerdp_set_advanced_settings(env, cls, instance, remote_program, work_dir,
return jni_freerdp_set_advanced_settings(env, cls, instance, remote_program, work_dir,
async_channel, async_transport, async_input, async_update);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1data_1directory(JNIEnv *env, jclass cls, jint instance, jstring directory)
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1data_1directory(JNIEnv *env, jclass cls, jint instance, jstring directory)
{
jni_freerdp_set_data_directory(env, cls, instance, directory);
return jni_freerdp_set_data_directory(env, cls, instance, directory);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1performance_1flags(
@ -81,28 +81,28 @@ JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_
jni_freerdp_set_clipboard_redirection(env, cls, inst, enable);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1sound_1redirection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1sound_1redirection
(JNIEnv *env, jclass cls, jint inst, jint redirect)
{
jni_freerdp_set_sound_redirection(env, cls, inst, redirect);
return jni_freerdp_set_sound_redirection(env, cls, inst, redirect);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1microphone_1redirection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1microphone_1redirection
(JNIEnv *env, jclass cls, jint inst, jboolean redirect)
{
jni_freerdp_set_microphone_redirection(env, cls, inst, redirect);
return jni_freerdp_set_microphone_redirection(env, cls, inst, redirect);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1drive_1redirection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1drive_1redirection
(JNIEnv *env, jclass cls, jint inst, jstring path)
{
jni_freerdp_set_drive_redirection(env, cls, inst, path);
return jni_freerdp_set_drive_redirection(env, cls, inst, path);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1gateway_1info
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1gateway_1info
(JNIEnv *env, jclass cls, jint inst, jstring hostname, jint port, jstring username, jstring password, jstring domain)
{
jni_freerdp_set_gateway_info(env, cls, inst, hostname, port, username, password, domain);
return jni_freerdp_set_gateway_info(env, cls, inst, hostname, port, username, password, domain);
}
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1update_1graphics(
@ -111,28 +111,28 @@ JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_free
return jni_freerdp_update_graphics(env, cls, instance, bitmap, x, y, width, height);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event(
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event(
JNIEnv *env, jclass cls, jint instance, jint x, jint y, jint flags)
{
jni_freerdp_send_cursor_event(env, cls, instance, x, y, flags);
return jni_freerdp_send_cursor_event(env, cls, instance, x, y, flags);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event(
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event(
JNIEnv *env, jclass cls, jint instance, jint keycode, jboolean down)
{
jni_freerdp_send_key_event(env, cls, instance, keycode, down);
return jni_freerdp_send_key_event(env, cls, instance, keycode, down);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event
(JNIEnv *env, jclass cls, jint instance, jint keycode)
{
jni_freerdp_send_unicodekey_event(env, cls, instance, keycode);
return jni_freerdp_send_unicodekey_event(env, cls, instance, keycode);
}
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data
(JNIEnv *env, jclass cls, jint instance, jstring data)
{
jni_freerdp_send_clipboard_data(env, cls, instance, data);
return jni_freerdp_send_clipboard_data(env, cls, instance, data);
}
JNIEXPORT jstring JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1get_1version(JNIEnv *env, jclass cls)

View File

@ -42,17 +42,17 @@ JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_free
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_cancel_connection
* Signature: (I)V
* Signature: (I)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1cancel_1connection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1cancel_1connection
(JNIEnv *, jclass, jint);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_connection_info
* Signature: (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIZILjava/lang/String;)V
* Signature: (ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIZILjava/lang/String;)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1connection_1info
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1connection_1info
(JNIEnv *, jclass, jint, jstring, jstring, jstring, jstring, jint, jint, jint, jint, jboolean, jint, jstring);
/*
@ -66,17 +66,17 @@ JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_advanced_settings
* Signature: (ILjava/lang/String;Ljava/lang/String;ZZZZ)V
* Signature: (ILjava/lang/String;Ljava/lang/String;ZZZZ)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1advanced_1settings
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1advanced_1settings
(JNIEnv *, jclass, jint, jstring, jstring, jboolean, jboolean, jboolean, jboolean);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_data_directory
* Signature: (ILjava/lang/String;)V
* Signature: (ILjava/lang/String;)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1data_1directory
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1data_1directory
(JNIEnv *, jclass, jint, jstring);
/*
@ -90,33 +90,33 @@ JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_sound_redirection
* Signature: (IZ)V
* Signature: (II)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1sound_1redirection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1sound_1redirection
(JNIEnv *, jclass, jint, jint);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_microphone_redirection
* Signature: (IZ)V
* Signature: (IZ)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1microphone_1redirection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1microphone_1redirection
(JNIEnv *, jclass, jint, jboolean);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_drive_redirection
* Signature: (ILjava/lang/String;)V
* Signature: (ILjava/lang/String;)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1drive_1redirection
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1drive_1redirection
(JNIEnv *, jclass, jint, jstring);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_set_gateway_info
* Signature: (ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
* Signature: (ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1gateway_1info
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1set_1gateway_1info
(JNIEnv *, jclass, jint, jstring, jint, jstring, jstring, jstring);
/*
@ -130,33 +130,33 @@ JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_free
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_send_cursor_event
* Signature: (IIII)V
* Signature: (IIII)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1cursor_1event
(JNIEnv *, jclass, jint, jint, jint, jint);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_send_key_event
* Signature: (IIZ)V
* Signature: (IIZ)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1key_1event
(JNIEnv *, jclass, jint, jint, jboolean);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_send_unicodekey_event
* Signature: (II)V
* Signature: (II)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1unicodekey_1event
(JNIEnv *, jclass, jint, jint);
/*
* Class: com_freerdp_freerdpcore_services_LibFreeRDP
* Method: freerdp_send_clipboard_data
* Signature: (ILjava/lang/String;)V
* Signature: (ILjava/lang/String;)Z
*/
JNIEXPORT void JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data
JNIEXPORT jboolean JNICALL Java_com_freerdp_freerdpcore_services_LibFreeRDP_freerdp_1send_1clipboard_1data
(JNIEnv *, jclass, jint, jstring);
/*

View File

@ -23,9 +23,9 @@ public class LibFreeRDP
private static native void freerdp_free(int inst);
private static native boolean freerdp_connect(int inst);
private static native boolean freerdp_disconnect(int inst);
private static native void freerdp_cancel_connection(int inst);
private static native boolean freerdp_cancel_connection(int inst);
private static native void freerdp_set_connection_info(int inst,
private static native boolean freerdp_set_connection_info(int inst,
String hostname, String username, String password, String domain,
int width, int height, int color_depth, int port, boolean console,
int security, String certname);
@ -35,27 +35,27 @@ public class LibFreeRDP
boolean disableMenuAnimations, boolean disableTheming,
boolean enableFontSmoothing, boolean enableDesktopComposition);
private static native void freerdp_set_advanced_settings(int inst,
private static native boolean freerdp_set_advanced_settings(int inst,
String remoteProgram, String workDir, boolean async_channel,
boolean async_transport, boolean async_input, boolean async_update);
private static native void freerdp_set_data_directory(int inst, String directory);
private static native boolean freerdp_set_data_directory(int inst, String directory);
private static native void freerdp_set_clipboard_redirection(int inst, boolean enable);
private static native void freerdp_set_sound_redirection(int inst, int redirect);
private static native void freerdp_set_microphone_redirection(int inst, boolean enable);
private static native void freerdp_set_drive_redirection(int inst, String path);
private static native boolean freerdp_set_sound_redirection(int inst, int redirect);
private static native boolean freerdp_set_microphone_redirection(int inst, boolean enable);
private static native boolean freerdp_set_drive_redirection(int inst, String path);
private static native void freerdp_set_gateway_info(int inst, String gatewayhostname, int port,
private static native boolean freerdp_set_gateway_info(int inst, String gatewayhostname, int port,
String gatewayusername, String gatewaypassword, String gatewaydomain);
private static native boolean freerdp_update_graphics(int inst,
Bitmap bitmap, int x, int y, int width, int height);
private static native void freerdp_send_cursor_event(int inst, int x, int y, int flags);
private static native void freerdp_send_key_event(int inst, int keycode, boolean down);
private static native void freerdp_send_unicodekey_event(int inst, int keycode);
private static native void freerdp_send_clipboard_data(int inst, String data);
private static native boolean freerdp_send_cursor_event(int inst, int x, int y, int flags);
private static native boolean freerdp_send_key_event(int inst, int keycode, boolean down);
private static native boolean freerdp_send_unicodekey_event(int inst, int keycode);
private static native boolean freerdp_send_clipboard_data(int inst, String data);
private static native String freerdp_get_version();
@ -106,9 +106,9 @@ public class LibFreeRDP
return freerdp_disconnect(inst);
}
public static void cancelConnection(int inst)
public static boolean cancelConnection(int inst)
{
freerdp_cancel_connection(inst);
return freerdp_cancel_connection(inst);
}
public static boolean setConnectionInfo(int inst, BookmarkBase bookmark)
@ -185,9 +185,9 @@ public class LibFreeRDP
return true;
}
public static void setDataDirectory(int inst, String directory)
public static boolean setDataDirectory(int inst, String directory)
{
freerdp_set_data_directory(inst, directory);
return freerdp_set_data_directory(inst, directory);
}
public static boolean updateGraphics(int inst, Bitmap bitmap, int x, int y, int width, int height)
@ -195,24 +195,24 @@ public class LibFreeRDP
return freerdp_update_graphics(inst, bitmap, x, y, width, height);
}
public static void sendCursorEvent(int inst, int x, int y, int flags)
public static boolean sendCursorEvent(int inst, int x, int y, int flags)
{
freerdp_send_cursor_event(inst, x, y, flags);
return freerdp_send_cursor_event(inst, x, y, flags);
}
public static void sendKeyEvent(int inst, int keycode, boolean down)
public static boolean sendKeyEvent(int inst, int keycode, boolean down)
{
freerdp_send_key_event(inst, keycode, down);
return freerdp_send_key_event(inst, keycode, down);
}
public static void sendUnicodeKeyEvent(int inst, int keycode)
public static boolean sendUnicodeKeyEvent(int inst, int keycode)
{
freerdp_send_unicodekey_event(inst, keycode);
return freerdp_send_unicodekey_event(inst, keycode);
}
public static void sendClipboardData(int inst, String data)
public static boolean sendClipboardData(int inst, String data)
{
freerdp_send_clipboard_data(inst, data);
return freerdp_send_clipboard_data(inst, data);
}
private static void OnConnectionSuccess(int inst)

View File

@ -179,9 +179,7 @@ BOOL df_pre_connect(freerdp* instance)
freerdp_channels_pre_connect(instance->context->channels, instance);
instance->context->cache = cache_new(instance->settings);
return TRUE;
return (instance->context->cache = cache_new(instance->settings)) != NULL;
}
BOOL df_post_connect(freerdp* instance)
@ -237,9 +235,7 @@ BOOL df_post_connect(freerdp* instance)
pointer_cache_register_callbacks(instance->update);
df_register_graphics(instance->context->graphics);
freerdp_channels_post_connect(instance->context->channels, instance);
return TRUE;
return freerdp_channels_post_connect(instance->context->channels, instance) >= 0;
}
BOOL df_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)

View File

@ -122,9 +122,7 @@ static BOOL tf_post_connect(freerdp* instance)
instance->update->BeginPaint = tf_begin_paint;
instance->update->EndPaint = tf_end_paint;
freerdp_channels_post_connect(instance->context->channels, instance);
return TRUE;
return (freerdp_channels_post_connect(instance->context->channels, instance) >= 0);
}
static void* tf_client_thread_proc(freerdp* instance)

View File

@ -142,7 +142,7 @@ static BOOL wl_post_connect(freerdp* instance)
/* put Wayland data in the context here */
context->window = window;
if (freerdp_channels_post_connect(instance->context->channels, instance))
if (freerdp_channels_post_connect(instance->context->channels, instance) < 0)
return FALSE;
wlf_UpdateWindowArea(context, window, 0, 0, gdi->width, gdi->height);

View File

@ -50,6 +50,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
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);
@ -66,9 +67,26 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
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;
for (--index; index >= 0; --index)
free(context->argv[index]);
free(context->argv);
context->argv = NULL;
goto out;
}
}
status = freerdp_client_settings_parse_command_line(settings, context->argc, context->argv, FALSE);
@ -89,8 +107,8 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
GetExitCodeThread(thread, &dwExitCode);
freerdp_client_stop(context);
out:
freerdp_client_context_free(context);
return 0;
return ret;
}

View File

@ -275,7 +275,8 @@ BOOL wf_pre_connect(freerdp* instance)
wfc->clrconv->palette = NULL;
wfc->clrconv->alpha = FALSE;
instance->context->cache = cache_new(settings);
if (!(instance->context->cache = cache_new(settings)))
return FALSE;
desktopWidth = settings->DesktopWidth;
desktopHeight = settings->DesktopHeight;
@ -484,7 +485,8 @@ BOOL wf_post_connect(freerdp* instance)
instance->update->BitmapUpdate = wf_gdi_bitmap_update;
}
freerdp_channels_post_connect(context->channels, instance);
if (freerdp_channels_post_connect(context->channels, instance) < 0)
return FALSE;
if (wfc->fullscreen)
floatbar_window_create(wfc);
@ -534,13 +536,31 @@ BOOL wf_authenticate(freerdp* instance, char** username, char** password, char**
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;
}
@ -873,6 +893,10 @@ int freerdp_client_load_settings_from_rdp_file(wfContext* wfc, char* filename)
if (filename)
{
settings->ConnectionFile = _strdup(filename);
if (!settings->ConnectionFile)
{
return 3;
}
// free old settings file
freerdp_client_rdp_file_free(wfc->connectionRdpFile);

View File

@ -552,6 +552,8 @@ BOOL xf_create_window(xfContext* xfc)
if (settings->WindowTitle)
{
windowTitle = _strdup(settings->WindowTitle);
if (!windowTitle)
return FALSE;
}
else if (settings->ServerPort == 3389)
{
@ -999,6 +1001,8 @@ BOOL xf_pre_connect(freerdp* instance)
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);
}
}
@ -1016,9 +1020,13 @@ BOOL xf_pre_connect(freerdp* instance)
}
if (!context->cache)
context->cache = cache_new(settings);
{
if (!(context->cache = cache_new(settings)))
return FALSE;
}
xf_keyboard_init(xfc);
if (!xf_keyboard_init(xfc))
return FALSE;
xf_detect_monitors(xfc, &maxWidth, &maxHeight);
@ -1165,7 +1173,8 @@ BOOL xf_post_connect(freerdp* instance)
update->SetKeyboardIndicators = xf_keyboard_set_indicators;
xfc->clipboard = xf_clipboard_new(xfc);
freerdp_channels_post_connect(channels, instance);
if (freerdp_channels_post_connect(channels, instance) < 0)
return FALSE;
EventArgsInit(&e, "xfreerdp");
e.width = settings->DesktopWidth;
@ -1422,8 +1431,8 @@ void* xf_client_thread(void* param)
xfContext* xfc;
freerdp* instance;
rdpContext* context;
HANDLE inputEvent;
HANDLE inputThread;
HANDLE inputEvent = NULL;
HANDLE inputThread = NULL;
rdpChannels* channels;
rdpSettings* settings;

View File

@ -836,6 +836,16 @@ static int xf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR_
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;
@ -1103,6 +1113,12 @@ xfClipboard* xf_clipboard_new(xfContext* xfc)
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;

View File

@ -87,7 +87,6 @@ const char* const X11_EVENT_STRINGS[] =
BOOL xf_event_action_script_init(xfContext* xfc)
{
int exitCode;
char* xevent;
FILE* actionScript;
char buffer[1024] = { 0 };
@ -102,18 +101,22 @@ BOOL xf_event_action_script_init(xfContext* xfc)
actionScript = popen(command, "r");
if (actionScript < 0)
if (!actionScript)
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;
}
@ -127,23 +130,22 @@ void xf_event_action_script_free(xfContext* xfc)
}
}
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];
@ -161,24 +163,24 @@ int xf_event_execute_action_script(xfContext* xfc, XEvent* event)
}
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;
if (!actionScript)
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)

View File

@ -45,7 +45,6 @@
BOOL xf_keyboard_action_script_init(xfContext* xfc)
{
int exitCode;
FILE* keyScript;
char* keyCombination;
char buffer[1024] = { 0 };
@ -61,11 +60,11 @@ BOOL xf_keyboard_action_script_init(xfContext* xfc)
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;
@ -73,24 +72,30 @@ BOOL xf_keyboard_action_script_init(xfContext* xfc)
keyScript = popen(command, "r");
if (keyScript < 0)
if (!keyScript)
{
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)
@ -110,7 +115,7 @@ void xf_keyboard_action_script_free(xfContext* xfc)
}
}
void xf_keyboard_init(xfContext* xfc)
BOOL xf_keyboard_init(xfContext* xfc)
{
xf_keyboard_clear(xfc);
@ -121,9 +126,11 @@ void xf_keyboard_init(xfContext* 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)
@ -407,7 +414,7 @@ int xf_keyboard_execute_action_script(xfContext* xfc, XF_MODIFIER_KEYS* mod, Key
keyScript = popen(command, "r");
if (keyScript < 0)
if (!keyScript)
return -1;
while (fgets(buffer, sizeof(buffer), keyScript) != NULL)

View File

@ -44,7 +44,7 @@ struct _XF_MODIFIER_KEYS
};
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);

View File

@ -312,6 +312,11 @@ static BOOL xf_rail_window_common(rdpContext* context, WINDOW_ORDER_INFO* orderI
{
appWindow->title = _strdup("RdpRailWindow");
}
if (!appWindow->title)
{
free(appWindow);
return FALSE;
}
HashTable_Add(xfc->railWindows, (void*) (UINT_PTR) orderInfo->windowId, (void*) appWindow);

View File

@ -213,13 +213,20 @@ int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc,
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)
@ -228,6 +235,8 @@ int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings,
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))
@ -243,18 +252,23 @@ int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* 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)

View File

@ -216,6 +216,8 @@ int freerdp_client_print_command_line_help(int argc, char** argv)
{
length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2);
str = (char*) calloc(length + 1UL, sizeof(char));
if (!str)
return -1;
sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format);
printf("%-20s", str);
free(str);
@ -231,6 +233,8 @@ int freerdp_client_print_command_line_help(int argc, char** argv)
{
length = (int) strlen(arg->Name) + 32;
str = (char*) calloc(length + 1UL, sizeof(char));
if (!str)
return -1;
sprintf_s(str, length + 1, "%s (default:%s)", arg->Name,
arg->Default ? "on" : "off");
@ -292,7 +296,8 @@ int freerdp_client_command_line_pre_filter(void* context, int index, int argc, L
if (_stricmp(&(argv[index])[length - 4], ".rdp") == 0)
{
settings = (rdpSettings*) context;
settings->ConnectionFile = _strdup(argv[index]);
if (!(settings->ConnectionFile = _strdup(argv[index])))
return COMMAND_LINE_ERROR_MEMORY;
return 1;
}
@ -303,7 +308,8 @@ int freerdp_client_command_line_pre_filter(void* context, int index, int argc, L
if (_stricmp(&(argv[index])[length - 13], ".msrcIncident") == 0)
{
settings = (rdpSettings*) context;
settings->AssistanceFile = _strdup(argv[index]);
if (!(settings->AssistanceFile = _strdup(argv[index])))
return COMMAND_LINE_ERROR_MEMORY;
return 1;
}
@ -332,12 +338,31 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
drive->Type = RDPDR_DTYP_FILESYSTEM;
if (count > 1)
drive->Name = _strdup(params[1]);
{
if (!(drive->Name = _strdup(params[1])))
{
free(drive);
return -1;
}
}
if (count > 2)
drive->Path = _strdup(params[2]);
{
if (!(drive->Path = _strdup(params[2])))
{
free(drive->Name);
free(drive);
return -1;
}
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive);
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive))
{
free(drive->Path);
free(drive->Name);
free(drive);
return -1;
}
return 1;
}
@ -361,12 +386,33 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
printer->Type = RDPDR_DTYP_PRINT;
if (count > 1)
printer->Name = _strdup(params[1]);
{
if (!(printer->Name = _strdup(params[1])))
{
free(printer);
return -1;
}
}
if (count > 2)
printer->DriverName = _strdup(params[2]);
{
if (!(printer->DriverName = _strdup(params[2])))
{
free(printer->Name);
free(printer);
return -1;
}
}
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer))
{
free(printer->DriverName);
free(printer->Name);
free(printer);
return -1;
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer);
}
return 1;
@ -391,12 +437,30 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
smartcard->Type = RDPDR_DTYP_SMARTCARD;
if (count > 1)
smartcard->Name = _strdup(params[1]);
{
if (!(smartcard->Name = _strdup(params[1])))
{
free(smartcard);
return -1;
}
}
if (count > 2)
smartcard->Path = _strdup(params[2]);
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard);
{
if (!(smartcard->Path = _strdup(params[2])))
{
free(smartcard->Name);
free(smartcard);
return -1;
}
}
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard))
{
free(smartcard->Path);
free(smartcard->Name);
free(smartcard);
return -1;
}
}
return 1;
@ -419,18 +483,56 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
serial->Type = RDPDR_DTYP_SERIAL;
if (count > 1)
serial->Name = _strdup(params[1]);
{
if (!(serial->Name = _strdup(params[1])))
{
free(serial);
return -1;
}
}
if (count > 2)
serial->Path = _strdup(params[2]);
{
if (!(serial->Path = _strdup(params[2])))
{
free(serial->Name);
free(serial);
return -1;
}
}
if (count > 3)
serial->Driver = _strdup(params[3]);
{
if (!(serial->Driver = _strdup(params[3])))
{
free(serial->Path);
free(serial->Name);
free(serial);
return -1;
}
}
if (count > 4)
serial->Permissive = _strdup(params[4]);
{
if (!(serial->Permissive = _strdup(params[4])))
{
free(serial->Driver);
free(serial->Path);
free(serial->Name);
free(serial);
return -1;
}
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial);
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial))
{
free(serial->Permissive);
free(serial->Driver);
free(serial->Path);
free(serial->Name);
free(serial);
return -1;
}
return 1;
}
@ -452,12 +554,31 @@ int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** p
parallel->Type = RDPDR_DTYP_PARALLEL;
if (count > 1)
parallel->Name = _strdup(params[1]);
{
if (!(parallel->Name = _strdup(params[1])))
{
free(parallel);
return -1;
}
}
if (count > 2)
parallel->Path = _strdup(params[2]);
{
if (!(parallel->Path = _strdup(params[2])))
{
free(parallel->Name);
free(parallel);
return -1;
}
}
freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel);
if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel))
{
free(parallel->Path);
free(parallel->Name);
free(parallel);
return -1;
}
return 1;
}
@ -470,17 +591,40 @@ int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** p
int index;
ADDIN_ARGV* args;
args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV));
args = (ADDIN_ARGV*) calloc(1, sizeof(ADDIN_ARGV));
if (!args)
return -1;
args->argc = count;
args->argv = (char**) calloc(args->argc, sizeof(char*));
if (!args->argv)
goto error_argv;
for (index = 0; index < args->argc; index++)
{
args->argv[index] = _strdup(params[index]);
if (!args->argv[index])
{
for (--index; index >= 0; --index)
free(args->argv[index]);
freerdp_static_channel_collection_add(settings, args);
goto error_argv_strdup;
}
}
if (!freerdp_static_channel_collection_add(settings, args))
goto error_argv_index;
return 0;
error_argv_index:
for (index = 0; index < args->argc; index++)
free(args->argv[index]);
error_argv_strdup:
free(args->argv);
error_argv:
free(args);
return -1;
}
int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params)
@ -489,16 +633,39 @@ int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char**
ADDIN_ARGV* args;
args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV));
if (!args)
return -1;
args->argc = count;
args->argv = (char**) calloc(args->argc, sizeof(char*));
if (!args->argv)
goto error_argv;
for (index = 0; index < args->argc; index++)
{
args->argv[index] = _strdup(params[index]);
if (!args->argv[index])
{
for (--index; index >= 0; --index)
free(args->argv[index]);
freerdp_dynamic_channel_collection_add(settings, args);
goto error_argv_strdup;
}
}
if (!freerdp_dynamic_channel_collection_add(settings, args))
goto error_argv_index;
return 0;
error_argv_index:
for (index = 0; index < args->argc; index++)
free(args->argv[index]);
error_argv_strdup:
free(args->argv);
error_argv:
free(args);
return -1;
}
static char** freerdp_command_line_parse_comma_separated_values(char* list, int* count)
@ -522,6 +689,8 @@ static char** freerdp_command_line_parse_comma_separated_values(char* list, int*
nArgs = nCommas + 1;
p = (char**) calloc((nArgs + 1UL), sizeof(char*));
if (!p)
return NULL;
str = (char*) list;
@ -562,6 +731,7 @@ static char** freerdp_command_line_parse_comma_separated_values_offset(char* lis
int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg)
{
rdpSettings* settings = (rdpSettings*) context;
int status = 0;
CommandLineSwitchStart(arg)
@ -586,7 +756,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
freerdp_client_add_static_channel(settings, count, p);
status = freerdp_client_add_static_channel(settings, count, p);
free(p);
}
@ -712,7 +882,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT
p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
p[0] = "rdpsnd";
freerdp_client_add_static_channel(settings, count, p);
status = freerdp_client_add_static_channel(settings, count, p);
free(p);
}
@ -724,7 +894,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT
count = 1;
p[0] = "rdpsnd";
freerdp_client_add_static_channel(settings, count, p);
status = freerdp_client_add_static_channel(settings, count, p);
}
}
CommandLineSwitchCase(arg, "microphone")
@ -789,7 +959,7 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT
CommandLineSwitchEnd(arg)
return 0;
return status;
}
int freerdp_parse_username(char* username, char** user, char** domain)
@ -963,6 +1133,8 @@ int freerdp_map_keyboard_layout_name_to_id(char* name)
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++)
{
@ -976,6 +1148,8 @@ int freerdp_map_keyboard_layout_name_to_id(char* name)
return id;
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
if (!layouts)
return -1;
for (i = 0; layouts[i].code; i++)
{
@ -989,6 +1163,8 @@ int freerdp_map_keyboard_layout_name_to_id(char* name)
return id;
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
if (!layouts)
return -1;
for (i = 0; layouts[i].code; i++)
{
@ -1187,18 +1363,21 @@ int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int
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);
@ -1282,13 +1461,16 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
length = (int) (p - arg->Value);
settings->ServerPort = atoi(&p[1]);
settings->ServerHostname = (char*) calloc(length + 1UL, sizeof(char));
if (!(settings->ServerHostname = (char*) calloc(length + 1UL, sizeof(char))))
return COMMAND_LINE_ERROR_MEMORY;
strncpy(settings->ServerHostname, arg->Value, length);
settings->ServerHostname[length] = '\0';
}
else
{
settings->ServerHostname = _strdup(arg->Value);
if (!(settings->ServerHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
}
else /* ipv6 */
@ -1299,7 +1481,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
continue;
length = p2 - p;
settings->ServerHostname = (char*) calloc(length, sizeof(char));
if (!(settings->ServerHostname = (char*) calloc(length, sizeof(char))))
return COMMAND_LINE_ERROR;
strncpy(settings->ServerHostname, p+1, length-1);
if (*(p2 + 1) == ':')
{
@ -1310,7 +1493,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "spn-class")
{
settings->AuthenticationServiceClass = _strdup(arg->Value);
if (!(settings->AuthenticationServiceClass = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "credentials-delegation")
{
@ -1324,7 +1509,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{
settings->SendPreconnectionPdu = TRUE;
settings->PreconnectionBlob = _strdup(arg->Value);
if (!(settings->PreconnectionBlob = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
}
CommandLineSwitchCase(arg, "w")
@ -1337,7 +1523,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "size")
{
str = _strdup(arg->Value);
if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
p = strchr(str, 'x');
@ -1391,6 +1578,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
int count = 0;
p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
if (!p)
return COMMAND_LINE_ERROR_MEMORY;
if (count > 16)
count = 16;
@ -1411,7 +1600,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "t")
{
settings->WindowTitle = _strdup(arg->Value);
if (!(settings->WindowTitle = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "decorations")
{
@ -1423,7 +1613,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Value)
{
str = _strdup(arg->Value);
if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
if ((p = strchr(str, 'x')))
{
*p = '\0';
@ -1450,11 +1641,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
settings->ConsoleSession = TRUE;
settings->RestrictedAdminModeRequired = TRUE;
settings->PasswordHash = _strdup(arg->Value);
if (!(settings->PasswordHash = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "client-hostname")
{
settings->ClientHostname = _strdup(arg->Value);
if (!(settings->ClientHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "kbd")
{
@ -1469,11 +1662,15 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
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;
@ -1496,11 +1693,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "d")
{
settings->Domain = _strdup(arg->Value);
if (!(settings->Domain = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "p")
{
settings->Password = _strdup(arg->Value);
if (!(settings->Password = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "g")
{
@ -1512,18 +1711,21 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
length = (int) (p - arg->Value);
settings->GatewayPort = atoi(&p[1]);
settings->GatewayHostname = (char*) calloc(length + 1UL, sizeof(char));
if (!(settings->GatewayHostname = (char*) calloc(length + 1UL, sizeof(char))))
return COMMAND_LINE_ERROR_MEMORY;
strncpy(settings->GatewayHostname, arg->Value, length);
settings->GatewayHostname[length] = '\0';
}
else
{
settings->GatewayHostname = _strdup(arg->Value);
if (!(settings->GatewayHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
}
else
{
settings->GatewayHostname = _strdup(settings->ServerHostname);
if (!(settings->GatewayHostname = _strdup(settings->ServerHostname)))
return COMMAND_LINE_ERROR_MEMORY;
}
settings->GatewayEnabled = TRUE;
@ -1533,17 +1735,21 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "gu")
{
gwUser = _strdup(arg->Value);
if (!(gwUser = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->GatewayUseSameCredentials = FALSE;
}
CommandLineSwitchCase(arg, "gd")
{
settings->GatewayDomain = _strdup(arg->Value);
if (!(settings->GatewayDomain = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->GatewayUseSameCredentials = FALSE;
}
CommandLineSwitchCase(arg, "gp")
{
settings->GatewayPassword = _strdup(arg->Value);
if (!(settings->GatewayPassword = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->GatewayUseSameCredentials = FALSE;
}
CommandLineSwitchCase(arg, "gt")
@ -1587,7 +1793,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "app")
{
settings->RemoteApplicationProgram = _strdup(arg->Value);
if (!(settings->RemoteApplicationProgram = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->RemoteApplicationMode = TRUE;
settings->RemoteAppLanguageBarSupported = TRUE;
@ -1597,28 +1804,35 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "load-balance-info")
{
settings->LoadBalanceInfo = (BYTE*) _strdup(arg->Value);
if (!(settings->LoadBalanceInfo = (BYTE*) _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->LoadBalanceInfoLength = (UINT32) strlen((char*) settings->LoadBalanceInfo);
}
CommandLineSwitchCase(arg, "app-name")
{
settings->RemoteApplicationName = _strdup(arg->Value);
if (!(settings->RemoteApplicationName = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "app-icon")
{
settings->RemoteApplicationIcon = _strdup(arg->Value);
if (!(settings->RemoteApplicationIcon = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "app-cmd")
{
settings->RemoteApplicationCmdLine = _strdup(arg->Value);
if (!(settings->RemoteApplicationCmdLine = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "app-file")
{
settings->RemoteApplicationFile = _strdup(arg->Value);
if (!(settings->RemoteApplicationFile = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "app-guid")
{
settings->RemoteApplicationGuid = _strdup(arg->Value);
if (!(settings->RemoteApplicationGuid = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "compression")
{
@ -1642,11 +1856,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "shell")
{
settings->AlternateShell = _strdup(arg->Value);
if (!(settings->AlternateShell = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "shell-dir")
{
settings->ShellWorkingDirectory = _strdup(arg->Value);
if (!(settings->ShellWorkingDirectory = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "audio-mode")
{
@ -1798,7 +2014,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "pcb")
{
settings->SendPreconnectionPdu = TRUE;
settings->PreconnectionBlob = _strdup(arg->Value);
if (!(settings->PreconnectionBlob = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "pcid")
{
@ -1888,20 +2105,24 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
if (strcmp(arg->Value, "netmon") == 0)
{
settings->AllowedTlsCiphers = _strdup("ALL:!ECDH");
if (!(settings->AllowedTlsCiphers = _strdup("ALL:!ECDH")))
return COMMAND_LINE_ERROR_MEMORY;
}
else if (strcmp(arg->Value, "ma") == 0)
{
settings->AllowedTlsCiphers = _strdup("AES128-SHA");
if (!(settings->AllowedTlsCiphers = _strdup("AES128-SHA")))
return COMMAND_LINE_ERROR_MEMORY;
}
else
{
settings->AllowedTlsCiphers = _strdup(arg->Value);
if (!(settings->AllowedTlsCiphers = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
}
CommandLineSwitchCase(arg, "cert-name")
{
settings->CertificateName = _strdup(arg->Value);
if (!(settings->CertificateName = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "cert-ignore")
{
@ -1990,11 +2211,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "wm-class")
{
settings->WmClass = _strdup(arg->Value);
if (!(settings->WmClass = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "play-rfx")
{
settings->PlayRemoteFxFile = _strdup(arg->Value);
if (!(settings->PlayRemoteFxFile = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
settings->PlayRemoteFx = TRUE;
}
CommandLineSwitchCase(arg, "auth-only")
@ -2028,7 +2251,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "assistance")
{
settings->RemoteAssistanceMode = TRUE;
settings->RemoteAssistancePassword = _strdup(arg->Value);
if (!(settings->RemoteAssistancePassword = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchDefault(arg)
{
@ -2040,17 +2264,23 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (!settings->Domain && user)
{
freerdp_parse_username(user, &settings->Username, &settings->Domain);
int ret;
ret = freerdp_parse_username(user, &settings->Username, &settings->Domain);
free(user);
if (ret != 0 )
return COMMAND_LINE_ERROR;
}
else
settings->Username = user;
if (!settings->GatewayDomain && gwUser)
{
freerdp_parse_username(gwUser, &settings->GatewayUsername,
int ret;
ret = freerdp_parse_username(gwUser, &settings->GatewayUsername,
&settings->GatewayDomain);
free(gwUser);
if (ret != 0)
return COMMAND_LINE_ERROR;
}
else
settings->GatewayUsername = gwUser;

View File

@ -89,7 +89,7 @@ COMMAND_LINE_ARGUMENT_A old_args[] =
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
};
void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32* ServerPort)
BOOL freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32* ServerPort)
{
char* p;
@ -97,7 +97,8 @@ void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32*
&& (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
{
/* Either "[...]" or "[...]:..." with at most one : after the brackets */
*ServerHostname = _strdup(str + 1);
if (!(*ServerHostname = _strdup(str + 1)))
return FALSE;
if ((p = strchr((char*) *ServerHostname, ']')))
{
@ -110,7 +111,8 @@ void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32*
else
{
/* Port number is cut off and used if exactly one : in the string */
*ServerHostname = _strdup(str);
if (!(*ServerHostname = _strdup(str)))
return FALSE;
if ((p = strchr((char*) *ServerHostname, ':')) && !strchr(p + 1, ':'))
{
@ -118,6 +120,7 @@ void freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32*
*ServerPort = atoi(p + 1);
}
}
return TRUE;
}
int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args)
@ -183,7 +186,8 @@ int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args)
return 1;
args_handled++;
settings->RemoteApplicationProgram = _strdup(args->argv[1]);
if (!(settings->RemoteApplicationProgram = _strdup(args->argv[1])))
return -1;
}
else
{
@ -211,8 +215,9 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
return -1;
}
freerdp_client_old_parse_hostname((char*) argv[index],
&settings->ServerHostname, &settings->ServerPort);
if (!freerdp_client_old_parse_hostname((char*) argv[index],
&settings->ServerHostname, &settings->ServerPort))
return -1;
return 2;
}
@ -240,7 +245,14 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
return -1;
args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV));
if (!args)
return -1;
args->argv = (char**) calloc(argc, sizeof(char*));
if (!args->argv)
{
free(args);
return -1;
}
args->argc = 1;
if ((index < argc - 1) && strcmp("--data", argv[index + 1]) == 0)
@ -250,9 +262,14 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
while ((index < argc) && (strcmp("--", argv[index]) != 0))
{
args_handled ++;
args_handled++;
args->argc = 1;
args->argv[0] = _strdup(argv[t]);
if (!(args->argv[0] = _strdup(argv[t])))
{
free(args->argv);
free(args);
return -1;
}
for (j = 0, p = (char*) argv[index]; (j < 4) && (p != NULL); j++)
{
@ -277,14 +294,31 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
if (p != NULL)
{
length = (int) (p - a);
args->argv[j + 1] = (char*) malloc(length + 1);
if (!(args->argv[j + 1] = (char*) malloc(length + 1)))
{
for (; j >= 0; --j)
free(args->argv[j]);
free(args->argv);
free(args);
return -1;
}
CopyMemory(args->argv[j + 1], a, length);
args->argv[j + 1][length] = '\0';
p++;
}
else
{
args->argv[j + 1] = _strdup(a);
if (!(args->argv[j + 1] = _strdup(a)))
{
for (; j >= 0; --j)
free(args->argv[j]);
free(args->argv);
free(args);
return -1;
}
}
args->argc++;
@ -306,7 +340,12 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
{
if (settings)
{
args->argv[0] = _strdup(argv[t]);
if (!(args->argv[0] = _strdup(argv[t])))
{
free(args->argv);
free(args);
return -1;
}
args_handled = freerdp_client_old_process_plugin(settings, args);
free (args->argv[0]);
}
@ -459,8 +498,9 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "c")
{
settings->ShellWorkingDirectory = _strdup(arg->Value);
WLog_WARN(TAG, "-c %s -> /shell-dir:%s", arg->Value, arg->Value);
if (!(settings->ShellWorkingDirectory = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
}
CommandLineSwitchCase(arg, "D")
{
@ -469,12 +509,14 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "T")
{
settings->WindowTitle = _strdup(arg->Value);
if (!(settings->WindowTitle = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-T %s -> /title:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "d")
{
settings->Domain = _strdup(arg->Value);
if (!(settings->Domain = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-d %s -> /d:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "f")
@ -484,7 +526,8 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "g")
{
str = _strdup(arg->Value);
if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
p = strchr(str, 'x');
@ -511,7 +554,8 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "n")
{
settings->ClientHostname = _strdup(arg->Value);
if (!(settings->ClientHostname = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-n -> /client-hostname:%s", arg->Value);
}
CommandLineSwitchCase(arg, "o")
@ -521,14 +565,16 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "p")
{
settings->Password = _strdup(arg->Value);
if (!(settings->Password = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-p ****** -> /p:******");
/* Hide the value from 'ps'. */
FillMemory(arg->Value, strlen(arg->Value), '*');
}
CommandLineSwitchCase(arg, "s")
{
settings->AlternateShell = _strdup(arg->Value);
if (!(settings->AlternateShell = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-s %s -> /shell:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "t")
@ -538,7 +584,8 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "u")
{
settings->Username = _strdup(arg->Value);
if (!(settings->Username = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
WLog_WARN(TAG, "-u %s -> /u:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "x")

View File

@ -52,9 +52,16 @@ static WCHAR CR_LF_STR_W[] = { '\r', '\n', '\0' };
#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 standard = 1;
#ifdef DEBUG_CLIENT_FILE
WLog_DBG(TAG, "%s:i:%d", name, value);
@ -189,122 +196,155 @@ BOOL freerdp_client_rdp_file_set_integer(rdpFile* file, const char* name, int va
else if (_stricmp(name, "rdgiskdcproxy") == 0)
file->RdgIsKdcProxy = value;
else
bStandard = FALSE;
standard = 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;
file->lines[index].flags |= RDP_FILE_LINE_FLAG_TYPE_INTEGER;
if (bStandard)
if (standard)
file->lines[index].flags |= RDP_FILE_LINE_FLAG_STANDARD;
file->lines[index].valueLength = 0;
}
return bStandard;
return standard;
}
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 standard = 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;
standard = 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 (standard == 0)
file->lines[index].flags |= RDP_FILE_LINE_FLAG_STANDARD;
file->lines[index].valueLength = 0;
}
return bStandard;
return standard;
}
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)
{
@ -314,16 +354,19 @@ void freerdp_client_add_option(rdpFile* file, char* option)
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;
@ -343,72 +386,105 @@ int freerdp_client_parse_rdp_file_add_line(rdpFile* file, char* line, int index)
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;
@ -431,11 +507,14 @@ BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, const BYTE* buffe
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 */
}
@ -462,12 +541,14 @@ BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, const BYTE* buffe
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')
{
@ -483,7 +564,7 @@ next_line:
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;
@ -506,7 +587,8 @@ BOOL freerdp_client_parse_rdp_file_buffer_unicode(rdpFile* file, const BYTE* buf
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] == '/')
{
@ -538,12 +620,14 @@ BOOL freerdp_client_parse_rdp_file_buffer_unicode(rdpFile* file, const BYTE* buf
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')
{
@ -594,6 +678,11 @@ BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name)
}
buffer = (BYTE*) malloc(file_size + 2);
if (!buffer)
{
fclose(fp);
return FALSE;
}
read_size = fread(buffer, file_size, 1, fp);
if (!read_size)
@ -606,7 +695,6 @@ BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name)
if (read_size < 1)
{
free(buffer);
buffer = NULL;
return FALSE;
}
@ -623,7 +711,9 @@ BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name)
#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)
{
@ -763,18 +853,26 @@ size_t freerdp_client_write_rdp_file_buffer(const rdpFile* file, char* buffer, s
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);
@ -785,9 +883,11 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
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);
@ -813,9 +913,15 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
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)
{
@ -845,6 +951,8 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
if (~((size_t) file->LoadBalanceInfo))
{
settings->LoadBalanceInfo = (BYTE*) _strdup(file->LoadBalanceInfo);
if (!settings->LoadBalanceInfo)
return FALSE;
settings->LoadBalanceInfoLength = (int) strlen((char*) settings->LoadBalanceInfo);
}
@ -897,9 +1005,11 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
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);
@ -916,15 +1026,30 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
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);
@ -1036,14 +1161,15 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
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;
@ -1052,7 +1178,7 @@ rdpFileLine* freerdp_client_rdp_file_find_line_index(rdpFile* file, int index)
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;
@ -1075,6 +1201,14 @@ rdpFileLine* freerdp_client_rdp_file_find_line_by_name(rdpFile* file, const char
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;
@ -1082,17 +1216,20 @@ int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, c
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;
@ -1100,14 +1237,24 @@ int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, c
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)
@ -1149,9 +1296,18 @@ int freerdp_client_rdp_file_set_integer_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);
}
@ -1174,7 +1330,7 @@ int freerdp_client_rdp_file_get_integer_option(rdpFile* file, const char* name)
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);
@ -1193,12 +1349,30 @@ rdpFile* freerdp_client_rdp_file_new()
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;

View File

@ -271,6 +271,11 @@ int TestClientRdpFile(int argc, char* argv[])
/* 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)
@ -331,7 +336,12 @@ int TestClientRdpFile(int argc, char* argv[])
}
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");
@ -339,7 +349,11 @@ int TestClientRdpFile(int argc, char* argv[])
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++)
{

View File

@ -11,6 +11,7 @@
#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"
@ -19,7 +20,6 @@
#import "RDPSession.h"
#import "Utils.h"
#pragma mark Connection helpers
static BOOL ios_pre_connect(freerdp* instance)
@ -279,6 +279,8 @@ void ios_context_free(freerdp* instance, rdpContext* context)
freerdp* ios_freerdp_new()
{
freerdp* inst = freerdp_new();
if (!inst)
return NULL;
inst->PreConnect = ios_pre_connect;
inst->PostConnect = ios_post_connect;
@ -297,6 +299,14 @@ freerdp* ios_freerdp_new()
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;
}

View File

@ -51,6 +51,14 @@ BOOL ios_ui_authenticate(freerdp * instance, char** username, char** password, c
*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;
}

View File

@ -75,31 +75,46 @@ NSString* TSXSessionDidFailToConnectNotification = @"TSXSessionDidFailToConnect"
settings->ConsoleSession = 1;
// connection info
settings->ServerHostname = strdup([_params UTF8StringForKey:@"hostname"]);
if (!(settings->ServerHostname = strdup([_params UTF8StringForKey:@"hostname"])))
goto out_free;
// String settings
if ([[_params StringForKey:@"username"] length])
{
settings->Username = strdup([_params UTF8StringForKey:@"username"]);
if (!settings->Username)
goto out_free;
}
if ([[_params StringForKey:@"password"] length])
{
settings->Password = strdup([_params UTF8StringForKey:@"password"]);
if (!settings->Password)
goto out_free;
}
if ([[_params StringForKey:@"domain"] length])
{
settings->Domain = strdup([_params UTF8StringForKey:@"domain"]);
if (!settings->Domain)
goto out_free;
}
settings->ShellWorkingDirectory = strdup([_params UTF8StringForKey:@"working_directory"]);
settings->AlternateShell = strdup([_params UTF8StringForKey:@"remote_program"]);
// RemoteFX
if (!settings->ShellWorkingDirectory || !settings->AlternateShell)
goto out_free;
// RemoteFX
if ([_params boolForKey:@"perf_remotefx" with3GEnabled:connected_via_3g])
{
settings->RemoteFxCodec = TRUE;
settings->FastPathOutput = TRUE;
settings->ColorDepth = 32;
settings->LargePointerFlag = TRUE;
settings->FrameMarkerCommandEnabled = TRUE;
settings->FrameAcknowledge = 10;
settings->FrameMarkerCommandEnabled = TRUE;
settings->FrameAcknowledge = 10;
}
else
{
@ -176,6 +191,12 @@ NSString* TSXSessionDidFailToConnectNotification = @"TSXSessionDidFailToConnect"
settings->GatewayUsageMethod = TSC_PROXY_MODE_DIRECT;
settings->GatewayEnabled = TRUE;
settings->GatewayUseSameCredentials = FALSE;
if (!settings->GatewayHostname || !settings->GatewayUsername || !settings->GatewayPassword
|| !settings->GatewayDomain)
{
goto out_free;
}
}
// Remote keyboard layout
@ -187,6 +208,10 @@ NSString* TSXSessionDidFailToConnectNotification = @"TSXSessionDidFailToConnect"
[self mfi]->session = self;
return self;
out_free:
[self release];
return nil;
}
- (void)dealloc

View File

@ -28,6 +28,6 @@ option(ANDROID_BUILD_JAVA_DEBUG "Create a android debug package" ${JAVA_DEBUG_DE
set(ANDROID_APP_VERSION 3 CACHE STRING "Application version")
set(ANDROID_APP_TARGET_SDK 21 CACHE STRING "Application target android SDK")
set(ANDROID_APP_MIN_SDK 9 CACHE STRING "Application minimum android SDK requirement")
set(ANDROID_APP_MIN_SDK 14 CACHE STRING "Application minimum android SDK requirement")
set(ANDROID_APP_GOOGLE_TARGET_SDK "16" CACHE STRING "Application target google SDK")

View File

@ -209,6 +209,6 @@ After that FreeRDP and the Android package need to be rebuilt to include the lat
Android CMake related Variables
-------------------------------
ANDROID_APP_TARGET_SDK ... specifies the desired android target SDK, currently 11
ANDROID_APP_MIN_SDK ... specifies the minimum android SDK version supported, currently 8
ANDROID_APP_TARGET_SDK ... specifies the desired android target SDK, currently 21
ANDROID_APP_MIN_SDK ... specifies the minimum android SDK version supported, currently 14
ANDROID_APP_GOOGLE_TARGET_SDK ... specifies the minimum google SDK requirement, currently 16

View File

@ -104,7 +104,7 @@ struct _BITMAP_PLANAR_CONTEXT
FREERDP_API int freerdp_split_color_planes(BYTE* data, UINT32 format, int width, int height, int scanline, BYTE* planes[4]);
FREERDP_API BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* plane, int width, int height, BYTE* outPlane, int* dstSize);
FREERDP_API BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int height, BYTE* outPlane);
FREERDP_API int freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4]);
FREERDP_API BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4]);
FREERDP_API BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, UINT32 format,
int width, int height, int scanline, BYTE* dstData, int* pDstSize);

View File

@ -55,8 +55,8 @@ struct rdp_certificate_store
#endif
FREERDP_API rdpCertificateData* certificate_data_new(
char* hostname, UINT16 port, char*subject,
char*issuer, char* fingerprint);
char* hostname, UINT16 port, char* subject,
char* issuer, char* fingerprint);
FREERDP_API void certificate_data_free(
rdpCertificateData* certificate_data);
FREERDP_API rdpCertificateStore* certificate_store_new(

View File

@ -1435,17 +1435,17 @@ FREERDP_API int freerdp_addin_replace_argument(ADDIN_ARGV* args, char* previous,
FREERDP_API int freerdp_addin_set_argument_value(ADDIN_ARGV* args, char* option, char* value);
FREERDP_API int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char* option, char* value);
FREERDP_API void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device);
FREERDP_API BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device);
FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name);
FREERDP_API RDPDR_DEVICE* freerdp_device_clone(RDPDR_DEVICE* device);
FREERDP_API void freerdp_device_collection_free(rdpSettings* settings);
FREERDP_API void freerdp_static_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel);
FREERDP_API BOOL freerdp_static_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel);
FREERDP_API ADDIN_ARGV* freerdp_static_channel_collection_find(rdpSettings* settings, const char* name);
FREERDP_API ADDIN_ARGV* freerdp_static_channel_clone(ADDIN_ARGV* channel);
FREERDP_API void freerdp_static_channel_collection_free(rdpSettings* settings);
FREERDP_API void freerdp_dynamic_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel);
FREERDP_API BOOL freerdp_dynamic_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel);
FREERDP_API ADDIN_ARGV* freerdp_dynamic_channel_collection_find(rdpSettings* settings, const char* name);
FREERDP_API ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel);
FREERDP_API void freerdp_dynamic_channel_collection_free(rdpSettings* settings);

View File

@ -75,7 +75,7 @@ extern "C" {
FREERDP_API rdpPcap* pcap_open(char* name, BOOL write);
FREERDP_API void pcap_close(rdpPcap* pcap);
FREERDP_API void pcap_add_record(rdpPcap* pcap, void* data, UINT32 length);
FREERDP_API BOOL pcap_add_record(rdpPcap* pcap, void* data, UINT32 length);
FREERDP_API BOOL pcap_has_next_record(rdpPcap* pcap);
FREERDP_API BOOL pcap_get_next_record(rdpPcap* pcap, pcap_record* record);
FREERDP_API BOOL pcap_get_next_record_header(rdpPcap* pcap, pcap_record* record);

View File

@ -189,25 +189,31 @@ rdpBrushCache* brush_cache_new(rdpSettings* settings)
{
rdpBrushCache* brushCache;
brushCache = (rdpBrushCache*) malloc(sizeof(rdpBrushCache));
brushCache = (rdpBrushCache*) calloc(1, sizeof(rdpBrushCache));
if (brushCache)
{
ZeroMemory(brushCache, sizeof(rdpBrushCache));
if (!brushCache)
return NULL;
brushCache->settings = settings;
brushCache->settings = settings;
brushCache->maxEntries = 64;
brushCache->maxMonoEntries = 64;
brushCache->maxEntries = 64;
brushCache->maxMonoEntries = 64;
brushCache->entries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brushCache->maxEntries);
ZeroMemory(brushCache->entries, sizeof(BRUSH_ENTRY) * brushCache->maxEntries);
brushCache->entries = (BRUSH_ENTRY*)calloc(brushCache->maxEntries, sizeof(BRUSH_ENTRY));
if (!brushCache->entries)
goto error_entries;
brushCache->monoEntries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brushCache->maxMonoEntries);
ZeroMemory(brushCache->monoEntries, sizeof(BRUSH_ENTRY) * brushCache->maxMonoEntries);
}
brushCache->monoEntries = (BRUSH_ENTRY*) calloc(brushCache->maxMonoEntries, sizeof(BRUSH_ENTRY));
if (!brushCache->monoEntries)
goto error_mono;
return brushCache;
error_mono:
free(brushCache->entries);
error_entries:
free(brushCache);
return NULL;
}
void brush_cache_free(rdpBrushCache* brushCache)

View File

@ -31,22 +31,50 @@ rdpCache* cache_new(rdpSettings* settings)
{
rdpCache* cache;
cache = (rdpCache*) malloc(sizeof(rdpCache));
ZeroMemory(cache, sizeof(rdpCache));
cache = (rdpCache*) calloc(1, sizeof(rdpCache));
if (!cache)
return NULL;
if (cache != NULL)
{
cache->settings = settings;
cache->glyph = glyph_cache_new(settings);
cache->brush = brush_cache_new(settings);
cache->pointer = pointer_cache_new(settings);
cache->bitmap = bitmap_cache_new(settings);
cache->offscreen = offscreen_cache_new(settings);
cache->palette = palette_cache_new(settings);
cache->nine_grid = nine_grid_cache_new(settings);
}
cache->settings = settings;
cache->glyph = glyph_cache_new(settings);
if (!cache->glyph)
goto error_glyph;
cache->brush = brush_cache_new(settings);
if (!cache->brush)
goto error_brush;
cache->pointer = pointer_cache_new(settings);
if (!cache->pointer)
goto error_pointer;
cache->bitmap = bitmap_cache_new(settings);
if (!cache->bitmap)
goto error_bitmap;
cache->offscreen = offscreen_cache_new(settings);
if (!cache->offscreen)
goto error_offscreen;
cache->palette = palette_cache_new(settings);
if (!cache->palette)
goto error_palette;
cache->nine_grid = nine_grid_cache_new(settings);
if (!cache->nine_grid)
goto error_ninegrid;
return cache;
error_ninegrid:
palette_cache_free(cache->palette);
error_palette:
offscreen_cache_free(cache->offscreen);
error_offscreen:
bitmap_cache_free(cache->bitmap);
error_bitmap:
pointer_cache_free(cache->pointer);
error_pointer:
brush_cache_free(cache->brush);
error_brush:
glyph_cache_free(cache->glyph);
error_glyph:
free(cache);
return NULL;
}
void cache_free(rdpCache* cache)

View File

@ -77,7 +77,7 @@ void update_process_glyph(rdpContext* context, BYTE* data, int* index,
}
}
void update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 length,
BOOL update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 length,
UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel, UINT32 bgcolor, UINT32 fgcolor, int x, int y,
int bkX, int bkY, int bkWidth, int bkHeight, int opX, int opY, int opWidth, int opHeight, BOOL fOpRedundant)
{
@ -108,17 +108,20 @@ void update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 leng
if (opWidth > 0 && opHeight > 0)
{
Glyph_BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor, fOpRedundant);
if (!Glyph_BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor, fOpRedundant))
return FALSE;
}
else
{
if (fOpRedundant)
{
Glyph_BeginDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor, fOpRedundant);
if (!Glyph_BeginDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor, fOpRedundant))
return FALSE;
}
else
{
Glyph_BeginDraw(context, 0, 0, 0, 0, bgcolor, fgcolor, fOpRedundant);
if (!Glyph_BeginDraw(context, 0, 0, 0, 0, bgcolor, fgcolor, fOpRedundant))
return FALSE;
}
}
@ -175,6 +178,8 @@ void update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 leng
size = data[index + 2];
fragments = (BYTE*) malloc(size);
if (!fragments)
return FALSE;
CopyMemory(fragments, data, size);
glyph_cache_fragment_put(glyph_cache, id, size, fragments);
@ -194,9 +199,9 @@ void update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 leng
}
if (opWidth > 0 && opHeight > 0)
Glyph_EndDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
else
Glyph_EndDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
return Glyph_EndDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
return Glyph_EndDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
}
BOOL update_gdi_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex)
@ -211,14 +216,12 @@ BOOL update_gdi_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex)
bkHeight = glyphIndex->bkBottom - glyphIndex->bkTop;
opHeight = glyphIndex->opBottom - glyphIndex->opTop;
update_process_glyph_fragments(context, glyphIndex->data, glyphIndex->cbData,
return update_process_glyph_fragments(context, glyphIndex->data, glyphIndex->cbData,
glyphIndex->cacheId, glyphIndex->ulCharInc, glyphIndex->flAccel,
glyphIndex->backColor, glyphIndex->foreColor, glyphIndex->x, glyphIndex->y,
glyphIndex->bkLeft, glyphIndex->bkTop, bkWidth, bkHeight,
glyphIndex->opLeft, glyphIndex->opTop, opWidth, opHeight,
glyphIndex->fOpRedundant);
return TRUE;
}
BOOL update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fastIndex)
@ -263,7 +266,7 @@ BOOL update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fastIndex)
if (y == -32768)
y = fastIndex->bkTop;
update_process_glyph_fragments(context, fastIndex->data, fastIndex->cbData,
return update_process_glyph_fragments(context, fastIndex->data, fastIndex->cbData,
fastIndex->cacheId, fastIndex->ulCharInc, fastIndex->flAccel,
fastIndex->backColor, fastIndex->foreColor, x, y,
fastIndex->bkLeft, fastIndex->bkTop,
@ -271,7 +274,6 @@ BOOL update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fastIndex)
opLeft, opTop,
opRight - opLeft, opBottom - opTop,
FALSE);
return TRUE;
}
BOOL update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph)
@ -323,14 +325,20 @@ BOOL update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph)
glyphData = &fastGlyph->glyphData;
glyph = Glyph_Alloc(context);
if (!glyph)
return FALSE;
glyph->x = glyphData->x;
glyph->y = glyphData->y;
glyph->cx = glyphData->cx;
glyph->cy = glyphData->cy;
glyph->cb = glyphData->cb;
glyph->aj = malloc(glyphData->cb);
if (!glyph->aj)
goto error_aj;
CopyMemory(glyph->aj, glyphData->aj, glyph->cb);
Glyph_New(context, glyph);
if (!Glyph_New(context, glyph))
goto error_glyph_new;
glyph_cache_put(cache->glyph, fastGlyph->cacheId, fastGlyph->data[0], glyph);
}
@ -338,7 +346,7 @@ BOOL update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph)
text_data[0] = fastGlyph->data[0];
text_data[1] = 0;
update_process_glyph_fragments(context, text_data, 1,
return update_process_glyph_fragments(context, text_data, 1,
fastGlyph->cacheId, fastGlyph->ulCharInc, fastGlyph->flAccel,
fastGlyph->backColor, fastGlyph->foreColor, x, y,
fastGlyph->bkLeft, fastGlyph->bkTop,
@ -346,7 +354,13 @@ BOOL update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fastGlyph)
opLeft, opTop,
opRight - opLeft, opBottom - opTop,
FALSE);
return TRUE;
error_glyph_new:
free(glyph->aj);
glyph->aj = NULL;
error_aj:
Glyph_Free(context, glyph);
return FALSE;
}
BOOL update_gdi_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cacheGlyph)
@ -362,10 +376,7 @@ BOOL update_gdi_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cacheGlyph)
glyph = Glyph_Alloc(context);
if (!glyph)
{
/* TODO: cleanup previously allocated memory */
return FALSE;
}
glyph->x = glyph_data->x;
glyph->y = glyph_data->y;
@ -373,7 +384,11 @@ BOOL update_gdi_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cacheGlyph)
glyph->cy = glyph_data->cy;
glyph->cb = glyph_data->cb;
glyph->aj = glyph_data->aj;
Glyph_New(context, glyph);
if (!Glyph_New(context, glyph))
{
Glyph_Free(context, glyph);
return FALSE;
}
glyph_cache_put(cache->glyph, cacheGlyph->cacheId, glyph_data->cacheIndex, glyph);
}

View File

@ -95,21 +95,23 @@ rdpNineGridCache* nine_grid_cache_new(rdpSettings* settings)
{
rdpNineGridCache* nine_grid;
nine_grid = (rdpNineGridCache*) malloc(sizeof(rdpNineGridCache));
ZeroMemory(nine_grid, sizeof(rdpNineGridCache));
nine_grid = (rdpNineGridCache*) calloc(1, sizeof(rdpNineGridCache));
if (!nine_grid)
return NULL;
if (nine_grid != NULL)
nine_grid->settings = settings;
nine_grid->maxSize = 2560;
nine_grid->maxEntries = 256;
nine_grid->settings->DrawNineGridCacheSize = nine_grid->maxSize;
nine_grid->settings->DrawNineGridCacheEntries = nine_grid->maxEntries;
nine_grid->entries = (NINE_GRID_ENTRY*) calloc(nine_grid->maxEntries, sizeof(NINE_GRID_ENTRY));
if (!nine_grid->entries)
{
nine_grid->settings = settings;
nine_grid->maxSize = 2560;
nine_grid->maxEntries = 256;
nine_grid->settings->DrawNineGridCacheSize = nine_grid->maxSize;
nine_grid->settings->DrawNineGridCacheEntries = nine_grid->maxEntries;
nine_grid->entries = (NINE_GRID_ENTRY*) malloc(sizeof(NINE_GRID_ENTRY) * nine_grid->maxEntries);
ZeroMemory(nine_grid->entries, sizeof(NINE_GRID_ENTRY) * nine_grid->maxEntries);
free(nine_grid);
return NULL;
}
return nine_grid;

View File

@ -146,26 +146,27 @@ rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings)
{
rdpOffscreenCache* offscreenCache;
offscreenCache = (rdpOffscreenCache*) malloc(sizeof(rdpOffscreenCache));
offscreenCache = (rdpOffscreenCache*) calloc(1, sizeof(rdpOffscreenCache));
if (offscreenCache)
if (!offscreenCache)
return NULL;
offscreenCache->settings = settings;
offscreenCache->update = ((freerdp*) settings->instance)->update;
offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE;
offscreenCache->maxSize = 7680;
offscreenCache->maxEntries = 2000;
settings->OffscreenCacheSize = offscreenCache->maxSize;
settings->OffscreenCacheEntries = offscreenCache->maxEntries;
offscreenCache->entries = (rdpBitmap**) calloc(offscreenCache->maxEntries, sizeof(rdpBitmap*));
if (!offscreenCache->entries)
{
ZeroMemory(offscreenCache, sizeof(rdpOffscreenCache));
offscreenCache->settings = settings;
offscreenCache->update = ((freerdp*) settings->instance)->update;
offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE;
offscreenCache->maxSize = 7680;
offscreenCache->maxEntries = 2000;
settings->OffscreenCacheSize = offscreenCache->maxSize;
settings->OffscreenCacheEntries = offscreenCache->maxEntries;
offscreenCache->entries = (rdpBitmap**) malloc(sizeof(rdpBitmap*) * offscreenCache->maxEntries);
ZeroMemory(offscreenCache->entries, sizeof(rdpBitmap*) * offscreenCache->maxEntries);
free(offscreenCache);
return NULL;
}
return offscreenCache;
}

View File

@ -109,39 +109,37 @@ BOOL update_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* pointer_new)
rdpCache* cache = context->cache;
pointer = Pointer_Alloc(context);
if (!pointer)
return FALSE;
if (pointer != NULL)
pointer->xorBpp = pointer_new->xorBpp;
pointer->xPos = pointer_new->colorPtrAttr.xPos;
pointer->yPos = pointer_new->colorPtrAttr.yPos;
pointer->width = pointer_new->colorPtrAttr.width;
pointer->height = pointer_new->colorPtrAttr.height;
pointer->lengthAndMask = pointer_new->colorPtrAttr.lengthAndMask;
pointer->lengthXorMask = pointer_new->colorPtrAttr.lengthXorMask;
if (pointer->lengthAndMask)
{
pointer->xorBpp = pointer_new->xorBpp;
pointer->xPos = pointer_new->colorPtrAttr.xPos;
pointer->yPos = pointer_new->colorPtrAttr.yPos;
pointer->width = pointer_new->colorPtrAttr.width;
pointer->height = pointer_new->colorPtrAttr.height;
pointer->lengthAndMask = pointer_new->colorPtrAttr.lengthAndMask;
pointer->lengthXorMask = pointer_new->colorPtrAttr.lengthXorMask;
pointer->andMaskData = pointer->xorMaskData = NULL;
if (pointer->lengthAndMask)
{
pointer->andMaskData = (BYTE*) malloc(pointer->lengthAndMask);
if (!pointer->andMaskData)
goto out_fail;
CopyMemory(pointer->andMaskData, pointer_new->colorPtrAttr.andMaskData, pointer->lengthAndMask);
}
if (pointer->lengthXorMask)
{
pointer->xorMaskData = (BYTE*) malloc(pointer->lengthXorMask);
CopyMemory(pointer->xorMaskData, pointer_new->colorPtrAttr.xorMaskData, pointer->lengthXorMask);
}
pointer->New(context, pointer);
pointer_cache_put(cache->pointer, pointer_new->colorPtrAttr.cacheIndex, pointer);
Pointer_Set(context, pointer);
return TRUE;
pointer->andMaskData = (BYTE*) malloc(pointer->lengthAndMask);
if (!pointer->andMaskData)
goto out_fail;
CopyMemory(pointer->andMaskData, pointer_new->colorPtrAttr.andMaskData, pointer->lengthAndMask);
}
return FALSE;
if (pointer->lengthXorMask)
{
pointer->xorMaskData = (BYTE*) malloc(pointer->lengthXorMask);
if (!pointer->xorMaskData)
goto out_fail;
CopyMemory(pointer->xorMaskData, pointer_new->colorPtrAttr.xorMaskData, pointer->lengthXorMask);
}
if (!pointer->New(context, pointer))
goto out_fail;
pointer_cache_put(cache->pointer, pointer_new->colorPtrAttr.cacheIndex, pointer);
return Pointer_Set(context, pointer);
out_fail:
free(pointer->andMaskData);
@ -213,18 +211,19 @@ rdpPointerCache* pointer_cache_new(rdpSettings* settings)
{
rdpPointerCache* pointer_cache;
pointer_cache = (rdpPointerCache*) malloc(sizeof(rdpPointerCache));
pointer_cache = (rdpPointerCache*) calloc(1, sizeof(rdpPointerCache));
if (!pointer_cache)
return NULL;
if (pointer_cache != NULL)
pointer_cache->settings = settings;
pointer_cache->cacheSize = settings->PointerCacheSize;
pointer_cache->update = ((freerdp*) settings->instance)->update;
pointer_cache->entries = (rdpPointer**) calloc(pointer_cache->cacheSize, sizeof(rdpPointer*));
if (!pointer_cache->entries)
{
ZeroMemory(pointer_cache, sizeof(rdpPointerCache));
pointer_cache->settings = settings;
pointer_cache->cacheSize = settings->PointerCacheSize;
pointer_cache->update = ((freerdp*) settings->instance)->update;
pointer_cache->entries = (rdpPointer**) malloc(sizeof(rdpPointer*) * pointer_cache->cacheSize);
ZeroMemory(pointer_cache->entries, sizeof(rdpPointer*) * pointer_cache->cacheSize);
free(pointer_cache);
return NULL;
}
return pointer_cache;

View File

@ -377,12 +377,13 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
if (vBarShortEntry->count > vBarShortEntry->size)
{
UINT32 *tmp;
vBarShortEntry->size = vBarShortEntry->count;
if (!vBarShortEntry->pixels)
vBarShortEntry->pixels = (UINT32*) malloc(vBarShortEntry->count * 4);
else
vBarShortEntry->pixels = (UINT32*) realloc(vBarShortEntry->pixels, vBarShortEntry->count * 4);
tmp = (UINT32*) realloc(vBarShortEntry->pixels, vBarShortEntry->count * 4);
if (!tmp)
return -1;
vBarShortEntry->pixels = tmp;
}
if (!vBarShortEntry->pixels && vBarShortEntry->size)
@ -442,12 +443,13 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
if (vBarEntry->count > vBarEntry->size)
{
UINT32 *tmp;
vBarEntry->size = vBarEntry->count;
if (!vBarEntry->pixels)
vBarEntry->pixels = (UINT32*) malloc(vBarEntry->count * 4);
else
vBarEntry->pixels = (UINT32*) realloc(vBarEntry->pixels, vBarEntry->count * 4);
tmp = (UINT32*) realloc(vBarEntry->pixels, vBarEntry->count * 4);
if (!tmp)
return -1;
vBarEntry->pixels = tmp;
}
if (!vBarEntry->pixels && vBarEntry->size)
@ -791,12 +793,13 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
if (glyphEntry->count > glyphEntry->size)
{
UINT32 *tmp;
glyphEntry->size = glyphEntry->count;
if (!glyphEntry->pixels)
glyphEntry->pixels = (UINT32*) malloc(glyphEntry->size * 4);
else
glyphEntry->pixels = (UINT32*) realloc(glyphEntry->pixels, glyphEntry->size * 4);
tmp = (UINT32*) realloc(glyphEntry->pixels, glyphEntry->size * 4);
if (!tmp)
return -1;
glyphEntry->pixels = tmp;
}
if (!glyphEntry->pixels)
@ -841,27 +844,31 @@ CLEAR_CONTEXT* clear_context_new(BOOL Compressor)
clear = (CLEAR_CONTEXT*) calloc(1, sizeof(CLEAR_CONTEXT));
if (clear)
{
clear->Compressor = Compressor;
if (!clear)
return NULL;
clear->nsc = nsc_context_new();
clear->Compressor = Compressor;
if (!clear->nsc)
{
free (clear);
return NULL;
}
clear->nsc = nsc_context_new();
if (!clear->nsc)
goto error_nsc;
nsc_context_set_pixel_format(clear->nsc, RDP_PIXEL_FORMAT_R8G8B8);
nsc_context_set_pixel_format(clear->nsc, RDP_PIXEL_FORMAT_R8G8B8);
clear->TempSize = 512 * 512 * 4;
clear->TempBuffer = (BYTE*) malloc(clear->TempSize);
clear->TempSize = 512 * 512 * 4;
clear->TempBuffer = (BYTE*) malloc(clear->TempSize);
if (!clear->TempBuffer)
goto error_temp_buffer;
clear_context_reset(clear);
}
clear_context_reset(clear);
return clear;
error_temp_buffer:
nsc_context_free(clear->nsc);
error_nsc:
free(clear);
return NULL;
}
void clear_context_free(CLEAR_CONTEXT* clear)

View File

@ -679,7 +679,7 @@ int h264_decompress(H264_CONTEXT* h264, BYTE* pSrcData, UINT32 SrcSize,
int h264_compress(H264_CONTEXT* h264, BYTE* pSrcData, DWORD SrcFormat,
int nSrcStep, int nSrcWidth, int nSrcHeight, BYTE** ppDstData, UINT32* pDstSize)
{
int status;
int status = -1;
prim_size_t roi;
int nWidth, nHeight;
primitives_t *prims = primitives_get();
@ -691,12 +691,19 @@ int h264_compress(H264_CONTEXT* h264, BYTE* pSrcData, DWORD SrcFormat,
nWidth = (nSrcWidth + 1) & ~1;
nHeight = (nSrcHeight + 1) & ~1;
h264->pYUVData[0] = (BYTE*) malloc(nWidth * nHeight);
if (!(h264->pYUVData[0] = (BYTE*) malloc(nWidth * nHeight)))
return -1;
h264->iStride[0] = nWidth;
h264->pYUVData[1] = (BYTE*) malloc(nWidth * nHeight / 4);
if (!(h264->pYUVData[1] = (BYTE*) malloc(nWidth * nHeight / 4)))
goto error_1;
h264->iStride[1] = nWidth / 2;
h264->pYUVData[2] = (BYTE*) malloc(nWidth * nHeight / 4);
if (!(h264->pYUVData[2] = (BYTE*) malloc(nWidth * nHeight / 4)))
goto error_2;
h264->iStride[2] = nWidth / 2;
h264->width = nWidth;
h264->height = nHeight;
roi.width = nSrcWidth;
@ -706,12 +713,14 @@ int h264_compress(H264_CONTEXT* h264, BYTE* pSrcData, DWORD SrcFormat,
status = h264->subsystem->Compress(h264, ppDstData, pDstSize);
free(h264->pYUVData[0]);
free(h264->pYUVData[1]);
free(h264->pYUVData[2]);
h264->pYUVData[0] = NULL;
h264->pYUVData[1] = NULL;
h264->pYUVData[2] = NULL;
error_2:
free(h264->pYUVData[1]);
h264->pYUVData[1] = NULL;
error_1:
free(h264->pYUVData[0]);
h264->pYUVData[0] = NULL;
return status;
}

View File

@ -873,6 +873,8 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int hei
{
outBufferSize = width * height;
outPlane = malloc(outBufferSize);
if (!outPlane)
return NULL;
}
else
{
@ -968,7 +970,10 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int hei
BYTE *outPtr, *srcPtr, *prevLinePtr;
if (!outPlane)
outPlane = (BYTE*) malloc(width * height);
{
if (!(outPlane = (BYTE*) malloc(width * height)))
return NULL;
}
// first line is copied as is
CopyMemory(outPlane, inPlane, width);
@ -994,14 +999,18 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(BYTE* inPlane, int width, int hei
return outPlane;
}
int freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4])
BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], int width, int height, BYTE* outPlanes[4])
{
outPlanes[0] = freerdp_bitmap_planar_delta_encode_plane(inPlanes[0], width, height, outPlanes[0]);
outPlanes[1] = freerdp_bitmap_planar_delta_encode_plane(inPlanes[1], width, height, outPlanes[1]);
outPlanes[2] = freerdp_bitmap_planar_delta_encode_plane(inPlanes[2], width, height, outPlanes[2]);
outPlanes[3] = freerdp_bitmap_planar_delta_encode_plane(inPlanes[3], width, height, outPlanes[3]);
int i;
return 0;
for (i = 0; i < 4; i++)
{
outPlanes[i] = freerdp_bitmap_planar_delta_encode_plane(inPlanes[i], width, height, outPlanes[i]);
if (!outPlanes[i])
return FALSE;
}
return TRUE;
}
BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, UINT32 format,
@ -1025,7 +1034,8 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data,
if (context->AllowRunLengthEncoding)
{
freerdp_bitmap_planar_delta_encode_planes(context->planes, width, height, context->deltaPlanes);
if (!freerdp_bitmap_planar_delta_encode_planes(context->planes, width, height, context->deltaPlanes))
return NULL;;
if (freerdp_bitmap_planar_compress_planes_rle(context->deltaPlanes, width, height,
context->rlePlanesBuffer, (int*) &dstSizes, context->AllowSkipAlpha) > 0)
@ -1071,6 +1081,8 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data,
size++;
dstData = malloc(size);
if (!dstData)
return NULL;
*pDstSize = size;
}
@ -1157,13 +1169,10 @@ BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWid
{
BITMAP_PLANAR_CONTEXT* context;
context = (BITMAP_PLANAR_CONTEXT*) malloc(sizeof(BITMAP_PLANAR_CONTEXT));
context = (BITMAP_PLANAR_CONTEXT*) calloc(1, sizeof(BITMAP_PLANAR_CONTEXT));
if (!context)
return NULL;
ZeroMemory(context, sizeof(BITMAP_PLANAR_CONTEXT));
if (flags & PLANAR_FORMAT_HEADER_NA)
context->AllowSkipAlpha = TRUE;
@ -1183,20 +1192,34 @@ BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWid
context->maxPlaneSize = context->maxWidth * context->maxHeight;
context->planesBuffer = malloc(context->maxPlaneSize * 4);
if (!context->planesBuffer)
goto error_planesBuffer;
context->planes[0] = &context->planesBuffer[context->maxPlaneSize * 0];
context->planes[1] = &context->planesBuffer[context->maxPlaneSize * 1];
context->planes[2] = &context->planesBuffer[context->maxPlaneSize * 2];
context->planes[3] = &context->planesBuffer[context->maxPlaneSize * 3];
context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4);
if (!context->deltaPlanesBuffer)
goto error_deltaPlanesBuffer;
context->deltaPlanes[0] = &context->deltaPlanesBuffer[context->maxPlaneSize * 0];
context->deltaPlanes[1] = &context->deltaPlanesBuffer[context->maxPlaneSize * 1];
context->deltaPlanes[2] = &context->deltaPlanesBuffer[context->maxPlaneSize * 2];
context->deltaPlanes[3] = &context->deltaPlanesBuffer[context->maxPlaneSize * 3];
context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4);
if (!context->rlePlanesBuffer)
goto error_rlePlanesBuffer;
return context;
error_rlePlanesBuffer:
free(context->deltaPlanesBuffer);
error_deltaPlanesBuffer:
free(context->planesBuffer);
error_planesBuffer:
free(context);
return NULL;
}
void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context)

View File

@ -2960,9 +2960,14 @@ int test_individual_planes_encoding_rle()
CopyMemory(planar->planes[1], (BYTE*) TEST_64X64_RED_PLANE, planeSize); /* Red */
CopyMemory(planar->planes[2], (BYTE*) TEST_64X64_GREEN_PLANE, planeSize); /* Green */
CopyMemory(planar->planes[3], (BYTE*) TEST_64X64_BLUE_PLANE, planeSize); /* Blue */
freerdp_bitmap_planar_delta_encode_plane(planar->planes[1], width, height, planar->deltaPlanes[1]); /* Red */
freerdp_bitmap_planar_delta_encode_plane(planar->planes[2], width, height, planar->deltaPlanes[2]); /* Green */
freerdp_bitmap_planar_delta_encode_plane(planar->planes[3], width, height, planar->deltaPlanes[3]); /* Blue */
if (!freerdp_bitmap_planar_delta_encode_plane(planar->planes[1], width, height, planar->deltaPlanes[1]) || /* Red */
!freerdp_bitmap_planar_delta_encode_plane(planar->planes[2], width, height, planar->deltaPlanes[2]) || /* Green */
!freerdp_bitmap_planar_delta_encode_plane(planar->planes[3], width, height, planar->deltaPlanes[3])) /* Blue */
{
return -1;
}
pOutput = planar->rlePlanesBuffer;
availableSize = planeSize * 3;
/* Red */
@ -3101,11 +3106,15 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
width = i;
height = i;
whiteBitmap = (BYTE*) malloc(width * height * 4);
if (!whiteBitmap)
return -1;
FillMemory(whiteBitmap, width * height * 4, 0xFF);
fill_bitmap_alpha_channel(whiteBitmap, width, height, 0x00);
compressedBitmap = freerdp_bitmap_compress_planar(planar, whiteBitmap, format, width, height, width * 4, NULL, &dstSize);
decompressedBitmap = (BYTE*) malloc(width * height * 4);
ZeroMemory(decompressedBitmap, width * height * 4);
decompressedBitmap = (BYTE*) calloc(width * height, 4);
if (!decompressedBitmap)
return -1;
pDstData = decompressedBitmap;
@ -3138,12 +3147,14 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
{
width = i;
height = i;
blackBitmap = (BYTE*) malloc(width * height * 4);
ZeroMemory(blackBitmap, width * height * 4);
blackBitmap = (BYTE*) calloc(width * height, 4);
if (!blackBitmap)
return -1;
fill_bitmap_alpha_channel(blackBitmap, width, height, 0x00);
compressedBitmap = freerdp_bitmap_compress_planar(planar, blackBitmap, format, width, height, width * 4, NULL, &dstSize);
decompressedBitmap = (BYTE*) malloc(width * height * 4);
ZeroMemory(decompressedBitmap, width * height * 4);
decompressedBitmap = (BYTE*) calloc(width * height, 4);
if (!decompressedBitmap)
return -1;
pDstData = decompressedBitmap;
@ -3179,8 +3190,9 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
height = 64;
compressedBitmap = freerdp_bitmap_compress_planar(planar, (BYTE*) TEST_RLE_BITMAP_EXPERIMENTAL_01,
format, width, height, width * 4, NULL, &dstSize);
decompressedBitmap = (BYTE*) malloc(width * height * 4);
ZeroMemory(decompressedBitmap, width * height * 4);
decompressedBitmap = (BYTE*) calloc(width * height, 4);
if (!decompressedBitmap)
return -1;
pDstData = decompressedBitmap;
@ -3217,8 +3229,9 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
height = 64;
compressedBitmap = freerdp_bitmap_compress_planar(planar, (BYTE*) TEST_RLE_BITMAP_EXPERIMENTAL_02,
format, width, height, width * 4, NULL, &dstSize);
decompressedBitmap = (BYTE*) malloc(width * height * 4);
ZeroMemory(decompressedBitmap, width * height * 4);
decompressedBitmap = (BYTE*) calloc(width * height, 4);
if (!decompressedBitmap)
return -1;
pDstData = decompressedBitmap;
@ -3262,8 +3275,9 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
height = 64;
compressedBitmap = freerdp_bitmap_compress_planar(planar, (BYTE*) TEST_RLE_BITMAP_EXPERIMENTAL_03,
format, width, height, width * 4, NULL, &dstSize);
decompressedBitmap = (BYTE*) malloc(width * height * 4);
ZeroMemory(decompressedBitmap, width * height * 4);
decompressedBitmap = (BYTE*) calloc(width * height, 4);
if (!decompressedBitmap)
return -1;
pDstData = decompressedBitmap;

View File

@ -1010,6 +1010,11 @@ int TestFreeRDPCodecProgressive(int argc, char* argv[])
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);

View File

@ -337,6 +337,8 @@ int zgfx_decompress(ZGFX_CONTEXT* zgfx, BYTE* pSrcData, UINT32 SrcSize, BYTE** p
status = zgfx_decompress_segment(zgfx, &pSrcData[1], SrcSize - 1);
*ppDstData = (BYTE*) malloc(zgfx->OutputCount);
if (!*ppDstData)
return -1;
*pDstSize = zgfx->OutputCount;
CopyMemory(*ppDstData, zgfx->OutputBuffer, zgfx->OutputCount);
@ -355,6 +357,8 @@ int zgfx_decompress(ZGFX_CONTEXT* zgfx, BYTE* pSrcData, UINT32 SrcSize, BYTE** p
uncompressedSize = *((UINT32*) &pSrcData[3]); /* uncompressedSize (4 bytes) */
pConcatenated = (BYTE*) malloc(uncompressedSize);
if (!pConcatenated)
return -1;
*ppDstData = pConcatenated;
*pDstSize = uncompressedSize;

View File

@ -46,11 +46,17 @@ LPSTR freerdp_get_library_install_path()
cchPath = cchInstallPrefix + cchLibraryPath + 2;
pszPath = (LPSTR) malloc(cchPath + 1);
if (!pszPath)
return NULL;
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
pszPath[cchInstallPrefix] = '\0';
NativePathCchAppendA(pszPath, cchPath + 1, pszLibraryPath);
if (FAILED(NativePathCchAppendA(pszPath, cchPath + 1, pszLibraryPath)))
{
free(pszPath);
return NULL;
}
return pszPath;
}
@ -69,11 +75,17 @@ LPSTR freerdp_get_dynamic_addin_install_path()
cchPath = cchInstallPrefix + cchAddinPath + 2;
pszPath = (LPSTR) malloc(cchPath + 1);
if (!pszPath)
return NULL;
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
pszPath[cchInstallPrefix] = '\0';
NativePathCchAppendA(pszPath, cchPath + 1, pszAddinPath);
if (FAILED(NativePathCchAppendA(pszPath, cchPath + 1, pszAddinPath)))
{
free(pszPath);
return NULL;
}
return pszPath;
}
@ -98,7 +110,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE
bHasExt = TRUE;
cchFileName = strlen(pszFileName);
if (PathCchFindExtensionA(pszFileName, cchFileName + 1, &pszExt) != S_OK)
if (FAILED(PathCchFindExtensionA(pszFileName, cchFileName + 1, &pszExt)))
{
pszExt = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
cchExt = strlen(pszExt);
@ -106,20 +118,39 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE
}
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);
}
@ -161,6 +192,8 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste
{
cchFileName += strlen(pszName) + strlen(pszSubsystem) + strlen(pszType) + strlen(pszExtension);
pszFileName = (LPSTR) malloc(cchFileName);
if (!pszFileName)
return NULL;
sprintf_s(pszFileName, cchFileName, "%s%s-client-%s-%s.%s", pszPrefix, pszName, pszSubsystem, pszType, pszExtension);
cchFileName = strlen(pszFileName);
}
@ -168,6 +201,9 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste
{
cchFileName += strlen(pszName) + strlen(pszSubsystem) + strlen(pszExtension);
pszFileName = (LPSTR) malloc(cchFileName);
if (!pszFileName)
return NULL;
sprintf_s(pszFileName, cchFileName, "%s%s-client-%s.%s", pszPrefix, pszName, pszSubsystem, pszExtension);
cchFileName = strlen(pszFileName);
}
@ -175,6 +211,9 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste
{
cchFileName += strlen(pszName) + strlen(pszExtension);
pszFileName = (LPSTR) malloc(cchFileName);
if (!pszFileName)
return NULL;
sprintf_s(pszFileName, cchFileName, "%s%s-client.%s", pszPrefix, pszName, pszExtension);
cchFileName = strlen(pszFileName);
}
@ -192,6 +231,11 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste
cchEntryName = 64 + strlen(pszName);
pszEntryName = (LPSTR) malloc(cchEntryName + 1);
if (!pszEntryName)
{
free(pszFileName);
return NULL;
}
sprintf_s(pszEntryName, cchEntryName + 1, "freerdp_%s_client_subsystem_entry", pszName);
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszEntryName);
@ -199,29 +243,22 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste
free(pszEntryName);
free(pszFileName);
if (entry)
return entry;
return entry;
}
/* channel add-in */
if (dwFlags & FREERDP_ADDIN_CHANNEL_STATIC)
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "VirtualChannelEntry");
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DYNAMIC)
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DVCPluginEntry");
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DEVICE)
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DeviceServiceEntry");
else
{
/* channel add-in */
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszType);
if (dwFlags & FREERDP_ADDIN_CHANNEL_STATIC)
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "VirtualChannelEntry");
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DYNAMIC)
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DVCPluginEntry");
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DEVICE)
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DeviceServiceEntry");
else
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszType);
free(pszFileName);
if (entry)
return entry;
}
return NULL;
free(pszFileName);
return entry;
}
static FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN freerdp_load_static_channel_addin_entry = NULL;

View File

@ -124,6 +124,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
int count;
int length;
char** tokens;
int ret = -1;
count = 1;
str = _strdup(list);
@ -140,9 +141,11 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
}
tokens = (char**) malloc(sizeof(char*) * count);
if (!tokens)
{
free(str);
return -1;
}
count = 0;
tokens[count++] = str;
@ -161,12 +164,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
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++)
{
@ -177,10 +175,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
q = strchr(p, ':');
if (!q)
{
free(tokens);
return -1;
}
goto out;
q[0] = '\0';
q++;
@ -209,26 +204,29 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
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)
@ -238,6 +236,7 @@ int freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
int count;
int length;
char* tokens[8];
int ret;
/**
* <ProtocolVersion>,<protocolType>,<machineAddressList>,<assistantAccountPwd>,
@ -298,10 +297,13 @@ int freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
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;
}
@ -323,96 +325,92 @@ int freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
{
char* p;
char* q;
int port;
char* str;
size_t length;
char* tag;
char* end;
char* p;
int ret = -1;
str = file->ConnectionString2;
if (!strstr(str, "<E>"))
return -1;
if (!strstr(str, "<C>"))
return -1;
str = _strdup(file->ConnectionString2);
if (!str)
return -1;
p = strstr(str, "<E>");
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(str, "<C>");
if (!p)
return -1;
/* Auth String Node (<A>) */
p = strstr(str, "<A");
if (!p)
return -1;
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++;
@ -422,14 +420,14 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
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++;
@ -440,7 +438,11 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
{
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;
}
@ -449,9 +451,11 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
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)
@ -748,7 +752,7 @@ int freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
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)
@ -825,6 +829,8 @@ char* freerdp_assistance_bin_to_hex_string(const BYTE* data, int size)
char bin2hex[] = "0123456789ABCDEF";
p = (char*) malloc((size + 1) * 2);
if (!p)
return NULL;
for (i = 0; i < size; i++)
{
@ -1129,21 +1135,21 @@ int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* fil
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 (file->RCTicket)
freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceRCTicket, file->RCTicket);
if (file->PassStub)
freerdp_set_param_string(settings, FreeRDP_RemoteAssistancePassStub, file->PassStub);
if (!file->MachineAddress)
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) != 0))
return -1;
if (file->PassStub && (freerdp_set_param_string(settings, FreeRDP_RemoteAssistancePassStub, file->PassStub) != 0))
return -1;
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);
@ -1173,16 +1179,7 @@ int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* fil
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)

View File

@ -51,7 +51,8 @@ int freerdp_addin_set_argument(ADDIN_ARGV* args, char* argument)
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;
}
@ -66,7 +67,8 @@ int freerdp_addin_replace_argument(ADDIN_ARGV* args, char* previous, char* argum
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;
}
@ -77,7 +79,8 @@ int freerdp_addin_replace_argument(ADDIN_ARGV* args, char* previous, char* argum
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;
}
@ -92,6 +95,8 @@ int freerdp_addin_set_argument_value(ADDIN_ARGV* args, char* option, char* value
length = strlen(option) + strlen(value) + 1;
str = (char*) malloc(length + 1);
if (!str)
return -1;
sprintf_s(str, length + 1, "%s:%s", option, value);
for (i = 0; i < args->argc; i++)
@ -129,6 +134,8 @@ int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char*
length = strlen(option) + strlen(value) + 1;
str = (char*) malloc(length + 1);
if (!str)
return -1;
sprintf_s(str, length + 1, "%s:%s", option, value);
for (i = 0; i < args->argc; i++)
@ -152,10 +159,10 @@ int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char*
return 0;
}
void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
{
if (!settings->DeviceArray)
return;
return FALSE;
if (settings->DeviceArraySize < (settings->DeviceCount + 1))
{
@ -166,12 +173,13 @@ void freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
new_array = (RDPDR_DEVICE**)
realloc(settings->DeviceArray, new_size * sizeof(RDPDR_DEVICE*));
if (!new_array)
return;
return FALSE;
settings->DeviceArray = new_array;
settings->DeviceArraySize = new_size;
}
settings->DeviceArray[settings->DeviceCount++] = device;
return TRUE;
}
RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name)
@ -381,6 +389,9 @@ void freerdp_device_collection_free(rdpSettings* settings)
{
device = (RDPDR_DEVICE*) settings->DeviceArray[index];
if (!device)
continue;
free(device->Name);
if (settings->DeviceArray[index]->Type == RDPDR_DTYP_FILESYSTEM)
@ -415,10 +426,10 @@ void freerdp_device_collection_free(rdpSettings* settings)
settings->DeviceCount = 0;
}
void freerdp_static_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel)
BOOL freerdp_static_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel)
{
if (!settings->StaticChannelArray)
return;
return FALSE;
if (settings->StaticChannelArraySize < (settings->StaticChannelCount + 1))
{
@ -429,12 +440,13 @@ void freerdp_static_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* ch
new_array = (ADDIN_ARGV**)
realloc(settings->StaticChannelArray, new_size * sizeof(ADDIN_ARGV*));
if (!new_array)
return;
return FALSE;
settings->StaticChannelArray = new_array;
settings->StaticChannelArraySize = new_size;
}
settings->StaticChannelArray[settings->StaticChannelCount++] = channel;
return TRUE;
}
ADDIN_ARGV* freerdp_static_channel_collection_find(rdpSettings* settings, const char* name)
@ -491,6 +503,9 @@ void freerdp_static_channel_collection_free(rdpSettings* settings)
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]);
@ -505,30 +520,25 @@ void freerdp_static_channel_collection_free(rdpSettings* settings)
settings->StaticChannelCount = 0;
}
void freerdp_dynamic_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel)
BOOL freerdp_dynamic_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel)
{
if (!settings->DynamicChannelArray)
return;
return FALSE;
if (settings->DynamicChannelArraySize < (settings->DynamicChannelCount + 1))
{
UINT32 new_size;
ADDIN_ARGV **new_array;
settings->DynamicChannelArraySize *= 2;
settings->DynamicChannelArray = (ADDIN_ARGV**)
realloc(settings->DynamicChannelArray, settings->DynamicChannelArraySize * sizeof(ADDIN_ARGV*));
new_size = settings->DynamicChannelArraySize * 2;
new_array = (ADDIN_ARGV**)
realloc(settings->DynamicChannelArray, new_size * sizeof(ADDIN_ARGV*));
new_array = realloc(settings->DynamicChannelArray, settings->DynamicChannelArraySize * sizeof(ADDIN_ARGV*) * 2);
if (!new_array)
return;
return FALSE;
settings->DynamicChannelArraySize *= 2;
settings->DynamicChannelArray = new_array;
settings->DynamicChannelArraySize = new_size;
}
settings->DynamicChannelArray[settings->DynamicChannelCount++] = channel;
return TRUE;
}
ADDIN_ARGV* freerdp_dynamic_channel_collection_find(rdpSettings* settings, const char* name)
@ -588,6 +598,9 @@ void freerdp_dynamic_channel_collection_free(rdpSettings* settings)
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]);
@ -2432,231 +2445,191 @@ char* freerdp_get_param_string(rdpSettings* settings, int id)
int freerdp_set_param_string(rdpSettings* settings, int id, const char* param)
{
char **tmp = NULL;
if (!param)
return -1;
switch (id)
{
case FreeRDP_ServerHostname:
free(settings->ServerHostname);
settings->ServerHostname = _strdup(param);
tmp = &settings->ServerHostname;
break;
case FreeRDP_Username:
free(settings->Username);
settings->Username = _strdup(param);
tmp = &settings->Username;
break;
case FreeRDP_Password:
free(settings->Password);
settings->Password = _strdup(param);
tmp = &settings->Password;
break;
case FreeRDP_Domain:
free(settings->Domain);
settings->Domain = _strdup(param);
tmp = &settings->Domain;
break;
case FreeRDP_PasswordHash:
free(settings->PasswordHash);
settings->PasswordHash = _strdup(param);
tmp = &settings->PasswordHash;
break;
case FreeRDP_ClientHostname:
free(settings->ClientHostname);
settings->ClientHostname = _strdup(param);
tmp = &settings->ClientHostname;
break;
case FreeRDP_ClientProductId:
free(settings->ClientProductId);
settings->ClientProductId = _strdup(param);
tmp = &settings->ClientProductId;
break;
case FreeRDP_AlternateShell:
free(settings->AlternateShell);
settings->AlternateShell = _strdup(param);
tmp = &settings->AlternateShell;
break;
case FreeRDP_ShellWorkingDirectory:
free(settings->ShellWorkingDirectory);
settings->ShellWorkingDirectory = _strdup(param);
tmp = &settings->ShellWorkingDirectory;
break;
case FreeRDP_ClientAddress:
free(settings->ClientAddress);
settings->ClientAddress = _strdup(param);
tmp = &settings->ClientAddress;
break;
case FreeRDP_ClientDir:
free(settings->ClientDir);
settings->ClientDir = _strdup(param);
tmp = &settings->ClientDir;
break;
case FreeRDP_DynamicDSTTimeZoneKeyName:
free(settings->DynamicDSTTimeZoneKeyName);
settings->DynamicDSTTimeZoneKeyName = _strdup(param);
tmp = &settings->DynamicDSTTimeZoneKeyName;
break;
case FreeRDP_RemoteAssistanceSessionId:
free(settings->RemoteAssistanceSessionId);
settings->RemoteAssistanceSessionId = _strdup(param);
tmp = &settings->RemoteAssistanceSessionId;
break;
case FreeRDP_RemoteAssistancePassStub:
free(settings->RemoteAssistancePassStub);
settings->RemoteAssistancePassStub = _strdup(param);
tmp = &settings->RemoteAssistancePassStub;
break;
case FreeRDP_RemoteAssistancePassword:
free(settings->RemoteAssistancePassword);
settings->RemoteAssistancePassword = _strdup(param);
tmp = &settings->RemoteAssistancePassword;
break;
case FreeRDP_RemoteAssistanceRCTicket:
free(settings->RemoteAssistanceRCTicket);
settings->RemoteAssistanceRCTicket = _strdup(param);
tmp = &settings->RemoteAssistanceRCTicket;
break;
case FreeRDP_AuthenticationServiceClass:
free(settings->AuthenticationServiceClass);
settings->AuthenticationServiceClass = _strdup(param);
tmp = &settings->AuthenticationServiceClass;
break;
case FreeRDP_PreconnectionBlob:
free(settings->PreconnectionBlob);
settings->PreconnectionBlob = _strdup(param);
tmp = &settings->PreconnectionBlob;
break;
case FreeRDP_KerberosKdc:
free(settings->KerberosKdc);
settings->KerberosKdc = _strdup(param);
tmp = &settings->KerberosKdc;
break;
case FreeRDP_KerberosRealm:
free(settings->KerberosRealm);
settings->KerberosRealm = _strdup(param);
tmp = &settings->KerberosRealm;
break;
case FreeRDP_CertificateName:
free(settings->CertificateName);
settings->CertificateName = _strdup(param);
tmp = &settings->CertificateName;
break;
case FreeRDP_CertificateFile:
free(settings->CertificateFile);
settings->CertificateFile = _strdup(param);
tmp = &settings->CertificateFile;
break;
case FreeRDP_PrivateKeyFile:
free(settings->PrivateKeyFile);
settings->PrivateKeyFile = _strdup(param);
tmp = &settings->PrivateKeyFile;
break;
case FreeRDP_RdpKeyFile:
free(settings->RdpKeyFile);
settings->RdpKeyFile = _strdup(param);
tmp = &settings->RdpKeyFile;
break;
case FreeRDP_WindowTitle:
free(settings->WindowTitle);
settings->WindowTitle = _strdup(param);
tmp = &settings->WindowTitle;
break;
case FreeRDP_ComputerName:
free(settings->ComputerName);
settings->ComputerName = _strdup(param);
tmp = &settings->ComputerName;
break;
case FreeRDP_ConnectionFile:
free(settings->ConnectionFile);
settings->ConnectionFile = _strdup(param);
tmp = &settings->ConnectionFile;
break;
case FreeRDP_AssistanceFile:
free(settings->AssistanceFile);
settings->AssistanceFile = _strdup(param);
tmp = &settings->AssistanceFile;
break;
case FreeRDP_HomePath:
free(settings->HomePath);
settings->HomePath = _strdup(param);
tmp = &settings->HomePath;
break;
case FreeRDP_ConfigPath:
free(settings->ConfigPath);
settings->ConfigPath = _strdup(param);
tmp = &settings->ConfigPath;
break;
case FreeRDP_CurrentPath:
free(settings->CurrentPath);
settings->CurrentPath = _strdup(param);
tmp = &settings->CurrentPath;
break;
case FreeRDP_DumpRemoteFxFile:
free(settings->DumpRemoteFxFile);
settings->DumpRemoteFxFile = _strdup(param);
tmp = &settings->DumpRemoteFxFile;
break;
case FreeRDP_PlayRemoteFxFile:
free(settings->PlayRemoteFxFile);
settings->PlayRemoteFxFile = _strdup(param);
tmp = &settings->PlayRemoteFxFile;
break;
case FreeRDP_GatewayHostname:
free(settings->GatewayHostname);
settings->GatewayHostname = _strdup(param);
tmp = &settings->GatewayHostname;
break;
case FreeRDP_GatewayUsername:
free(settings->GatewayUsername);
settings->GatewayUsername = _strdup(param);
tmp = &settings->GatewayUsername;
break;
case FreeRDP_GatewayPassword:
free(settings->GatewayPassword);
settings->GatewayPassword = _strdup(param);
tmp = &settings->GatewayPassword;
break;
case FreeRDP_GatewayDomain:
free(settings->GatewayDomain);
settings->GatewayDomain = _strdup(param);
tmp = &settings->GatewayDomain;
break;
case FreeRDP_RemoteApplicationName:
free(settings->RemoteApplicationName);
settings->RemoteApplicationName = _strdup(param);
tmp = &settings->RemoteApplicationName;
break;
case FreeRDP_RemoteApplicationIcon:
free(settings->RemoteApplicationIcon);
settings->RemoteApplicationIcon = _strdup(param);
tmp = &settings->RemoteApplicationIcon;
break;
case FreeRDP_RemoteApplicationProgram:
free(settings->RemoteApplicationProgram);
settings->RemoteApplicationProgram = _strdup(param);
tmp = &settings->RemoteApplicationProgram;
break;
case FreeRDP_RemoteApplicationFile:
free(settings->RemoteApplicationFile);
settings->RemoteApplicationFile = _strdup(param);
tmp = &settings->RemoteApplicationFile;
break;
case FreeRDP_RemoteApplicationGuid:
free(settings->RemoteApplicationGuid);
settings->RemoteApplicationGuid = _strdup(param);
tmp = &settings->RemoteApplicationGuid;
break;
case FreeRDP_RemoteApplicationCmdLine:
free(settings->RemoteApplicationCmdLine);
settings->RemoteApplicationCmdLine = _strdup(param);
tmp = &settings->RemoteApplicationCmdLine;
break;
case FreeRDP_ImeFileName:
free(settings->ImeFileName);
settings->ImeFileName = _strdup(param);
tmp = &settings->ImeFileName;
break;
case FreeRDP_DrivesToRedirect:
free(settings->DrivesToRedirect);
settings->DrivesToRedirect = _strdup(param);
tmp = &settings->DrivesToRedirect;
break;
default:
@ -2664,6 +2637,10 @@ int freerdp_set_param_string(rdpSettings* settings, int id, const char* param)
return -1;
}
free(*tmp);
if (!(*tmp = _strdup(param)))
return -1;
/* Mark field as modified */
settings->SettingsModified[id] = 1;

View File

@ -85,6 +85,9 @@ int test_msrsc_incident_file_type1()
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));
@ -136,6 +139,9 @@ int test_msrsc_incident_file_type2()
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));
@ -174,9 +180,17 @@ int test_msrsc_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;
}

View File

@ -791,6 +791,8 @@ rdpCertificate* certificate_clone(rdpCertificate* certificate)
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;
}
@ -798,11 +800,15 @@ rdpCertificate* certificate_clone(rdpCertificate* certificate)
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++)
{
@ -811,6 +817,15 @@ rdpCertificate* certificate_clone(rdpCertificate* certificate)
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);
}
@ -819,6 +834,16 @@ rdpCertificate* certificate_clone(rdpCertificate* certificate)
}
return _certificate;
out_fail:
if (_certificate->x509_cert_chain)
{
free(_certificate->x509_cert_chain->array);
free(_certificate->x509_cert_chain);
}
free(_certificate->cert_info.Modulus);
free(_certificate);
return NULL;
}
/**

View File

@ -237,6 +237,8 @@ int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance)
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle, CHANNEL_EVENT_CONNECTED, hostname, hostnameLength);
name = (char*) malloc(9);
if (!name)
return -1;
CopyMemory(name, pChannelOpenData->name, 8);
name[8] = '\0';
@ -449,6 +451,8 @@ int freerdp_channels_disconnect(rdpChannels* channels, freerdp* instance)
pChannelOpenData = &channels->openDataList[index];
name = (char*) malloc(9);
if (!name)
return -1;
CopyMemory(name, pChannelOpenData->name, 8);
name[8] = '\0';

View File

@ -334,11 +334,13 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
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
{
@ -346,16 +348,22 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
{
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;
}
}
@ -363,12 +371,16 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
{
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);
@ -388,7 +400,7 @@ BOOL rdp_client_reconnect(rdpRdp* rdp)
status = rdp_client_connect(rdp);
if (status)
freerdp_channels_post_connect(channels, context->instance);
status = (freerdp_channels_post_connect(channels, context->instance) >= 0);
return status;
}
@ -826,7 +838,11 @@ int rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s)
if (!rdp_send_confirm_active(rdp))
return -1;
input_register_client_callbacks(rdp->input);
if (!input_register_client_callbacks(rdp->input))
{
WLog_ERR(TAG, "error registering client callbacks");
return -1;
}
/**
* The server may request a different desktop size during Deactivation-Reactivation sequence.

View File

@ -138,9 +138,24 @@ int rpc_ncacn_http_ntlm_init(rdpRpc* rpc, RpcChannel* channel)
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;
}
}
}
}

View File

@ -780,9 +780,24 @@ BOOL rdg_ncacn_http_ntlm_init(rdpRdg* rdg, rdpTls* tls)
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;
}
}
}
}

View File

@ -1590,11 +1590,12 @@ BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
Stream_Read_UINT32(s, flags); /* flags */
Stream_Read_UINT32(s, monitorCount); /* monitorCount */
if (blockLength < (8 + (monitorCount * 20)))
if (((blockLength - 8) / 20) < monitorCount)
return FALSE;
monitorDefArray = (MONITOR_DEF*) malloc(sizeof(MONITOR_DEF) * monitorCount);
ZeroMemory(monitorDefArray, sizeof(MONITOR_DEF) * monitorCount);
monitorDefArray = (MONITOR_DEF*) calloc(monitorCount, sizeof(MONITOR_DEF));
if (!monitorDefArray)
return FALSE;
for (index = 0; index < monitorCount; index++)
{
@ -1657,7 +1658,7 @@ BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpMcs* mcs, UINT16 block
UINT32 monitorAttributeSize;
MONITOR_ATTRIBUTES* monitorAttributesArray;
if (blockLength < 8)
if (blockLength < 12)
return FALSE;
Stream_Read_UINT32(s, flags); /* flags */
@ -1667,11 +1668,12 @@ BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpMcs* mcs, UINT16 block
if (monitorAttributeSize != 20)
return FALSE;
if (blockLength < (12 + (monitorCount * monitorAttributeSize)))
if ((blockLength - 12) / monitorAttributeSize < monitorCount)
return FALSE;
monitorAttributesArray = (MONITOR_ATTRIBUTES*) malloc(sizeof(MONITOR_ATTRIBUTES) * monitorCount);
ZeroMemory(monitorAttributesArray, sizeof(MONITOR_ATTRIBUTES) * monitorCount);
monitorAttributesArray = (MONITOR_ATTRIBUTES*) calloc(monitorCount, sizeof(MONITOR_ATTRIBUTES));
if (!monitorAttributesArray)
return FALSE;
for (index = 0; index < monitorCount; index++)
{

View File

@ -498,7 +498,7 @@ BOOL input_recv(rdpInput* input, wStream* s)
return TRUE;
}
void input_register_client_callbacks(rdpInput* input)
BOOL input_register_client_callbacks(rdpInput* input)
{
rdpSettings* settings = input->context->settings;
@ -528,7 +528,10 @@ void input_register_client_callbacks(rdpInput* input)
if (input->asynchronous)
{
input->proxy = input_message_proxy_new(input);
if (!input->proxy)
return FALSE;
}
return TRUE;
}
BOOL freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags)

View File

@ -53,7 +53,7 @@ BOOL input_send_fastpath_extended_mouse_event(rdpInput* input, UINT16 flags, UIN
BOOL input_recv(rdpInput* input, wStream* s);
int input_process_events(rdpInput* input);
void input_register_client_callbacks(rdpInput* input);
BOOL input_register_client_callbacks(rdpInput* input);
rdpInput* input_new(rdpRdp* rdp);
void input_free(rdpInput* input);

View File

@ -423,6 +423,8 @@ BOOL license_get_server_rsa_public_key(rdpLicense* license)
CopyMemory(license->Exponent, Exponent, 4);
license->ModulusLength = ModulusLength;
license->Modulus = (BYTE*) malloc(ModulusLength);
if (!license->Modulus)
return FALSE;
CopyMemory(license->Modulus, Modulus, ModulusLength);
return TRUE;
}
@ -501,19 +503,24 @@ BOOL license_read_product_info(wStream* s, LICENSE_PRODUCT_INFO* productInfo)
return FALSE;
productInfo->pbCompanyName = (BYTE*) malloc(productInfo->cbCompanyName);
if (!productInfo->pbCompanyName)
return FALSE;
Stream_Read(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
Stream_Read_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
if (Stream_GetRemainingLength(s) < productInfo->cbProductId)
{
free(productInfo->pbCompanyName);
productInfo->pbCompanyName = NULL;
return FALSE;
}
goto out_fail;
productInfo->pbProductId = (BYTE*) malloc(productInfo->cbProductId);
if (!productInfo->pbProductId)
goto out_fail;
Stream_Read(s, productInfo->pbProductId, productInfo->cbProductId);
return TRUE;
out_fail:
free(productInfo->pbCompanyName);
productInfo->pbCompanyName = NULL;
return FALSE;
}
/**
@ -526,6 +533,8 @@ LICENSE_PRODUCT_INFO* license_new_product_info()
{
LICENSE_PRODUCT_INFO* productInfo;
productInfo = (LICENSE_PRODUCT_INFO*) malloc(sizeof(LICENSE_PRODUCT_INFO));
if (!productInfo)
return NULL;
productInfo->dwVersion = 0;
productInfo->cbCompanyName = 0;
productInfo->pbCompanyName = NULL;
@ -584,6 +593,8 @@ BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob)
blob->type = wBlobType;
blob->data = (BYTE*) malloc(blob->length);
if (!blob->data)
return FALSE;
Stream_Read(s, blob->data, blob->length); /* blobData */
return TRUE;
}
@ -640,10 +651,9 @@ BOOL license_write_encrypted_premaster_secret_blob(wStream* s, LICENSE_BLOB* blo
LICENSE_BLOB* license_new_binary_blob(UINT16 type)
{
LICENSE_BLOB* blob;
blob = (LICENSE_BLOB*) malloc(sizeof(LICENSE_BLOB));
blob->type = type;
blob->length = 0;
blob->data = NULL;
blob = (LICENSE_BLOB*) calloc(1, sizeof(LICENSE_BLOB));
if (blob)
blob->type = type;
return blob;
}
@ -684,6 +694,8 @@ BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList)
scopeList->count = scopeCount;
scopeList->array = (LICENSE_BLOB*) malloc(sizeof(LICENSE_BLOB) * scopeCount);
if (!scopeList->array)
return FALSE;
/* ScopeArray */
for (i = 0; i < scopeCount; i++)
@ -705,11 +717,7 @@ BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList)
SCOPE_LIST* license_new_scope_list()
{
SCOPE_LIST* scopeList;
scopeList = (SCOPE_LIST*) malloc(sizeof(SCOPE_LIST));
scopeList->count = 0;
scopeList->array = NULL;
return scopeList;
return (SCOPE_LIST*) calloc(1, sizeof(SCOPE_LIST));
}
/**
@ -722,6 +730,9 @@ void license_free_scope_list(SCOPE_LIST* scopeList)
{
UINT32 i;
if (!scopeList)
return;
/*
* We must NOT call license_free_binary_blob() on each scopelist->array[i] element,
* because scopelist->array was allocated at once, by a single call to malloc. The elements
@ -1093,29 +1104,44 @@ BOOL license_send_valid_client_error_packet(rdpLicense* license)
rdpLicense* license_new(rdpRdp* rdp)
{
rdpLicense* license;
license = (rdpLicense*) malloc(sizeof(rdpLicense));
license = (rdpLicense*) calloc(1, sizeof(rdpLicense));
if (!license)
return NULL;
if (license != NULL)
{
ZeroMemory(license, sizeof(rdpLicense));
license->rdp = rdp;
license->state = LICENSE_STATE_AWAIT;
license->certificate = certificate_new();
license->ProductInfo = license_new_product_info();
license->ErrorInfo = license_new_binary_blob(BB_ERROR_BLOB);
license->KeyExchangeList = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB);
license->ServerCertificate = license_new_binary_blob(BB_CERTIFICATE_BLOB);
license->ClientUserName = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB);
license->ClientMachineName = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB);
license->PlatformChallenge = license_new_binary_blob(BB_ANY_BLOB);
license->EncryptedPlatformChallenge = license_new_binary_blob(BB_ANY_BLOB);
license->EncryptedPremasterSecret = license_new_binary_blob(BB_ANY_BLOB);
license->EncryptedHardwareId = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB);
license->ScopeList = license_new_scope_list();
license_generate_randoms(license);
}
license->rdp = rdp;
license->state = LICENSE_STATE_AWAIT;
if (!(license->certificate = certificate_new()))
goto out_error;
if (!(license->ProductInfo = license_new_product_info()))
goto out_error;
if (!(license->ErrorInfo = license_new_binary_blob(BB_ERROR_BLOB)))
goto out_error;
if (!(license->KeyExchangeList = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB)))
goto out_error;
if (!(license->ServerCertificate = license_new_binary_blob(BB_CERTIFICATE_BLOB)))
goto out_error;
if (!(license->ClientUserName = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB)))
goto out_error;
if (!(license->ClientMachineName = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB)))
goto out_error;
if (!(license->PlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
goto out_error;
if (!(license->EncryptedPlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
goto out_error;
if (!(license->EncryptedPremasterSecret = license_new_binary_blob(BB_ANY_BLOB)))
goto out_error;
if (!(license->EncryptedHardwareId = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
goto out_error;
if (!(license->ScopeList = license_new_scope_list()))
goto out_error;
license_generate_randoms(license);
return license;
out_error:
license_free(license);
return NULL;
}
/**

View File

@ -2770,15 +2770,13 @@ rdpInputProxy* input_message_proxy_new(rdpInput* input)
{
rdpInputProxy* proxy;
proxy = (rdpInputProxy*) malloc(sizeof(rdpInputProxy));
proxy = (rdpInputProxy*) calloc(1, sizeof(rdpInputProxy));
if (proxy)
{
ZeroMemory(proxy, sizeof(rdpInputProxy));
if (!proxy)
return NULL;
proxy->input = input;
input_message_proxy_register(proxy, input);
}
proxy->input = input;
input_message_proxy_register(proxy, input);
return proxy;
}

View File

@ -43,13 +43,7 @@ int rdp_recv_multitransport_packet(rdpRdp* rdp, wStream* s)
rdpMultitransport* multitransport_new(void)
{
rdpMultitransport* multitransport = (rdpMultitransport*)malloc(sizeof(rdpMultitransport));
if (multitransport)
{
memset(multitransport, 0, sizeof(rdpMultitransport));
}
return multitransport;
return (rdpMultitransport*)calloc(1, sizeof(rdpMultitransport));
}
void multitransport_free(rdpMultitransport* multitransport)

View File

@ -883,34 +883,65 @@ BOOL nla_read_ts_password_creds(rdpNla* nla, wStream* s)
}
/* TSPasswordCreds (SEQUENCE) */
ber_read_sequence_tag(s, &length);
if (!ber_read_sequence_tag(s, &length) ||
/* [0] domainName (OCTET STRING) */
ber_read_contextual_tag(s, 0, &length, TRUE);
ber_read_octet_string_tag(s, &length);
/* [0] domainName (OCTET STRING) */
!ber_read_contextual_tag(s, 0, &length, TRUE) ||
!ber_read_octet_string_tag(s, &length))
{
return FALSE;
}
nla->identity->DomainLength = (UINT32) length;
nla->identity->Domain = (UINT16*) malloc(length);
CopyMemory(nla->identity->Domain, Stream_Pointer(s), nla->identity->DomainLength);
Stream_Seek(s, nla->identity->DomainLength);
nla->identity->DomainLength /= 2;
if (nla->identity->DomainLength > 0)
{
nla->identity->Domain = (UINT16*) malloc(length);
if (!nla->identity->Domain)
return FALSE;
CopyMemory(nla->identity->Domain, Stream_Pointer(s), nla->identity->DomainLength);
Stream_Seek(s, nla->identity->DomainLength);
nla->identity->DomainLength /= 2;
}
else
nla->identity->Domain = NULL;
/* [1] userName (OCTET STRING) */
ber_read_contextual_tag(s, 1, &length, TRUE);
ber_read_octet_string_tag(s, &length);
if (!ber_read_contextual_tag(s, 1, &length, TRUE) ||
!ber_read_octet_string_tag(s, &length))
{
return FALSE;
}
nla->identity->UserLength = (UINT32) length;
nla->identity->User = (UINT16*) malloc(length);
CopyMemory(nla->identity->User, Stream_Pointer(s), nla->identity->UserLength);
Stream_Seek(s, nla->identity->UserLength);
nla->identity->UserLength /= 2;
if (nla->identity->PasswordLength > 0)
{
nla->identity->User = (UINT16 *) malloc(length);
if (!nla->identity->User)
return FALSE;
CopyMemory(nla->identity->User, Stream_Pointer(s), nla->identity->UserLength);
Stream_Seek(s, nla->identity->UserLength);
nla->identity->UserLength /= 2;
}
else
nla->identity->User = NULL;
/* [2] password (OCTET STRING) */
ber_read_contextual_tag(s, 2, &length, TRUE);
ber_read_octet_string_tag(s, &length);
if (!ber_read_contextual_tag(s, 2, &length, TRUE) ||
!ber_read_octet_string_tag(s, &length))
{
return FALSE;
}
nla->identity->PasswordLength = (UINT32) length;
nla->identity->Password = (UINT16*) malloc(length);
CopyMemory(nla->identity->Password, Stream_Pointer(s), nla->identity->PasswordLength);
Stream_Seek(s, nla->identity->PasswordLength);
nla->identity->PasswordLength /= 2;
if (nla->identity->PasswordLength > 0)
{
nla->identity->Password = (UINT16 *) malloc(length);
if (!nla->identity->Password)
return FALSE;
CopyMemory(nla->identity->Password, Stream_Pointer(s), nla->identity->PasswordLength);
Stream_Seek(s, nla->identity->PasswordLength);
nla->identity->PasswordLength /= 2;
}
else
nla->identity->Password = NULL;
nla->identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
return TRUE;
@ -951,10 +982,10 @@ int nla_sizeof_ts_credentials(rdpNla* nla)
static BOOL nla_read_ts_credentials(rdpNla* nla, PSecBuffer ts_credentials)
{
BOOL rc;
wStream* s;
int length;
int ts_password_creds_length;
BOOL ret;
s = Stream_New(ts_credentials->pvBuffer, ts_credentials->cbBuffer);
@ -965,21 +996,18 @@ static BOOL nla_read_ts_credentials(rdpNla* nla, PSecBuffer ts_credentials)
}
/* TSCredentials (SEQUENCE) */
ber_read_sequence_tag(s, &length);
/* [0] credType (INTEGER) */
ber_read_contextual_tag(s, 0, &length, TRUE);
ber_read_integer(s, NULL);
/* [1] credentials (OCTET STRING) */
ber_read_contextual_tag(s, 1, &length, TRUE);
ber_read_octet_string_tag(s, &ts_password_creds_length);
rc = nla_read_ts_password_creds(nla, s);
/* TSCredentials (SEQUENCE) */
ret = ber_read_sequence_tag(s, &length) &&
/* [0] credType (INTEGER) */
ber_read_contextual_tag(s, 0, &length, TRUE) &&
ber_read_integer(s, NULL) &&
/* [1] credentials (OCTET STRING) */
ber_read_contextual_tag(s, 1, &length, TRUE) &&
ber_read_octet_string_tag(s, &ts_password_creds_length) &&
nla_read_ts_password_creds(nla, s);
Stream_Free(s, FALSE);
return rc;
return ret;
}
int nla_write_ts_credentials(rdpNla* nla, wStream* s)
@ -1398,6 +1426,12 @@ LPTSTR nla_make_spn(const char* ServiceClass, const char* hostname)
hostnameX = _strdup(hostname);
ServiceClassX = _strdup(ServiceClass);
#endif
if (!hostnameX || !ServiceClassX)
{
free(hostnameX);
free(ServiceClassX);
return NULL;
}
if (!ServiceClass)
{
@ -1445,10 +1479,6 @@ LPTSTR nla_make_spn(const char* ServiceClass, const char* hostname)
rdpNla* nla_new(freerdp* instance, rdpTransport* transport, rdpSettings* settings)
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
rdpNla* nla = (rdpNla*) calloc(1, sizeof(rdpNla));
@ -1468,6 +1498,7 @@ rdpNla* nla_new(freerdp* instance, rdpTransport* transport, rdpSettings* setting
nla->transport = transport;
nla->sendSeqNum = 0;
nla->recvSeqNum = 0;
ZeroMemory(&nla->negoToken, sizeof(SecBuffer));
ZeroMemory(&nla->pubKeyAuth, sizeof(SecBuffer));
ZeroMemory(&nla->authInfo, sizeof(SecBuffer));
@ -1475,26 +1506,39 @@ rdpNla* nla_new(freerdp* instance, rdpTransport* transport, rdpSettings* setting
if (nla->server)
{
LONG status;
HKEY hKey;
DWORD dwType;
DWORD dwSize;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"),
0, KEY_READ | KEY_WOW64_64KEY, &hKey);
0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status != ERROR_SUCCESS)
return nla;
status = RegQueryValueEx(hKey, _T("SspiModule"), NULL, &dwType, NULL, &dwSize);
if (status != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return nla;
}
nla->SspiModule = (LPTSTR) malloc(dwSize + sizeof(TCHAR));
if (!nla->SspiModule)
{
RegCloseKey(hKey);
free(nla);
return NULL;
}
status = RegQueryValueEx(hKey, _T("SspiModule"), NULL, &dwType,
(BYTE*) nla->SspiModule, &dwSize);
if (status == ERROR_SUCCESS)
{
status = RegQueryValueEx(hKey, _T("SspiModule"), NULL, &dwType, NULL, &dwSize);
WLog_INFO(TAG, "Using SSPI Module: %s", nla->SspiModule);
if (status == ERROR_SUCCESS)
{
nla->SspiModule = (LPTSTR) malloc(dwSize + sizeof(TCHAR));
status = RegQueryValueEx(hKey, _T("SspiModule"), NULL, &dwType,
(BYTE*) nla->SspiModule, &dwSize);
if (status == ERROR_SUCCESS)
{
WLog_INFO(TAG, "Using SSPI Module: %s", nla->SspiModule);
RegCloseKey(hKey);
}
}
}
RegCloseKey(hKey);
}
return nla;

View File

@ -2280,6 +2280,8 @@ BOOL update_read_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_or
return FALSE;
glyph->aj = (BYTE*) malloc(glyph->cb);
if (!glyph->aj)
return FALSE;
Stream_Read(s, glyph->aj, glyph->cb);
}
@ -2370,6 +2372,8 @@ BOOL update_read_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_gl
return FALSE;
glyph->aj = (BYTE*) malloc(glyph->cb);
if (!glyph->aj)
return FALSE;
Stream_Read(s, glyph->aj, glyph->cb);
}

View File

@ -134,28 +134,38 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
{
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)
@ -164,6 +174,8 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
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);
}
@ -173,6 +185,8 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
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);
}
@ -182,10 +196,21 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
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;
}
}
}
@ -228,6 +253,8 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, wStream* s)
return -1;
redirection->LoadBalanceInfo = (BYTE*) malloc(redirection->LoadBalanceInfoLength);
if (!redirection->LoadBalanceInfo)
return -1;
Stream_Read(s, redirection->LoadBalanceInfo, redirection->LoadBalanceInfoLength);
WLog_DBG(TAG, "loadBalanceInfo:");
@ -258,6 +285,8 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, wStream* s)
Stream_Read_UINT32(s, redirection->PasswordLength);
redirection->Password = (BYTE*) malloc(redirection->PasswordLength);
if (!redirection->Password)
return -1;
Stream_Read(s, redirection->Password, redirection->PasswordLength);
WLog_DBG(TAG, "PasswordCookie:");
@ -291,6 +320,8 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, wStream* s)
return -1;
redirection->TsvUrl = (BYTE*) malloc(redirection->TsvUrlLength);
if (!redirection->TsvUrl)
return -1;
Stream_Read(s, redirection->TsvUrl, redirection->TsvUrlLength);
WLog_DBG(TAG, "TsvUrl:");

View File

@ -852,6 +852,11 @@ BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId,
BytesReturned = sizeof(ULONG);
pBuffer = (ULONG*) malloc(sizeof(BytesReturned));
if (!pBuffer)
{
SetLastError(E_OUTOFMEMORY);
return FALSE;
}
*pBuffer = vcm->SessionId;
@ -1212,7 +1217,10 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
length = Length;
buffer = (BYTE *)malloc(length);
if (!buffer)
{
SetLastError(E_OUTOFMEMORY);
return FALSE;
}
CopyMemory(buffer, Buffer, length);
ret = wts_queue_send_item(channel, buffer, length);
@ -1232,6 +1240,7 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
SetLastError(E_OUTOFMEMORY);
return FALSE;
}
@ -1309,16 +1318,26 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CL
}
*ppBuffer = malloc(sizeof(void*));
CopyMemory(*ppBuffer, &fds[0], sizeof(void*));
*pBytesReturned = sizeof(void*);
status = TRUE;
if (!*ppBuffer)
{
SetLastError(E_OUTOFMEMORY);
} else {
CopyMemory(*ppBuffer, &fds[0], sizeof(void*));
*pBytesReturned = sizeof(void*);
status = TRUE;
}
break;
case WTSVirtualEventHandle:
*ppBuffer = malloc(sizeof(HANDLE));
CopyMemory(*ppBuffer, &(hEvent), sizeof(HANDLE));
*pBytesReturned = sizeof(void*);
status = TRUE;
if (!*ppBuffer)
{
SetLastError(E_OUTOFMEMORY);
} else {
CopyMemory(*ppBuffer, &(hEvent), sizeof(HANDLE));
*pBytesReturned = sizeof(void*);
status = TRUE;
}
break;
case WTSVirtualChannelReady:
@ -1349,8 +1368,14 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CL
}
*ppBuffer = malloc(sizeof(BOOL));
CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
*pBytesReturned = sizeof(BOOL);
if (!*ppBuffer)
{
SetLastError(E_OUTOFMEMORY);
status = FALSE;
} else {
CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
*pBytesReturned = sizeof(BOOL);
}
break;
default:

View File

@ -37,6 +37,8 @@
#include <winpr/registry.h>
#include <freerdp/settings.h>
#include <ctype.h>
#ifdef _WIN32
#pragma warning(push)
@ -191,15 +193,19 @@ void settings_load_hkey_local_machine(rdpSettings* settings)
settings_client_load_hkey_local_machine(settings);
}
void settings_get_computer_name(rdpSettings* settings)
BOOL settings_get_computer_name(rdpSettings* settings)
{
DWORD nSize = 0;
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize);
settings->ComputerName = (char*) malloc(nSize);
if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
return FALSE;
settings->ComputerName = _strdup(computerName);
if (!settings->ComputerName)
return;
GetComputerNameExA(ComputerNameNetBIOS, settings->ComputerName, &nSize);
return FALSE;
return TRUE;
}
rdpSettings* freerdp_settings_new(DWORD flags)
@ -288,7 +294,8 @@ rdpSettings* freerdp_settings_new(DWORD flags)
if(!settings->MonitorIds)
goto out_fail;
settings_get_computer_name(settings);
if (!settings_get_computer_name(settings))
goto out_fail;
settings->ReceivedCapabilities = calloc(1, 32);
if (!settings->ReceivedCapabilities)
@ -549,59 +556,55 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
{
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
@ -666,15 +669,19 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
_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));
@ -688,6 +695,10 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
_settings->OrderSupport = malloc(32);
if (!_settings->OrderSupport)
goto out_fail;
if (!_settings->ReceivedCapabilities || !_settings->OrderSupport)
goto out_fail;
CopyMemory(_settings->ReceivedCapabilities, settings->ReceivedCapabilities, 32);
CopyMemory(_settings->OrderSupport, settings->OrderSupport, 32);
@ -733,16 +744,24 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
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)
@ -760,37 +779,52 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
_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);
@ -798,10 +832,16 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
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;
}

View File

@ -128,6 +128,7 @@ int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s)
if (update->dump_rfx)
{
/* TODO: treat return values */
pcap_add_record(update->pcap_rfx, mark, cmdLength + 2);
pcap_flush(update->pcap_rfx);
}

View File

@ -1283,8 +1283,9 @@ int freerdp_tcp_connect(rdpSettings* settings, const char* hostname, int port, i
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;
}
@ -1296,6 +1297,12 @@ int freerdp_tcp_connect(rdpSettings* settings, const char* hostname, int port, i
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);
@ -1316,6 +1323,7 @@ int freerdp_tcp_connect(rdpSettings* settings, const char* hostname, int port, i
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &optval, optlen) < 0)
{
close(sockfd);
WLog_ERR(TAG, "unable to set receive buffer len");
return -1;
}
@ -1325,7 +1333,11 @@ int freerdp_tcp_connect(rdpSettings* settings, const char* hostname, int port, i
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;

View File

@ -5,7 +5,8 @@ set(MODULE_PREFIX "TEST_CORE")
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}

View File

@ -0,0 +1,28 @@
#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;
}

View File

@ -1816,6 +1816,8 @@ BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s)
return FALSE;
areas = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * numberOfAreas);
if (!areas)
return FALSE;
for (index = 0; index < numberOfAreas; index++)
{

View File

@ -124,7 +124,11 @@ BOOL update_read_icon_info(wStream* s, ICON_INFO* iconInfo)
if (iconInfo->colorTable == NULL)
{
if (iconInfo->cbColorTable)
{
iconInfo->colorTable = (BYTE*) malloc(iconInfo->cbColorTable);
if (!iconInfo->colorTable)
return FALSE;
}
}
else if (iconInfo->cbColorTable)
{
@ -292,6 +296,8 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI
size = sizeof(RECTANGLE_16) * windowState->numWindowRects;
windowState->windowRects = (RECTANGLE_16*) malloc(size);
if (!windowState->windowRects)
return FALSE;
if (Stream_GetRemainingLength(s) < 8 * windowState->numWindowRects)
return FALSE;
@ -324,6 +330,8 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI
size = sizeof(RECTANGLE_16) * windowState->numVisibilityRects;
windowState->visibilityRects = (RECTANGLE_16*) malloc(size);
if (!windowState->visibilityRects)
return FALSE;
if (Stream_GetRemainingLength(s) < windowState->numVisibilityRects * 8)
return FALSE;
@ -342,8 +350,9 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI
BOOL update_read_window_icon_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_ICON_ORDER* window_icon)
{
window_icon->iconInfo = (ICON_INFO*) malloc(sizeof(ICON_INFO));
ZeroMemory(window_icon->iconInfo, sizeof(ICON_INFO));
window_icon->iconInfo = (ICON_INFO*) calloc(1, sizeof(ICON_INFO));
if (!window_icon->iconInfo)
return FALSE;
return update_read_icon_info(s, window_icon->iconInfo); /* iconInfo (ICON_INFO) */
}

View File

@ -125,6 +125,8 @@ static void* base64_decode(const char* s, int length, int* data_len)
return NULL;
q = data = (BYTE*) malloc(length / 4 * 3);
if (!q)
return NULL;
/* first treat complete blocks */
nBlocks = (length / 4);

View File

@ -325,7 +325,6 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store,
if (!fp)
return FALSE;
/* Read the current contents of the file. */
fseek(fp, 0, SEEK_END);
size = ftell(fp);

View File

@ -231,6 +231,11 @@ BOOL crypto_cert_get_public_key(CryptoCert cert, BYTE** PublicKey, DWORD* Public
*PublicKeyLength = (DWORD) length;
*PublicKey = (BYTE*) malloc(length);
ptr = (BYTE*) (*PublicKey);
if (!ptr)
{
status = FALSE;
goto exit;
}
i2d_PublicKey(pkey, &ptr);
@ -380,9 +385,9 @@ char* crypto_print_name(X509_NAME* name)
if (X509_NAME_print_ex(outBIO, name, 0, XN_FLAG_ONELINE) > 0)
{
unsigned long size = BIO_number_written(outBIO);
buffer = malloc(size + 1);
ZeroMemory(buffer, size + 1);
memset(buffer, 0, size + 1);
buffer = calloc(1, size + 1);
if (!buffer)
return NULL;
BIO_read(outBIO, buffer, size);
}
@ -471,7 +476,15 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
if (num_subject_alt_names)
{
strings = (char**) malloc(sizeof(char*) * num_subject_alt_names);
if (!strings)
goto out;
*lengths = (int*) malloc(sizeof(int) * num_subject_alt_names);
if (!*lengths)
{
free(strings);
goto out;
}
}
for (index = 0; index < num_subject_alt_names; ++index)
@ -494,6 +507,8 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
*lengths = NULL ;
return NULL;
}
out:
GENERAL_NAMES_free(subject_alt_names);
return strings;

View File

@ -1012,6 +1012,11 @@ int tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname, int por
offset = 0;
length = 2048;
pemCert = (BYTE*) malloc(length + 1);
if (!pemCert)
{
WLog_ERR(TAG, "error allocating pemCert");
return -1;
}
status = BIO_read(bio, pemCert, length);

View File

@ -44,6 +44,7 @@ HGDI_DC gdi_GetDC()
HGDI_DC hDC = (HGDI_DC) malloc(sizeof(GDI_DC));
if (!hDC)
return NULL;
hDC->bytesPerPixel = 4;
hDC->bitsPerPixel = 32;
hDC->drawMode = GDI_R2_BLACK;

View File

@ -46,6 +46,7 @@ HGDI_RGN gdi_CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBot
HGDI_RGN hRgn = (HGDI_RGN) malloc(sizeof(GDI_RGN));
if (!hRgn)
return NULL;
hRgn->objectType = GDIOBJECT_REGION;
hRgn->x = nLeftRect;
hRgn->y = nTopRect;
@ -69,6 +70,7 @@ HGDI_RECT gdi_CreateRect(int xLeft, int yTop, int xRight, int yBottom)
HGDI_RECT hRect = (HGDI_RECT) malloc(sizeof(GDI_RECT));
if (!hRect)
return NULL;
hRect->objectType = GDIOBJECT_RECT;
hRect->left = xLeft;
hRect->top = yTop;

View File

@ -98,7 +98,9 @@ int freerdp_keyboard_init_x11_evdev(DWORD* keyboardLayoutId, DWORD x11_keycode_t
DWORD freerdp_keyboard_init(DWORD keyboardLayoutId)
{
DWORD keycode;
#if defined(__APPLE__) || defined(WITH_X11)
int status = -1;
#endif
#ifdef __APPLE__
if (status < 0)

View File

@ -248,6 +248,14 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types)
{
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)
@ -265,6 +273,14 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types)
{
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)
@ -282,6 +298,14 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types)
{
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;
}
}
}

View File

@ -227,7 +227,7 @@ int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout)
kbd = popen("kbd -t -l", "r");
if (kbd < 0)
if (!kbd)
return -1;
while (fgets(buffer, sizeof(buffer), kbd) != NULL)

View File

@ -48,7 +48,8 @@ int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
/* We start by looking for _XKB_RULES_NAMES_BACKUP which appears to be used by libxklavier */
xprop = popen("xprop -root _XKB_RULES_NAMES_BACKUP", "r");
if (!(xprop = popen("xprop -root _XKB_RULES_NAMES_BACKUP", "r")))
return 0;
/* Sample output for "Canadian Multilingual Standard"
*
@ -100,7 +101,8 @@ int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
/* Check _XKB_RULES_NAMES if _XKB_RULES_NAMES_BACKUP fails */
xprop = popen("xprop -root _XKB_RULES_NAMES", "r");
if (!(xprop = popen("xprop -root _XKB_RULES_NAMES", "r")))
return 0;
while (fgets(buffer, sizeof(buffer), xprop) != NULL)
{
@ -157,6 +159,9 @@ char* freerdp_detect_keymap_from_xkb()
/* this tells us about the current XKB configuration, if XKB is available */
setxkbmap = popen("setxkbmap -print", "r");
if (!setxkbmap)
return NULL;
while (fgets(buffer, sizeof(buffer), setxkbmap) != NULL)
{
/* the line with xkb_keycodes is what interests us */
@ -182,8 +187,10 @@ char* freerdp_detect_keymap_from_xkb()
length = (end - beg);
keymap = (char*) malloc(length + 1);
strncpy(keymap, beg, length);
keymap[length] = '\0';
if (keymap) {
strncpy(keymap, beg, length);
keymap[length] = '\0';
}
break;
}

View File

@ -1541,6 +1541,12 @@ char* freerdp_get_unix_timezone_identifier()
}
tzid = (char*) malloc(length + 1);
if (!tzid)
{
fclose(fp);
return NULL;
}
fread(tzid, length, 1, fp);
tzid[length] = '\0';
@ -1579,6 +1585,9 @@ char* freerdp_get_unix_timezone_identifier()
}
tzid = (char*) malloc(len - pos + 1);
if (!tzid)
return NULL;
strncpy(tzid, buf + pos + 1, len - pos);
return tzid;
@ -1597,6 +1606,8 @@ BOOL freerdp_match_unix_timezone_identifier_with_list(const char* tzid, const ch
char* list_copy;
list_copy = _strdup(list);
if (!list_copy)
return FALSE;
p = strtok(list_copy, " ");
@ -1636,10 +1647,13 @@ TIME_ZONE_ENTRY* freerdp_detect_windows_time_zone(UINT32 bias)
if (freerdp_match_unix_timezone_identifier_with_list(tzid, WindowsTimeZoneIdTable[j].tzid))
{
free(tzid);
timezone = (TIME_ZONE_ENTRY*) malloc(sizeof(TIME_ZONE_ENTRY));
if (!timezone)
return NULL;
memcpy((void*) timezone, (void*) &TimeZoneTable[i], sizeof(TIME_ZONE_ENTRY));
timezone->Bias = bias;
free(tzid);
return timezone;
}
}

View File

@ -36,9 +36,7 @@
static MSUSB_PIPE_DESCRIPTOR* msusb_mspipe_new()
{
MSUSB_PIPE_DESCRIPTOR* MsPipe = (MSUSB_PIPE_DESCRIPTOR*) malloc(sizeof(MSUSB_PIPE_DESCRIPTOR));
memset(MsPipe, 0, sizeof(MSUSB_PIPE_DESCRIPTOR));
return MsPipe;
return (MSUSB_PIPE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_PIPE_DESCRIPTOR));
}
static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes, UINT32 NumberOfPipes)
@ -69,11 +67,15 @@ static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size,
int pnum, move = 0;
MSUSB_PIPE_DESCRIPTOR** MsPipes;
MsPipes = (MSUSB_PIPE_DESCRIPTOR**) malloc(NumberOfPipes * sizeof(MSUSB_PIPE_DESCRIPTOR*));
MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(NumberOfPipes, sizeof(MSUSB_PIPE_DESCRIPTOR*));
if (!MsPipes)
return NULL;
for (pnum = 0; pnum < NumberOfPipes; pnum++)
{
MSUSB_PIPE_DESCRIPTOR * MsPipe = msusb_mspipe_new();
MSUSB_PIPE_DESCRIPTOR *MsPipe = msusb_mspipe_new();
if (!MsPipe)
goto out_error;
data_read_UINT16(data + move, MsPipe->MaximumPacketSize);
data_read_UINT32(data + move + 4, MsPipe->MaximumTransferSize);
@ -92,13 +94,19 @@ static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size,
*offset += move;
return MsPipes;
out_error:
for (pnum = 0; pnum < NumberOfPipes; pnum++)
{
free(MsPipes[pnum]);
}
free(MsPipes);
return NULL;
}
static MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_new()
{
MSUSB_INTERFACE_DESCRIPTOR* MsInterface = (MSUSB_INTERFACE_DESCRIPTOR*) malloc(sizeof(MSUSB_INTERFACE_DESCRIPTOR));
memset(MsInterface, 0, sizeof(MSUSB_INTERFACE_DESCRIPTOR));
return MsInterface;
return (MSUSB_INTERFACE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_INTERFACE_DESCRIPTOR));
}
static void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface)
@ -137,6 +145,8 @@ MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size,
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
MsInterface = msusb_msinterface_new();
if (!MsInterface)
return NULL;
data_read_UINT16(data, MsInterface->Length);
data_read_UINT16(data + 2, MsInterface->NumberOfPipesExpected);
@ -156,9 +166,15 @@ MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size,
{
MsInterface->MsPipes =
msusb_mspipes_read(data+(*offset), data_size-(*offset), MsInterface->NumberOfPipes, offset);
if (!MsInterface->MsPipes)
goto out_error;
}
return MsInterface;
out_error:
msusb_msinterface_free(MsInterface);
return NULL;
}
int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data, int* offset)
@ -219,7 +235,9 @@ static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(BYTE * data, UIN
int inum, offset = 0;
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) malloc(NumInterfaces * sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) calloc(NumInterfaces, sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
if (!MsInterfaces)
return NULL;
for (inum = 0; inum < NumInterfaces; inum++)
{
@ -257,11 +275,7 @@ int msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, BYTE* data, int* offs
MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_new()
{
MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL;
MsConfig = (MSUSB_CONFIG_DESCRIPTOR*) malloc(sizeof(MSUSB_CONFIG_DESCRIPTOR));
memset(MsConfig, 0, sizeof(MSUSB_CONFIG_DESCRIPTOR));
return MsConfig;
return (MSUSB_CONFIG_DESCRIPTOR*) calloc(1, sizeof(MSUSB_CONFIG_DESCRIPTOR));
}
void msusb_msconfig_free(MSUSB_CONFIG_DESCRIPTOR* MsConfig)

View File

@ -52,19 +52,19 @@ int gettimeofday(struct timeval* tp, void* tz)
#define PCAP_MAGIC 0xA1B2C3D4
void pcap_read_header(rdpPcap* pcap, pcap_header* header)
BOOL pcap_read_header(rdpPcap* pcap, pcap_header* header)
{
fread((void*) header, sizeof(pcap_header), 1, pcap->fp);
return fread((void*) header, sizeof(pcap_header), 1, pcap->fp) == 1;
}
void pcap_write_header(rdpPcap* pcap, pcap_header* header)
BOOL pcap_write_header(rdpPcap* pcap, pcap_header* header)
{
fwrite((void*) header, sizeof(pcap_header), 1, pcap->fp);
return fwrite((void*) header, sizeof(pcap_header), 1, pcap->fp) == 1;
}
void pcap_read_record_header(rdpPcap* pcap, pcap_record_header* record)
BOOL pcap_read_record_header(rdpPcap* pcap, pcap_record_header* record)
{
fread((void*) record, sizeof(pcap_record_header), 1, pcap->fp);
return fread((void*) record, sizeof(pcap_record_header), 1, pcap->fp) == 1;
}
void pcap_write_record_header(rdpPcap* pcap, pcap_record_header* record)
@ -72,12 +72,23 @@ void pcap_write_record_header(rdpPcap* pcap, pcap_record_header* record)
fwrite((void*) record, sizeof(pcap_record_header), 1, pcap->fp);
}
void pcap_read_record(rdpPcap* pcap, pcap_record* record)
BOOL pcap_read_record(rdpPcap* pcap, pcap_record* record)
{
pcap_read_record_header(pcap, &record->header);
if (!pcap_read_record_header(pcap, &record->header))
return FALSE;
record->length = record->header.incl_len;
record->data = malloc(record->length);
fread(record->data, record->length, 1, pcap->fp);
if (!record->data)
return FALSE;
if (fread(record->data, record->length, 1, pcap->fp) != 1)
{
free(record->data);
record->data = NULL;
return FALSE;
}
return TRUE;
}
void pcap_write_record(rdpPcap* pcap, pcap_record* record)
@ -86,15 +97,16 @@ void pcap_write_record(rdpPcap* pcap, pcap_record* record)
fwrite(record->data, record->length, 1, pcap->fp);
}
void pcap_add_record(rdpPcap* pcap, void* data, UINT32 length)
BOOL pcap_add_record(rdpPcap* pcap, void* data, UINT32 length)
{
pcap_record* record;
struct timeval tp;
if (pcap->tail == NULL)
{
pcap->tail = (pcap_record*) malloc(sizeof(pcap_record));
ZeroMemory(pcap->tail, sizeof(pcap_record));
pcap->tail = (pcap_record*) calloc(1, sizeof(pcap_record));
if (!pcap->tail)
return FALSE;
pcap->head = pcap->tail;
pcap->record = pcap->head;
@ -102,8 +114,9 @@ void pcap_add_record(rdpPcap* pcap, void* data, UINT32 length)
}
else
{
record = (pcap_record*) malloc(sizeof(pcap_record));
ZeroMemory(record, sizeof(pcap_record));
record = (pcap_record*) calloc(1, sizeof(pcap_record));
if (!record)
return FALSE;
pcap->tail->next = record;
pcap->tail = record;
@ -120,6 +133,7 @@ void pcap_add_record(rdpPcap* pcap, void* data, UINT32 length)
gettimeofday(&tp, 0);
record->header.ts_sec = tp.tv_sec;
record->header.ts_usec = tp.tv_usec;
return TRUE;
}
BOOL pcap_has_next_record(rdpPcap* pcap)
@ -143,18 +157,13 @@ BOOL pcap_get_next_record_header(rdpPcap* pcap, pcap_record* record)
BOOL pcap_get_next_record_content(rdpPcap* pcap, pcap_record* record)
{
fread(record->data, record->length, 1, pcap->fp);
return TRUE;
return fread(record->data, record->length, 1, pcap->fp) == 1;
}
BOOL pcap_get_next_record(rdpPcap* pcap, pcap_record* record)
{
if (pcap_has_next_record(pcap) != TRUE)
return FALSE;
pcap_read_record(pcap, record);
return TRUE;
return pcap_has_next_record(pcap) &&
pcap_read_record(pcap, record);
}
rdpPcap* pcap_open(char* name, BOOL write)
@ -169,38 +178,43 @@ rdpPcap* pcap_open(char* name, BOOL write)
return NULL;
}
pcap = (rdpPcap*) malloc(sizeof(rdpPcap));
pcap = (rdpPcap*) calloc(1, sizeof(rdpPcap));
if (!pcap)
goto fail_close;
if (pcap != NULL)
pcap->name = name;
pcap->write = write;
pcap->record_count = 0;
pcap->fp = pcap_fp;
if (write)
{
ZeroMemory(pcap, sizeof(rdpPcap));
pcap->name = name;
pcap->write = write;
pcap->record_count = 0;
pcap->fp = pcap_fp;
if (write)
{
pcap->header.magic_number = 0xA1B2C3D4;
pcap->header.version_major = 2;
pcap->header.version_minor = 4;
pcap->header.thiszone = 0;
pcap->header.sigfigs = 0;
pcap->header.snaplen = 0xFFFFFFFF;
pcap->header.network = 0;
pcap_write_header(pcap, &pcap->header);
}
else
{
fseek(pcap->fp, 0, SEEK_END);
pcap->file_size = (int) ftell(pcap->fp);
fseek(pcap->fp, 0, SEEK_SET);
pcap_read_header(pcap, &pcap->header);
}
pcap->header.magic_number = 0xA1B2C3D4;
pcap->header.version_major = 2;
pcap->header.version_minor = 4;
pcap->header.thiszone = 0;
pcap->header.sigfigs = 0;
pcap->header.snaplen = 0xFFFFFFFF;
pcap->header.network = 0;
if (!pcap_write_header(pcap, &pcap->header))
goto fail;
}
else
{
fseek(pcap->fp, 0, SEEK_END);
pcap->file_size = (int) ftell(pcap->fp);
fseek(pcap->fp, 0, SEEK_SET);
if (!pcap_read_header(pcap, &pcap->header))
goto fail;
}
return pcap;
fail:
free(pcap);
fail_close:
fclose(pcap_fp);
return NULL;
}
void pcap_flush(rdpPcap* pcap)

View File

@ -34,9 +34,16 @@ PROFILER* profiler_create(char* name)
PROFILER* profiler;
profiler = (PROFILER*) malloc(sizeof(PROFILER));
if (!profiler)
return NULL;
profiler->name = name;
profiler->stopwatch = stopwatch_create();
if (!profiler->stopwatch)
{
free(profiler);
return NULL;
}
return profiler;
}

View File

@ -55,6 +55,8 @@ STOPWATCH* stopwatch_create()
#endif
sw = (STOPWATCH*) malloc(sizeof(STOPWATCH));
if (!sw)
return NULL;
stopwatch_reset(sw);
return sw;

View File

@ -95,9 +95,13 @@ int main(int argc, char** argv)
XFree(pfs);
engine = rdtk_engine_new();
if (!engine)
return 1;
scanline = width * 4;
buffer = (BYTE*) malloc(scanline * height);
if (!buffer)
return 1;
surface = rdtk_surface_new(engine, buffer, width, height, scanline);

View File

@ -167,6 +167,8 @@ void mf_event_region_free(mfEventRegion* event_region)
mfEvent* mf_event_new(int type)
{
mfEvent* event = malloc(sizeof(mfEvent));
if (!event)
return NULL;
event->type = type;
return event;
}

View File

@ -92,18 +92,20 @@ mfInfo* mf_info_init()
{
mfInfo* mfi;
mfi = (mfInfo*) malloc(sizeof(mfInfo));
memset(mfi, 0, sizeof(mfInfo));
mfi = (mfInfo*) calloc(1, sizeof(mfInfo));
if (mfi != NULL)
{
pthread_mutex_init(&mfi->mutex, NULL);
mfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * MF_INFO_MAXPEERS);
memset(mfi->peers, 0, sizeof(freerdp_peer*) * MF_INFO_MAXPEERS);
mfi->peers = (freerdp_peer**) calloc(MF_INFO_MAXPEERS, sizeof(freerdp_peer*));
if (!mfi->peers)
{
free(mfi);
return NULL;
}
mfi->framesPerSecond = MF_INFO_DEFAULT_FPS;
mfi->input_disabled = FALSE;
}

View File

@ -155,6 +155,8 @@ int mf_mlion_screen_updates_init()
mf_mlion_display_info(&pixelWidth, &pixelHeight, &scale);
localBuf = malloc(pixelWidth * pixelHeight * 4);
if (!localBuf)
return -1;
CFDictionaryRef opts;

View File

@ -24,6 +24,7 @@
#include <freerdp/listener.h>
#include <freerdp/codec/rfx.h>
#include <winpr/stream.h>
#include <freerdp/peer.h>
#include <winpr/crt.h>
@ -388,6 +389,13 @@ void* mf_peer_main_loop(void* arg)
/* 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;

View File

@ -167,7 +167,7 @@ static void test_peer_end_frame(freerdp_peer* client)
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;
@ -176,9 +176,10 @@ static void test_peer_draw_background(freerdp_peer* client)
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);
@ -189,7 +190,10 @@ static void test_peer_draw_background(freerdp_peer* client)
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);
@ -223,11 +227,13 @@ static void test_peer_draw_background(freerdp_peer* client)
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;
@ -237,10 +243,16 @@ static void test_peer_load_icon(freerdp_peer* client)
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);
@ -248,26 +260,40 @@ static void test_peer_load_icon(freerdp_peer* client)
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)
@ -392,7 +418,7 @@ static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec,
return TRUE;
}
void tf_peer_dump_rfx(freerdp_peer* client)
BOOL tf_peer_dump_rfx(freerdp_peer* client)
{
wStream* s;
UINT32 prev_seconds;
@ -402,20 +428,26 @@ void tf_peer_dump_rfx(freerdp_peer* client)
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;
Stream_Buffer(s) = realloc(Stream_Buffer(s), record.length);
tmp = realloc(Stream_Buffer(s), record.length);
if (!tmp)
break;
Stream_Buffer(s) = tmp;
record.data = Stream_Buffer(s);
Stream_Capacity(s) = record.length;
@ -430,6 +462,11 @@ void tf_peer_dump_rfx(freerdp_peer* client)
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)
@ -524,7 +561,12 @@ BOOL tf_peer_post_connect(freerdp_peer* client)
#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"))
{
@ -584,12 +626,11 @@ BOOL tf_peer_activate(freerdp_peer* client)
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;
}
@ -718,6 +759,12 @@ static void* test_peer_mainloop(void* arg)
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;

View File

@ -54,6 +54,8 @@ BOOL wf_mirror_driver_find_display_device(wfInfo* wfi)
{
deviceKeyLength = _tcslen(deviceInfo.DeviceKey) - deviceKeyPrefixLength;
wfi->deviceKey = (LPTSTR) malloc((deviceKeyLength + 1) * sizeof(TCHAR));
if (!wfi->deviceKey)
return FALSE;
_tcsncpy_s(wfi->deviceKey, deviceKeyLength + 1,
&deviceInfo.DeviceKey[deviceKeyPrefixLength], deviceKeyLength);
@ -210,6 +212,8 @@ BOOL wf_mirror_driver_update(wfInfo* wfi, int mode)
}
deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
if (!deviceMode)
return FALSE;
deviceMode->dmDriverExtra = 2 * sizeof(DWORD);
extHdr = (DWORD*)((BYTE*) &deviceMode + sizeof(DEVMODE));
@ -278,8 +282,9 @@ BOOL wf_mirror_driver_map_memory(wfInfo* wfi)
return FALSE;
}
wfi->changeBuffer = malloc(sizeof(GETCHANGESBUF));
ZeroMemory(wfi->changeBuffer, sizeof(GETCHANGESBUF));
wfi->changeBuffer = calloc(1, sizeof(GETCHANGESBUF));
if (!wfi->changeBuffer)
return FALSE;
status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer);
@ -365,4 +370,4 @@ void wf_mirror_driver_deactivate(wfInfo* wfi)
wf_mirror_driver_update(wfi, MIRROR_UNLOAD);
wfi->mirrorDriverActive = FALSE;
}
}
}

View File

@ -37,6 +37,7 @@
#include "wf_rdpsnd.h"
#include "wf_peer.h"
#include <freerdp/peer.h>
BOOL wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
@ -211,13 +212,23 @@ DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
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)
@ -246,7 +257,8 @@ 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;

View File

@ -73,6 +73,8 @@ BOOL wf_settings_read_string_ascii(HKEY key, LPTSTR subkey, LPTSTR name, char**
if (status == ERROR_SUCCESS)
{
strX = (LPTSTR) malloc(dwSize + sizeof(TCHAR));
if (!strX)
return FALSE;
status = RegQueryValueEx(hKey, name, NULL, &dwType, (BYTE*) strX, &dwSize);
if (status != ERROR_SUCCESS)
@ -99,4 +101,4 @@ BOOL wf_settings_read_string_ascii(HKEY key, LPTSTR subkey, LPTSTR name, char**
}
return FALSE;
}
}

Some files were not shown because too many files have changed in this diff Show More