From adff58f48ddf923ee69180d4ef8439bf4affb45e Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Apr 2014 10:05:53 +0200 Subject: [PATCH 1/8] winpr/pipe: fix variable type - unsigned to signed fcntl returns int. Comparison to 0 < always returned false. --- winpr/libwinpr/pipe/pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index 36ab3be6c..d1c26e5fc 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -308,7 +308,7 @@ BOOL WaitNamedPipeW(LPCWSTR lpNamedPipeName, DWORD nTimeOut) BOOL SetNamedPipeHandleState(HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout) { int fd; - unsigned long flags; + int flags; WINPR_NAMED_PIPE* pNamedPipe; pNamedPipe = (WINPR_NAMED_PIPE*) hNamedPipe; From b8cf4a23045978f7b50e6a82e2bed31a621190e0 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Apr 2014 10:13:19 +0200 Subject: [PATCH 2/8] remove re-declaration of extended pipe functions remove them from winpr/pipe.h since they are defined and declared in winpr/file.h --- winpr/include/winpr/file.h | 2 ++ winpr/include/winpr/pipe.h | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/winpr/include/winpr/file.h b/winpr/include/winpr/file.h index a264f4f4f..59979b6ce 100644 --- a/winpr/include/winpr/file.h +++ b/winpr/include/winpr/file.h @@ -335,6 +335,8 @@ WINPR_API char* GetNamedPipeNameWithoutPrefixA(LPCSTR lpName); WINPR_API char* GetNamedPipeUnixDomainSocketBaseFilePathA(void); WINPR_API char* GetNamedPipeUnixDomainSocketFilePathA(LPCSTR lpName); +WINPR_API int GetNamePipeFileDescriptor(HANDLE hNamedPipe); + #ifdef __cplusplus } #endif diff --git a/winpr/include/winpr/pipe.h b/winpr/include/winpr/pipe.h index 5c5b12f0f..f5e8ecf16 100644 --- a/winpr/include/winpr/pipe.h +++ b/winpr/include/winpr/pipe.h @@ -106,16 +106,6 @@ WINPR_API BOOL GetNamedPipeClientComputerNameW(HANDLE Pipe, LPCWSTR ClientComput #define GetNamedPipeClientComputerName GetNamedPipeClientComputerNameA #endif -/** - * Extended API - */ - -WINPR_API char* GetNamedPipeNameWithoutPrefixA(LPCSTR lpName); -WINPR_API char* GetNamedPipeUnixDomainSocketBaseFilePathA(); -WINPR_API char* GetNamedPipeUnixDomainSocketFilePathA(LPCSTR lpName); - -WINPR_API int GetNamePipeFileDescriptor(HANDLE hNamedPipe); - #ifdef __cplusplus } #endif From 117112d20feda0637bdc8be31856cce0230b45d7 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Apr 2014 10:20:47 +0200 Subject: [PATCH 3/8] sample client: fix ReceiveChannelData prototype --- client/Sample/freerdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Sample/freerdp.c b/client/Sample/freerdp.c index d5f89f7a2..065cada69 100644 --- a/client/Sample/freerdp.c +++ b/client/Sample/freerdp.c @@ -94,7 +94,7 @@ void tf_end_paint(rdpContext* context) return; } -int tf_receive_channel_data(freerdp* instance, int channelId, BYTE* data, int size, int flags, int total_size) +int tf_receive_channel_data(freerdp* instance, UINT16 channelId, BYTE* data, int size, int flags, int total_size) { return freerdp_channels_data(instance, channelId, data, size, flags, total_size); } From 81684778860a5677d07b1f0176bf55f1076095d0 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Apr 2014 10:22:53 +0200 Subject: [PATCH 4/8] sample server: fix printf format compiler warning --- server/Sample/sfreerdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 164a08ccf..68d4b3695 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -443,7 +443,7 @@ static void* tf_debug_channel_thread_func(void* arg) Stream_SetPosition(s, BytesReturned); - printf("got %d bytes\n", BytesReturned); + printf("got %lu bytes\n", BytesReturned); } Stream_Free(s, TRUE); From 291569d1e5f38f72fa8f55db7ca78a5167d3c1a7 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 16 Apr 2014 16:53:41 +0200 Subject: [PATCH 5/8] winpr: change GetKnownSubPath to use a const path --- winpr/include/winpr/path.h | 2 +- winpr/libwinpr/path/shell.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/winpr/include/winpr/path.h b/winpr/include/winpr/path.h index 811cfdb07..a69867d02 100644 --- a/winpr/include/winpr/path.h +++ b/winpr/include/winpr/path.h @@ -280,7 +280,7 @@ extern "C" { #endif WINPR_API char* GetKnownPath(int id); -WINPR_API char* GetKnownSubPath(int id, char* path); +WINPR_API char* GetKnownSubPath(int id, const char* path); WINPR_API char* GetCombinedPath(const char* basePath, const char* subPath); //#ifndef _WIN32 diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index c7ead6871..10f7b7d9d 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -258,7 +258,7 @@ char* GetKnownPath(int id) return path; } -char* GetKnownSubPath(int id, char* path) +char* GetKnownSubPath(int id, const char* path) { char* subPath; char* knownPath; From 02c4e261d1ab94636d8e7fadf5de135b507b87bc Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Thu, 17 Apr 2014 11:48:50 +0200 Subject: [PATCH 6/8] winpr-env: update Get/SetEnvironmentVariableA * set last error to ERROR_ENVVAR_NOT_FOUND in GetEnvironmentVariableA if not found * remove unused variables in SetEnvironmentVariableA * add more test cases --- winpr/libwinpr/environment/CMakeLists.txt | 6 +++ winpr/libwinpr/environment/environment.c | 13 +++--- .../TestEnvironmentSetEnvironmentVariable.c | 43 ++++++++++++++++--- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/winpr/libwinpr/environment/CMakeLists.txt b/winpr/libwinpr/environment/CMakeLists.txt index 88a5db719..e5d4ff550 100644 --- a/winpr/libwinpr/environment/CMakeLists.txt +++ b/winpr/libwinpr/environment/CMakeLists.txt @@ -31,9 +31,15 @@ add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT" set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SOVERSION ${WINPR_VERSION} PREFIX "lib") +set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS + MONOLITHIC ${MONOLITHIC_BUILD} INTERNAL + MODULE winpr + MODULES winpr-error) + if(MONOLITHIC_BUILD) else() + target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT WinPRTargets) endif() diff --git a/winpr/libwinpr/environment/environment.c b/winpr/libwinpr/environment/environment.c index 0ecc0fbb5..2dc6087ee 100644 --- a/winpr/libwinpr/environment/environment.c +++ b/winpr/libwinpr/environment/environment.c @@ -24,6 +24,7 @@ #endif #include +#include #ifndef _WIN32 @@ -151,7 +152,10 @@ DWORD GetEnvironmentVariableA(LPCSTR lpName, LPSTR lpBuffer, DWORD nSize) env = getenv(lpName); if (!env) + { + SetLastError(ERROR_ENVVAR_NOT_FOUND); return 0; + } length = strlen(env); @@ -227,19 +231,18 @@ DWORD GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, DWORD nSize) BOOL SetEnvironmentVariableA(LPCSTR lpName, LPCSTR lpValue) { - int length; - char* envstr; - if (!lpName) return FALSE; if (lpValue) { - setenv(lpName,lpValue,1); + if (0 != setenv(lpName,lpValue,1)) + return FALSE; } else { - unsetenv(lpName); + if (0 != unsetenv(lpName)) + return FALSE; } return TRUE; diff --git a/winpr/libwinpr/environment/test/TestEnvironmentSetEnvironmentVariable.c b/winpr/libwinpr/environment/test/TestEnvironmentSetEnvironmentVariable.c index a80010d19..13df05e32 100644 --- a/winpr/libwinpr/environment/test/TestEnvironmentSetEnvironmentVariable.c +++ b/winpr/libwinpr/environment/test/TestEnvironmentSetEnvironmentVariable.c @@ -3,28 +3,59 @@ #include #include #include +#include +#define TEST_NAME "WINPR_TEST_VARIABLE" +#define TEST_VALUE "WINPR_TEST_VALUE" int TestEnvironmentSetEnvironmentVariable(int argc, char* argv[]) { DWORD nSize; LPSTR lpBuffer; + DWORD error = 0; - SetEnvironmentVariableA("WINPR_TEST_VARIABLE", "WINPR_TEST_VALUE"); + SetEnvironmentVariableA(TEST_NAME, TEST_VALUE); - nSize = GetEnvironmentVariableA("WINPR_TEST_VARIABLE", NULL, 0); + nSize = GetEnvironmentVariableA(TEST_NAME, NULL, 0); + /* check if value returned is len + 1 ) */ + if (nSize != strlen(TEST_VALUE) + 1) + { + printf("GetEnvironmentVariableA not found error\n"); + return -1; + } lpBuffer = (LPSTR) malloc(nSize); - nSize = GetEnvironmentVariableA("WINPR_TEST_VARIABLE", lpBuffer, nSize); + nSize = GetEnvironmentVariableA(TEST_NAME, lpBuffer, nSize); - printf("GetEnvironmentVariableA(WINPR_TEST_VARIABLE) = %s\n" , lpBuffer); - - if (strcmp(lpBuffer, "WINPR_TEST_VALUE") != 0) + if (nSize != strlen(TEST_VALUE)) { + printf("GetEnvironmentVariableA wrong size returned\n"); + return -1; + } + + if (strcmp(lpBuffer, TEST_VALUE) != 0) + { + printf("GetEnvironmentVariableA returned value doesn't match\n"); + return -1; + } + + nSize = GetEnvironmentVariableA("__xx__notset_",lpBuffer, nSize); + error = GetLastError(); + if (0 != nSize || ERROR_ENVVAR_NOT_FOUND != error) + { + printf("GetEnvironmentVariableA not found error\n"); return -1; } free(lpBuffer); + /* clear variable */ + SetEnvironmentVariableA(TEST_NAME, NULL); + nSize = GetEnvironmentVariableA(TEST_VALUE, NULL, 0); + if ( 0 != nSize) + { + printf("SetEnvironmentVariableA failed to clear variable\n"); + return -1; + } return 0; } From 630cb35aa58f694921a5705d99850ab101c9f773 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Thu, 17 Apr 2014 12:04:26 +0200 Subject: [PATCH 7/8] transport: fix variable initialization Fixes possible problem when NLA is enabled and header verification fails. --- libfreerdp/core/transport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 59ede14da..1cac01c0f 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -988,6 +988,7 @@ int transport_check_fds(rdpTransport* transport) return status; Stream_SetPosition(transport->ReceiveBuffer, 0); + length = 0; if (transport->NlaMode) { From 76b7ecd1b7b6de5a370939dd1206b63e59f4aa93 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Thu, 17 Apr 2014 12:16:10 +0200 Subject: [PATCH 8/8] core/fastpath: fix compiler warning --- libfreerdp/core/fastpath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index 48bf5b224..31d96cc52 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -910,7 +910,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s BYTE* pDstData = NULL; UINT32 compressionFlags = 0; BYTE pad = 0; - BYTE* pSignature; + BYTE* pSignature = NULL; fpUpdatePduHeader.action = 0; fpUpdatePduHeader.secFlags = 0;