ReactOS 0.4.15-dev-7918-g2a2556c
RtlpApplyLengthFunction.c File Reference
#include "precomp.h"
#include <ntstrsafe.h>
Include dependency graph for RtlpApplyLengthFunction.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI RtlpApplyLengthFunction (IN ULONG Flags, IN ULONG Type, IN PVOID UnicodeStringOrUnicodeStringBuffer, IN NTSTATUS(NTAPI *LengthFunction)(ULONG, PUNICODE_STRING, PULONG))
 
NTSTATUS NTAPI LengthFunctionFail (ULONG Unknown, PUNICODE_STRING String, PULONG Length)
 
NTSTATUS NTAPI LengthFunctionOk (ULONG Unknown, PUNICODE_STRING String, PULONG Length)
 
NTSTATUS NTAPI LengthFunctionReturn1 (ULONG Unknown, PUNICODE_STRING String, PULONG Length)
 
NTSTATUS NTAPI LengthFunctionCopyLen (ULONG Unknown, PUNICODE_STRING String, PULONG Length)
 
 START_TEST (RtlpApplyLengthFunction)
 

Function Documentation

◆ LengthFunctionCopyLen()

NTSTATUS NTAPI LengthFunctionCopyLen ( ULONG  Unknown,
PUNICODE_STRING  String,
PULONG  Length 
)

Definition at line 42 of file RtlpApplyLengthFunction.c.

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}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by START_TEST().

◆ LengthFunctionFail()

NTSTATUS NTAPI LengthFunctionFail ( ULONG  Unknown,
PUNICODE_STRING  String,
PULONG  Length 
)

Definition at line 20 of file RtlpApplyLengthFunction.c.

21{
22 ok_int(*Length, 0);
23 /* Show that this is ignored when an error is returned */
24 *Length = 3;
26}
#define ok_int(expression, result)
Definition: atltest.h:134
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:334

Referenced by START_TEST().

◆ LengthFunctionOk()

NTSTATUS NTAPI LengthFunctionOk ( ULONG  Unknown,
PUNICODE_STRING  String,
PULONG  Length 
)

Definition at line 28 of file RtlpApplyLengthFunction.c.

29{
30 ok_int(*Length, 0);
31 *Length = 4;
32 return STATUS_SUCCESS;
33}

Referenced by START_TEST().

◆ LengthFunctionReturn1()

NTSTATUS NTAPI LengthFunctionReturn1 ( ULONG  Unknown,
PUNICODE_STRING  String,
PULONG  Length 
)

Definition at line 35 of file RtlpApplyLengthFunction.c.

36{
37 ok_int(*Length, 0);
38 *Length = 4;
39 return (NTSTATUS)1;
40}
LONG NTSTATUS
Definition: precomp.h:26

Referenced by START_TEST().

◆ RtlpApplyLengthFunction()

NTSTATUS NTAPI RtlpApplyLengthFunction ( IN ULONG  Flags,
IN ULONG  Type,
IN PVOID  UnicodeStringOrUnicodeStringBuffer,
IN   NTSTATUSNTAPI *LengthFunction)(ULONG, PUNICODE_STRING, PULONG 
)

Definition at line 446 of file path.c.

450{
454
455 if (Flags || UnicodeStringOrUnicodeStringBuffer == NULL || LengthFunction == NULL)
456 {
457 DPRINT1("ERROR: Flags=0x%x, UnicodeStringOrUnicodeStringBuffer=%p, LengthFunction=%p\n",
458 Flags, UnicodeStringOrUnicodeStringBuffer, LengthFunction);
460 }
461
462 if (Type == sizeof(UNICODE_STRING))
463 {
464 String = (PUNICODE_STRING)UnicodeStringOrUnicodeStringBuffer;
465 }
466 else if (Type == sizeof(RTL_UNICODE_STRING_BUFFER))
467 {
468 String = &((PRTL_UNICODE_STRING_BUFFER)UnicodeStringOrUnicodeStringBuffer)->String;
469 }
470 else
471 {
472 DPRINT1("ERROR: Type = %u\n", Type);
474 }
475
476 Length = 0;
477 Status = LengthFunction(0, String, &Length);
478 if (!NT_SUCCESS(Status))
479 return Status;
480
483
484 String->Length = (USHORT)(Length * sizeof(WCHAR));
485
486 if (Type == sizeof(RTL_UNICODE_STRING_BUFFER))
487 {
488 String->Buffer[Length] = UNICODE_NULL;
489 }
490
491 return STATUS_SUCCESS;
492}
Type
Definition: Type.h:7
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
Status
Definition: gdiplustypes.h:25
struct _RTL_UNICODE_STRING_BUFFER * PRTL_UNICODE_STRING_BUFFER
#define UNICODE_NULL
#define UNICODE_STRING_MAX_CHARS
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:498
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( RtlpApplyLengthFunction  )

Definition at line 50 of file RtlpApplyLengthFunction.c.

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}
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
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok_wstr(x, y)
Definition: atltest.h:130
Definition: bufpool.h:45
GLdouble n
Definition: glext.h:7729
#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)
uint16_t * PWSTR
Definition: typedefs.h:56
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53