ReactOS 0.4.16-dev-122-g325d74c
RtlpApplyLengthFunction.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Test for RtlpApplyLengthFunction
5 * COPYRIGHT: Copyright 2021 Mark Jansen <mark.jansen@reactos.org>
6 */
7
8#include "precomp.h"
9#include <ntstrsafe.h>
10
11
16 IN PVOID UnicodeStringOrUnicodeStringBuffer,
17 IN NTSTATUS(NTAPI*LengthFunction)(ULONG, PUNICODE_STRING, PULONG));
18
19
21{
22 ok_int(*Length, 0);
23 /* Show that this is ignored when an error is returned */
24 *Length = 3;
26}
27
29{
30 ok_int(*Length, 0);
31 *Length = 4;
32 return STATUS_SUCCESS;
33}
34
36{
37 ok_int(*Length, 0);
38 *Length = 4;
39 return (NTSTATUS)1;
40}
41
43{
44 /* Use Buffer as length, to show that the function does not interpret the contents at all */
45 *Length = (ULONG)(ULONG_PTR)String->Buffer;
46 return STATUS_SUCCESS;
47}
48
49
51{
53 /* Show that RtlpApplyLengthFunction does not interpret anything in the UNICODE_STRING */
54 UNICODE_STRING String = { 1, 2, (PWSTR)3 };
56 WCHAR StaticBuffer[10] = { 0 };
57 ULONG n;
58
60 ok_int(String.Length, 1);
62
64 ok_int(String.Length, 1);
66
67 /* Show that no flag is accepted */
68 for (n = 0; n < 32; ++n)
69 {
71 ok_int(String.Length, 1);
73 }
74
76 ok_int(String.Length, 1);
78
79 /* Still Length 1 when the function returns an error */
81 ok_int(String.Length, 1);
83
85 ok_int(String.Length, 8); /* Value returned from LengthFunction is multiplied by sizeof(WCHAR) */
87
88 String.Length = 1;
90 ok_int(String.Length, 8);
91 ok_hex(Status, STATUS_SUCCESS); /* Returns STATUS_SUCCESS regardless of success code from the function */
92
93 /* Show max length */
95 String.Length = 2;
99
100 String.Buffer = (PWCHAR)(UNICODE_STRING_MAX_CHARS + 1);
101 String.Length = 2;
103 ok_int(String.Length, 2); /* Unchanged */
105
106 /* Now try it with the RTL_UNICODE_STRING_BUFFER, this works fine on 2k3 but not on Win10!! */
107 RtlInitBuffer(&Buffer.ByteBuffer, (PUCHAR)StaticBuffer, sizeof(StaticBuffer));
108 /* In this case the Buffer is modified, so we should have a valid UNICODE_STRING! */
109 Buffer.String.Length = 5;
110 Buffer.String.MaximumLength = Buffer.ByteBuffer.StaticSize;
111 Buffer.String.Buffer = (PWSTR)Buffer.ByteBuffer.Buffer;
112 wcscpy(StaticBuffer, L"123456789");
113
114 /* Show that no flag is accepted */
115 for (n = 0; n < 32; ++n)
116 {
118 ok_int(Buffer.String.Length, 5);
120 ok_wstr(StaticBuffer, L"123456789");
121 }
122
123 /* Still Length 1 when the function returns an error */
125 ok_int(Buffer.String.Length, 5);
127 ok_wstr(StaticBuffer, L"123456789");
128
130 ok_int(Buffer.String.Length, 8); /* Value returned from LengthFunction is multiplied by sizeof(WCHAR) */
132 ok_wstr(StaticBuffer, L"1234"); /* Buffer is truncated */
133 ok_wstr(StaticBuffer + 5, L"6789"); /* Rest is not overwritten*/
134
135 Buffer.String.Length = 1;
136 wcscpy(StaticBuffer, L"123456789");
138 ok_int(Buffer.String.Length, 8);
139 ok_hex(Status, STATUS_SUCCESS); /* Returns STATUS_SUCCESS regardless of success code from the function */
140 ok_wstr(StaticBuffer, L"1234"); /* Buffer is truncated */
141 ok_wstr(StaticBuffer + 5, L"6789"); /* Rest is not overwritten*/
142}
143
NTSTATUS NTAPI LengthFunctionOk(ULONG Unknown, PUNICODE_STRING String, PULONG Length)
NTSTATUS NTAPI LengthFunctionCopyLen(ULONG Unknown, PUNICODE_STRING String, PULONG Length)
NTSTATUS NTAPI LengthFunctionReturn1(ULONG Unknown, PUNICODE_STRING String, PULONG Length)
NTSTATUS NTAPI LengthFunctionFail(ULONG Unknown, PUNICODE_STRING String, PULONG Length)
NTSTATUS NTAPI RtlpApplyLengthFunction(IN ULONG Flags, IN ULONG Type, IN PVOID UnicodeStringOrUnicodeStringBuffer, IN NTSTATUS(NTAPI *LengthFunction)(ULONG, PUNICODE_STRING, PULONG))
Definition: path.c:446
Type
Definition: Type.h:7
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok_wstr(x, y)
Definition: atltest.h:130
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define NTSTATUS
Definition: precomp.h:21
Status
Definition: gdiplustypes.h:25
GLdouble n
Definition: glext.h:7729
@ Unknown
Definition: i8042prt.h:114
#define UNICODE_STRING_MAX_CHARS
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:334
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:498
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define STATUS_SUCCESS
Definition: shellext.h:65
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180