FreeRDP/winpr/libwinpr
Samuel Holland 6931f54fad Fix NTLM AvPair lists
There were two main issues here: First, the `ntlm_av_pair_add` and
`ntlm_av_pair_add_copy` were not adding a new `MsvAvEOL` to the end of
the list to replace the one they overwrote. This caused the second call
to one of those functions to fail (since it couldn't find the
terminator), which was the source of the test failure. It also caused
`ntlm_av_pair_list_length` and `ntlm_print_av_pair_list` to read out of
bounds until they happened to find the right word.

Second, several bounds checks were wrong or missing. For example,
`ntlm_av_pair_add` does not ensure that the value fits inside the list.
And `ntlm_av_pair_get_len` and `ntlm_av_pair_get_value_pointer` can
return error codes or NULL, but those error returns were ignored, and
the values used anyway (such as in `ntlm_av_pair_add_copy`).

This fixes the list handling code to have the invariant that all
functions returning `NTLM_AV_PAIR*` only return non-`NULL` if the entire
returned `AvPair` is within bounds. This removes the need for the length
parameter in functions that only operate on a single `AvPair`. This
check is performed by the new `ntlm_av_pair_check` helper, which is
added in some new places and used to simplify the code in others.

Other issues fixed along the way include:
 - `ntlm_av_pair_list_length` did not cast to `PBYTE`, so it was
   returning the number of `NTLM_AV_PAIR`-sized chunks (which was
   possibly not even an integer) instead of the number of bytes
 - I removed an impossible check for `offset <= 0` in
   `ntlm_av_pair_get_next_pointer`
 - The assertion that `Value != NULL` and the call to `CopyMemory` are
   only necessary if `AvLen` is nonzero
 - `ntlm_av_pair_get_next_pointer` (renamed to `ntlm_av_pair_next`)
   could be declared `static`

With this commit, TestNTLM now passes on powerpc64.

```
$ ./Testing/TestSspi TestNTLM
NTLM_NEGOTIATE (length = 40):
NTLM_CHALLENGE (length = 168):
NTLM_AUTHENTICATE (length = 352):
$ echo $?
0
```

Fixes #5250
2019-03-17 20:40:13 -05:00
..
asn1 First shot on fixing over linking 2016-03-29 18:14:34 +02:00
bcrypt First shot on fixing over linking 2016-03-29 18:14:34 +02:00
clipboard Avoid building POSIX clipboard if WIN32 2019-01-09 10:04:38 +01:00
com First shot on fixing over linking 2016-03-29 18:14:34 +02:00
comm Fixed another bunch of warnings. 2018-10-24 14:36:12 +02:00
credentials Removed windows module.def files. 2016-02-29 15:18:47 +01:00
credui fix string format specifiers 2016-12-16 13:48:43 +01:00
crt Added _wcsnlen function for WCHAR string length. 2018-12-10 12:39:32 +01:00
crypto Pull in the LibreSSL compatibility patches from FreeBSD 2018-05-01 08:43:36 -05:00
dsparse Fix #4239: Various memory leaks 2017-12-12 11:40:48 +01:00
environment Fixed sign-compare warning 2019-01-30 18:05:49 +01:00
error Fixed thread function return and parameters. 2018-03-07 14:36:55 +01:00
file Merge pull request #5139 from akallabeth/drive_hotplug_shutdown_crash_fix 2019-02-07 10:08:41 +01:00
handle Ignore INVALID_HANDLE_VALUE during clang scanbuild runs. 2019-02-21 12:21:51 +01:00
heap Removed windows module.def files. 2016-02-29 15:18:47 +01:00
input Sun keyboard 2017-08-04 13:09:32 +02:00
interlocked Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
io winpr/io/device: Fix leak found by covscan 2018-08-22 14:34:02 +02:00
library Fixed warnings of uninitialized struct values. 2018-10-24 13:25:18 +02:00
locale First shot on fixing over linking 2016-03-29 18:14:34 +02:00
memory First shot on fixing over linking 2016-03-29 18:14:34 +02:00
nt Fix #4239: Various memory leaks 2017-12-12 11:40:48 +01:00
path Fixed wide character comparison. 2019-02-08 09:20:58 +01:00
pipe Fixed clang analyzer false positive memory leaks. 2019-01-29 17:17:30 +01:00
pool Fixed threadpool work function return and arguments. 2018-03-07 14:36:55 +01:00
registry Replaced atoi 2017-11-15 15:52:16 +01:00
rpc Fixed NULL dereferences and uninitialized values 2019-01-30 16:11:10 +01:00
security First shot on fixing over linking 2016-03-29 18:14:34 +02:00
shell Removed use of strcpy. 2018-08-27 14:34:09 +02:00
smartcard Fixed another bunch of warnings. 2018-10-24 14:36:12 +02:00
sspi Fix NTLM AvPair lists 2019-03-17 20:40:13 -05:00
sspicli Fixed warnings of uninitialized struct values. 2018-10-24 13:25:18 +02:00
synch Respect return value from SetEvent and abort creation. 2019-02-21 12:21:51 +01:00
sysinfo fix clang warnings, directly include wtypes.h (#4097) 2017-08-29 09:09:38 +02:00
thread Fixed return check in SwitchToThread 2019-01-18 13:02:30 +01:00
timezone Fixed #5093: Try to read timezone from java TimeZone first 2018-12-05 10:41:14 +01:00
utils Merge pull request #5027 from akallabeth/wlog_off_fix 2019-02-28 10:55:12 +01:00
winhttp winpr: always build "monolitic" 2014-07-10 11:10:58 +02:00
winsock winpr/winsock: Fix leak found by covscan 2018-08-23 09:11:24 +02:00
wnd fix string format specifiers 2016-12-16 13:48:43 +01:00
wtsapi Pointer arithmetics require lvalue 2019-01-09 11:13:38 +01:00
CMakeLists.txt Use lowercase for includes and libs 2019-01-09 09:36:28 +01:00
dummy.c freerdp: various missing link dependencies and symbol exports 2013-09-03 21:48:26 -04:00
log.h Moved logging defines to main logger. 2014-09-09 16:32:04 +02:00