Commit Graph

196 Commits

Author SHA1 Message Date
Armin Novak
00a5d06fc1 Fixed coverity memory leak. 2018-08-27 14:34:42 +02:00
Armin Novak
2517755d25 Fixed thread function return and parameters. 2018-03-07 14:36:55 +01:00
David Fort
917bc4b551 set some define consistency
This patch cleanup the defines to make then consistent.
2018-02-05 14:17:23 +01:00
Armin Novak
44dfaf7841 Fixed dead store warning. 2017-11-15 15:56:24 +01:00
Armin Novak
3baba6f9c0 Removed unused argument. 2017-11-15 15:56:24 +01:00
Armin Novak
0490aeb018 Fixed clang malloc integer overflow warnings. 2017-07-20 09:29:48 +02:00
Armin Novak
09d43a66f4 Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
Armin Novak
99c45405cb Fixed GetEnvironmentVariable. 2017-03-03 12:43:00 +01:00
Armin Novak
b2c29158be Scanbuild warning, argument checks and leak fixes.
* Added Stream_GetRemainingCapacity to check remaining stream size
  before writes.
* Fixed shadow server memory leak.
* Fixed lots of scanbuild warnings
* Added missing argument checks in many functions
* Added missing static function declarations
2017-03-02 18:13:43 +01:00
Armin Novak
c249705085 Fixed scanbuild warnings. 2017-02-20 13:45:19 +01:00
Ilya Shipitsin
102913e808 make cppcheck a bit happier:
[channels/printer/client/printer_cups.c:103]: (error) Resource leak: fp
[server/Mac/mf_event.c:195]: (error) Memory leak: event_queue
[server/shadow/shadow_capture.c:233]: (error) Memory leak: capture
[winpr/libwinpr/sspi/test/TestSchannel.c:440]: (error) Memory leak: lpTokenIn
[winpr/libwinpr/thread/argv.c:198]: (error) Memory leak: lpEscapedChars
[winpr/libwinpr/utils/sam.c:312]: (error) Memory leak: entry
2017-01-25 17:09:25 +05:00
Norbert Federa
f71b6b46e8 fix string format specifiers
- fixed invalid, missing or additional arguments
- removed all type casts from arguments
- added missing (void*) typecasts for %p arguments
- use inttypes defines where appropriate
2016-12-16 13:48:43 +01:00
Armin Novak
edacd7c6b7 Thread using proper function pointer type. 2016-10-07 14:07:51 +02:00
Norbert Federa
458f606934 winpr/thread: fix SwitchToThread
On some operating systems sched_yield is a stub returning returning -1.
In that case use usleep which should at least trigger a context switch
if any thread is waiting.
2016-06-02 15:38:57 +02:00
Norbert Federa
e718fb324b fix race conditions, tests and some invalid return values
Since the current winpr implementation for overlapped operations is
incomplete and buggy, all affected functions will now fail if they are
called with a set FILE_FLAG_OVERLAPPED flag or a non-null pointer to
a OVERLAPPED structure.

winpr/nt:
- use proper one-time initialization on win32
- fix TestNtCreateFile
- fix broken/incomplete _RtlAnsiStringToUnicodeString
- unimplemented functions return appropriate error codes

winpr/pipe:
- improved TestPipeCreateNamedPipe
- rewrite the completely broken TestPipeCreateNamedPipeOverlapped test

rdtk:
- improve test and don't blindly return success

winpr/synch:
- fix race condition in TestSynchTimerQueue

winpr/ssspi:
- fix TestEnumerateSecurityPackages printf output
- fix TestQuerySecurityPackageInfo printf output

winpr/environment:
- fix GetEnvironmentStrings printf output

winpr/comm:
- unimplemented functions return appropriate error codes

winpr/io:
- unimplemented functions return appropriate error codes

winpr/thread:
- implement SwitchToThread() via sched_yield()
2016-06-01 16:26:26 +02:00
Norbert Federa
1b231f9dd9 winpr/thread: fix TestThreadCreateProcess
On WIN32 TestThread now works and is expected to succeed
2016-05-25 15:47:58 +02:00
Marc-André Moreau
ceefc4b099 Merge branch 'master' of github.com:FreeRDP/FreeRDP 2016-03-07 10:19:50 -05:00
Armin Novak
68c402ac58 Removed windows module.def files.
All symbols exported from libraries are declared
using *_API defines.
2016-02-29 15:18:47 +01:00
Marc-André Moreau
d0f413db12 winpr: initial port to Universal Windows Platform (UWP) 2016-02-05 16:28:45 -05:00
Armin Novak
b6b0f57a88 Fixed compiler warning about cast. 2016-02-04 12:57:21 +01:00
Bernhard Miklautz
0cdb4f7924 Fix compiler warnings
gcc (Debian 4.9.2-10) 4.9.2

winpr/libwinpr/thread/argv.c: In function ‘CommandLineToArgvA’:
winpr/libwinpr/thread/argv.c:94:6: warning: unused variable ‘index’ [-Wunused-variable]
  int index;

winpr/libwinpr/file/test/TestFileGetStdHandle.c: In function ‘TestFileGetStdHandle’:
winpr/libwinpr/file/test/TestFileGetStdHandle.c:44:2: warning: implicit
	declaration of function ‘CloseHandle’ [-Wimplicit-function-declaration]
  CloseHandle(stdout);
    ^
libfreerdp/codec/test/TestFreeRDPRegion.c: In function ‘test_norbert2_case’:
libfreerdp/codec/test/TestFreeRDPRegion.c:697:6: warning: unused variable ‘i’ [-Wunused-variable]
  int i;

channels/cliprdr/server/cliprdr_main.c: In function ‘cliprdr_server_receive_format_list’:
channels/cliprdr/server/cliprdr_main.c:636:24: warning: unused variable ‘cliprdr’ [-Wunused-variable]
  CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
                        ^
channels/cliprdr/server/cliprdr_main.c: In function ‘cliprdr_server_init’:
channels/cliprdr/server/cliprdr_main.c:1097:24: warning: unused variable ‘cliprdr’ [-Wunused-variable]
  CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
2015-11-09 19:26:34 +01:00
Norbert Federa
d6b5b906f4 winpr/argv: fix CommandLineToArgvA memory access
- fixed access of unitialized memory beyond terminating null
- minor simplifications
2015-11-05 18:10:05 +01:00
Bernhard Miklautz
c70559d128 winpr API: add EnvironmentBlockToEnvpA
* expose EnvironmentBlockToEnvpA
* cleanup includes in process.c
* removed unused "flag" variable in _CreateProcessExA
* make ProcessHandleCloseHandle static
2015-10-23 18:38:42 +02:00
Bernhard Miklautz
72f13aeacb CreateProcess: add stdin/out/err redirection
When launching a new process stdin/stdout/stderr can be redirected by
passing the corresponding HANDLEs in the passed lpStartupInfo structure.
This is required for example if a pipe should be used as stdin/stdout.

If set in lpStartupInfo the file descriptor of the passed handle is
now used. The test was updated accordingly.
2015-08-28 10:41:23 +02:00
Marc-André Moreau
611c194f80 Merge pull request #2801 from bmiklautz/fix/thread
winpr/thread: small cleanups
2015-07-28 08:47:06 -04:00
Bernhard Miklautz
c3ea07f3d9 winpr/thread: don't close invalid file descriptors
In case the file descriptor is -1 don't call close.
2015-07-24 14:57:47 +02:00
Bernhard Miklautz
81d422588e winrp/thread: don't call pthread_exit on return
As the pthread_exit man page states pthread_exit is called implicitly
when the start function returns.
2015-07-24 14:52:31 +02:00
Bernhard Miklautz
ca150f2255 winpr/thread: small cleanups
Also adds error checking of winpr_StartThread in winpr_StartThread.
2015-07-23 11:52:49 +02:00
Armin Novak
9af2e22d51 Fixed mutex unlocking and return checks. 2015-07-16 17:07:29 +02:00
Bernhard Miklautz
68e8569110 winpr/synch: remove the dependency on winsock.h
winsock.h pulls in a lot of defines and dependencies that are not
required and partially unwanted in winpr's core (for parts that are not
related to network). In order to get rid of this dependency and have an
independent defines for extended winpr functions the WINPR_FD_* defines
are used internally (and for exposed functions). Where required, like in
WSAEventSelect, the FD_* is mapped to WINPR_FD_*.
2015-07-14 11:39:41 +02:00
Armin Novak
d18b0fbeb4 Handle API updated. 2015-07-03 09:52:52 +02:00
Bernhard Miklautz
c7adb569ff CreateProcess: fix setting of default handler
If SA_SIGINFO isn't set in the flags sa_handler is used
instead of sa_sigaction.

This fixes also the compiler warning:

FreeRDP/winpr/libwinpr/thread/process.c: In function ‘_CreateProcessExA’:
FreeRDP/winpr/libwinpr/thread/process.c:282:20: warning: assignment from
       incompatible pointer type [enabled by default]
2015-07-02 12:25:48 +02:00
Bernhard Miklautz
be53e9e029 CreateProcess: two fixes
* change to lpCurrentDirectory if set even if no token was supplied
* fix wrong check - add missing !

This was part of akallabeth's PR #2714.
2015-07-02 12:05:46 +02:00
Norbert Federa
c84e90bf06 winpr: fix CreateProcess signal handler issues
The calling thread of CreateProcess can be in any library and
can have arbitrary signal masks and handlers.

We now save the caller's mask and  block all signals before forking.
After fork:
- child resets the handlers and unblocks all signals.
- parent restores the caller's original signal mask.
2015-07-02 11:28:06 +02:00
Bernhard Miklautz
ab8d83c8fc winpr/thread: fix test compilation on windows
Use DWORD instead of QWORD.
2015-06-22 19:09:59 +02:00
Emmanuel Ledoux
de1a21eadd winpr-thread: added HP's copyright 2015-05-27 18:24:56 +02:00
Emmanuel Ledoux
206714a270 winpr-thread: thread_list's synchronization based on a pthread_cond_t 2015-05-27 18:15:17 +02:00
Emmanuel Ledoux
f74cd12df2 winpr-thread: a better error message and comments about thread_list 2015-05-26 18:15:57 +02:00
Emmanuel Ledoux
56f34582c7 winpr-thread: added an assertion to enforce that thread_list is correctly set 2015-05-26 17:55:27 +02:00
Emmanuel Ledoux
93127e0a7a winpr-thread: thread_list's synchronization based on an Event 2015-05-26 17:40:34 +02:00
Emmanuel Ledoux
f94ab0033b winpr-thread: better error message upon a failure of TestThreadExitThread 2015-05-22 19:17:30 +02:00
Emmanuel Ledoux
6f5de27081 winpr-thread:
- added the unit test: TestThreadExitThread
  - fix: ensure thread_list to be up to date before to call ExitThread()
  - possibly resolved: Problems with serial redirection #2389
2015-05-22 18:28:10 +02:00
Marc-André Moreau
b9c1cddc2e Merge pull request #2583 from bceverly/OpenBSD-cleanup
Two minor source code changes to remove warnings
2015-05-21 10:17:54 -04:00
Bryan Everly
a3a3efe31e Fixed mistake with bitwise operator in previous two commits 2015-05-20 12:17:05 -04:00
Bryan Everly
80af54b169 Moved thread code to OpenBSD only 2015-05-20 10:52:24 -04:00
Hardening
f8120919af Add checks for some XXX_New and XXX_Add functions
Based on PR #2616
2015-05-18 11:28:00 +02:00
Norbert Federa
1eff1a345e free can handle NULL perfectly fine 2015-05-11 09:07:39 +02:00
Norbert Federa
c77def3048 Fix unchecked CreateMutex calls 2015-05-07 13:27:49 +02:00
Bryan Everly
9865854f3c Simplified random byte stream generation code to use SSL RAND_bytes() and also eliminated two more compiler warnings. 2015-05-05 12:33:44 -04:00
Bernhard Miklautz
a8c44f15c0 winpr: small fixes and cleanups
Update the pull request and integrate the latest comments and
suggestions.

* TestLibrary*: fix typo in error message
* TestPipeCreateNamedPipeOverlapped: free possibly allocated memory
* smartcard_pcsc.c: format fix
* process.c: add missing NULL check
* MessageQueue.c: delete possibly initialized critical section on error
2015-04-08 11:34:37 +02:00
Bernhard Miklautz
850de59b55 winpr: add checks for *alloc
Add missing checks if memory allocation was successful. Also adapt
caller(s) when possible.
2015-04-08 11:34:37 +02:00
Armin Novak
b3ea02a777 Removed INVALID_HANDLE_VALUE from types not using it. 2015-03-31 15:18:45 +02:00
Armin Novak
afe8bd2a86 Fixed missing checks for invalid handle. 2015-03-31 15:18:45 +02:00
Bernhard Miklautz
1d7b3694a9 Integrate feedback from pull request (#2492)
* shell: add missing NULL checks
* thread: handle case where HAVE_EVENTFD_H isn't defined
* wlog: return NULL instead of 0
* wlog: use g_RootLog instead of WLog_GetRoot
  otherwise a new root might be initialized on uninit
* indentation and style fixes
2015-03-25 17:38:21 +01:00
Bernhard Miklautz
3c7662517c hardening
Start to add missing checks for:
* *alloc
* *_New
2015-03-25 17:38:21 +01:00
David FORT
52bd4469d9 Make handle operations static
This patch moves the handle operations in a static struct.
2015-03-16 10:31:26 +01:00
Armin Novak
9153af6a3e Using new handle cleanup structure 2015-03-11 17:57:01 +01:00
Armin Novak
465d8ec688 Using new handle cleanup structure 2015-03-11 17:57:01 +01:00
Bernhard Miklautz
582856d142 winpr/process: handle pids <= 0
TerminateProcess shouldn't call kill if the PID is <=0 because this has
unwanted effects (and is not what TerminateProcess should do):

* with PID == 0 any process in the same process group gets the signal
  sent
* with PID == -1 *every* processes that the running users has
  permissions to gets the signal sent
* with PID < -1 the process within the same process group and -PID gets
  the signal send

For more details see kill(2).
2015-02-09 14:07:14 +01:00
Emmanuel Ledoux
4aeaffa286 libwinpr: better indentation 2015-01-28 12:43:20 +01:00
Emmanuel Ledoux
ab4a744b08 libwinpr: attempt to fix TerminateThread(...).
The following sequence should not hang forever anymore: TerminateThread(thread, 0); WaitForSingleObject(thread, INFINTE);
2015-01-27 21:05:40 +01:00
Armin Novak
122d1c43f4 Prettiefied WLog messages. 2015-01-20 11:04:23 +01:00
Armin Novak
44904ad5d2 Fixed a race condition at thread creation
The thread structure was incorrectly updated after the thread
function was already running. This caused a race condition with
thread exiting. When the thread function returned before the structure
was correctly updated, the exit routine cleaned up the handle as
it was incorrectly marked not started.
2015-01-16 11:26:31 +01:00
Armin Novak
4d8c91b0fe Fixed missing declarations. 2014-12-07 01:15:49 +01:00
Armin Novak
8a6c4396b2 Fixed memory leak. 2014-12-07 01:04:30 +01:00
Marc-André Moreau
6ccce86140 Merge branch 'master' of github.com:FreeRDP/FreeRDP
Conflicts:
	winpr/libwinpr/thread/thread.c
2014-12-03 10:10:50 -05:00
Martin Haimberger
7897de057b fixed compiler warning 2014-12-02 00:36:46 -08:00
Martin Haimberger
fa6d551676 changed processhandle handling to new system 2014-12-02 00:08:10 -08:00
Martin Haimberger
128458d380 fixing memoryleak by introducing a nonehandle
In CreateProcess the non functional thread
handle was leaked.
2014-12-01 23:53:58 -08:00
Marc-André Moreau
0818846d7c winpr: fix build warnings 2014-11-21 15:12:49 -05:00
Marc-André Moreau
871339da88 Merge branch 'master' of github.com:awakecoding/FreeRDP
Conflicts:
	winpr/libwinpr/thread/thread.c
2014-11-20 11:51:18 -05:00
Marc-André Moreau
2afcac7838 libwinpr-thread: fix non-blocking internal pipe-based event on OS X 2014-11-20 11:48:02 -05:00
Armin Novak
7b9bf1a504 Fixed uninitialized variable. 2014-11-16 17:02:36 +01:00
Armin Novak
fb5d20f338 Fixed NULL pointer dereference. 2014-11-16 16:51:04 +01:00
Armin Novak
53450b6423 Checking setgid before calling initgroups now. 2014-11-16 15:59:26 +01:00
Armin Novak
51cb07b0f4 Fixed use after free. 2014-11-16 15:21:13 +01:00
Armin Novak
f5a78d9c98 Fixed use after free. 2014-11-16 14:44:30 +01:00
Armin Novak
2d7311b253 Fixed type of stack trace variables. 2014-11-11 21:00:03 +01:00
Marc-André Moreau
68ee5df7d9 winpr: fix build warnings 2014-11-11 11:21:34 -05:00
Armin Novak
5bf25fd87c Fixed missing includes and typo. 2014-10-27 11:45:39 +01:00
Armin Novak
8f98f28ce8 Fixed merge errors. 2014-10-27 11:39:02 +01:00
Armin Novak
a6eff65259 Fixed ExitThread, now running pthread_exit and setting event. 2014-10-27 11:28:13 +01:00
Armin Novak
02a4d77da1 Setting exited flag in TerminateThread now to allow setting return code. 2014-10-27 11:28:12 +01:00
Armin Novak
7ef2bd3ca0 Added joined flag. 2014-10-27 11:28:12 +01:00
Armin Novak
5122ce939a Added funcion name to debug messages.
Fixed setting of started flag for threads.
pthred_exit now used correct return value argument.
Return value now also set when terminating thread.
2014-10-27 11:23:18 +01:00
Armin Novak
56ae609943 Removed WaitForSingleObject in reset_event, joining thread when not allowed. 2014-10-27 11:23:17 +01:00
Armin Novak
8a352c6f63 Fixed thread cleanup, now saving state of started flag, setting event and
then cleaning up the thread resources.
2014-10-27 11:23:17 +01:00
Armin Novak
f80f5621ac Fixed thread handle cleanup, checking for resource cleanup now before resetting flags. 2014-10-27 11:23:17 +01:00
Armin Novak
8de2868281 Preferring exit code from ExitThread now over thread function return. 2014-10-27 11:23:16 +01:00
Armin Novak
3d7b65a430 Now using thread_launcher function to properly clean up thread resources at exit. 2014-10-27 11:23:15 +01:00
Armin Novak
c304f457cf Implemented thread handling for WaitForMultipleObjects.
Implemented thread specific functions.
2014-10-27 11:23:15 +01:00
Armin Novak
b22b897389 Reformatted changed files. 2014-09-09 16:32:22 +02:00
Armin Novak
7e3a1b3073 Now using macro to generate module specific log tag. 2014-09-09 16:32:04 +02:00
Armin Novak
28ece6bb46 Replaced stdio logging with WLog 2014-09-09 16:31:46 +02:00
Bernhard Miklautz
6a49bcfe40 winpr: always build "monolitic"
winpr is now always build as single library.
The build option MONOLITHIC_BUILD doesn't influence this behavior anymore.

The only exception is winpr-makecert-tool which is still build as extra
library.

This obsoletes complex_libraries for winpr.
2014-07-10 11:10:58 +02:00
Marc-André Moreau
cd35b2772f libwinpr-thread: fix compilation on Android 2014-05-22 15:32:49 -04:00
Marc-André Moreau
ae6c778eb7 libwinpr-smartcard: modifying threading 2014-05-11 05:23:30 -04:00
Bernhard Miklautz
b817e92e5e cmake: mark required libraries for export 2014-04-23 10:16:02 +02:00
Hardening
1d1844aabd Treat OOM cases 2014-04-09 16:07:06 +02:00
Bernhard Miklautz
24c67267a3 winpr: add cwd support in CreateProcess* 2014-02-13 14:31:11 +01:00