[channels,rdpear] fix inconsistencies in ndr.c/h

This commit is contained in:
akallabeth 2024-09-13 12:16:19 +02:00
parent 1c161b0270
commit f0a73e3e9c
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
2 changed files with 54 additions and 43 deletions

View File

@ -29,7 +29,6 @@
#define NDR_MAX_CONSTRUCTS 16
#define NDR_MAX_DEFERRED 50
/** @brief */
struct NdrContext_s
{
BYTE version;
@ -113,13 +112,13 @@ void ndr_context_free(NdrContext* context)
}
}
void ndr_context_bytes_read(NdrContext* context, size_t len)
static void ndr_context_bytes_read(NdrContext* context, size_t len)
{
WINPR_ASSERT(context);
context->indentLevels[context->currentLevel] += len;
}
void ndr_context_bytes_written(NdrContext* context, size_t len)
static void ndr_context_bytes_written(NdrContext* context, size_t len)
{
ndr_context_bytes_read(context, len);
}
@ -284,8 +283,10 @@ BOOL ndr_end_constructed(NdrContext* context, wStream* s)
Stream_StaticInit(&staticS, Stream_Buffer(s) + offset, 4);
/* len */
size_t len = Stream_GetPosition(s) - (offset + 8);
if (!ndr_write_uint32(context, &staticS, len))
const size_t len = Stream_GetPosition(s) - (offset + 8);
if (len > UINT32_MAX)
return FALSE;
if (!ndr_write_uint32(context, &staticS, (UINT32)len))
return FALSE;
return TRUE;
@ -432,8 +433,7 @@ SIMPLE_TYPE_IMPL(UINT64, uint64)
WINPR_ASSERT(context); \
WINPR_ASSERT(s); \
WINPR_ASSERT(hints); \
return ndr_read_uconformant_array(context, s, (NdrArrayHints*)hints, ndr_##TYPE##_descr(), \
(void*)v); \
return ndr_read_uconformant_array(context, s, hints, ndr_##TYPE##_descr(), v); \
} \
\
BOOL ndr_write_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, \
@ -442,16 +442,15 @@ SIMPLE_TYPE_IMPL(UINT64, uint64)
WINPR_ASSERT(context); \
WINPR_ASSERT(s); \
WINPR_ASSERT(hints); \
NdrArrayHints* ahints = (NdrArrayHints*)hints; \
return ndr_write_uconformant_array(context, s, ahints->count, ndr_##TYPE##_descr(), \
(const void*)v); \
const NdrArrayHints* ahints = (const NdrArrayHints*)hints; \
return ndr_write_uconformant_array(context, s, ahints->count, ndr_##TYPE##_descr(), v); \
} \
void ndr_destroy_##TYPE##Array(NdrContext* context, const void* hints, void* obj) \
{ \
WINPR_ASSERT(context); \
WINPR_ASSERT(obj); \
WINPR_ASSERT(hints); \
NdrArrayHints* ahints = (NdrArrayHints*)hints; \
const NdrArrayHints* ahints = (const NdrArrayHints*)hints; \
NdrMessageType descr = ndr_##TYPE##_descr(); \
if (descr->destroyFn) \
{ \
@ -477,7 +476,7 @@ SIMPLE_TYPE_IMPL(UINT64, uint64)
WINPR_ASSERT(context); \
WINPR_ASSERT(s); \
WINPR_ASSERT(hints); \
return ndr_read_uconformant_varying_array(context, s, (NdrVaryingArrayHints*)hints, \
return ndr_read_uconformant_varying_array(context, s, (const NdrVaryingArrayHints*)hints, \
ndr_##TYPE##_descr(), v); \
} \
BOOL ndr_write_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \
@ -486,7 +485,7 @@ SIMPLE_TYPE_IMPL(UINT64, uint64)
WINPR_ASSERT(context); \
WINPR_ASSERT(s); \
WINPR_ASSERT(hints); \
return ndr_write_uconformant_varying_array(context, s, (NdrVaryingArrayHints*)hints, \
return ndr_write_uconformant_varying_array(context, s, (const NdrVaryingArrayHints*)hints, \
ndr_##TYPE##_descr(), v); \
} \
\
@ -495,7 +494,7 @@ SIMPLE_TYPE_IMPL(UINT64, uint64)
ndr_read_##TYPE##VaryingArray, \
ndr_write_##TYPE##VaryingArray, \
NULL, \
(NDR_DUMP_FN)NULL }; \
NULL }; \
\
NdrMessageType ndr_##TYPE##VaryingArray_descr(void) \
{ \
@ -643,7 +642,7 @@ BOOL ndr_struct_read_fromDescr(NdrContext* context, wStream* s, const NdrStructD
if (field->hintsField >= 0)
{
/* computes the address of the hints field if any */
WINPR_ASSERT(field->hintsField < descr->nfields);
WINPR_ASSERT((size_t)field->hintsField < descr->nfields);
const NdrFieldStruct* hintsField = &descr->fields[field->hintsField];
hints = (BYTE*)target + hintsField->structOffset;
@ -711,17 +710,17 @@ BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStruct
for (size_t i = 0; i < descr->nfields; i++)
{
const NdrFieldStruct* field = &descr->fields[i];
BYTE* ptr = (BYTE*)src + field->structOffset;
const BYTE* ptr = (const BYTE*)src + field->structOffset;
void* hints = NULL;
const void* hints = NULL;
if (field->hintsField >= 0)
{
/* computes the address of the hints field if any */
WINPR_ASSERT(field->hintsField < descr->nfields);
WINPR_ASSERT((size_t)field->hintsField < descr->nfields);
const NdrFieldStruct* hintsField = &descr->fields[field->hintsField];
hints = (BYTE*)src + hintsField->structOffset;
hints = (const BYTE*)src + hintsField->structOffset;
}
switch (field->pointerType)
@ -731,7 +730,7 @@ BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStruct
{
ndr_refid ptrId = NDR_PTR_NULL;
BOOL isNew = 0;
ptr = *(void**)ptr;
ptr = *(const void**)ptr;
if (!ptr && field->pointerType == NDR_POINTER_NON_NULL)
{
@ -754,8 +753,8 @@ BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStruct
}
deferred->name = field->name;
deferred->hints = hints;
deferred->target = ptr;
deferred->hints = WINPR_CAST_CONST_PTR_AWAY(hints, void*);
deferred->target = WINPR_CAST_CONST_PTR_AWAY(ptr, void*);
deferred->msg = field->typeDescr;
ndeferred++;
}
@ -792,13 +791,13 @@ void ndr_struct_dump_fromDescr(wLog* logger, UINT32 lvl, size_t identLevel,
for (size_t i = 0; i < descr->nfields; i++)
{
const NdrFieldStruct* field = &descr->fields[i];
BYTE* ptr = (BYTE*)obj + field->structOffset;
const BYTE* ptr = (const BYTE*)obj + field->structOffset;
switch (field->pointerType)
{
case NDR_POINTER:
case NDR_POINTER_NON_NULL:
ptr = *(void**)ptr;
ptr = *(const void**)ptr;
break;
case NDR_NOT_POINTER:
break;
@ -830,7 +829,7 @@ void ndr_struct_destroy(NdrContext* context, const NdrStructDescr* descr, void*
if (field->hintsField >= 0)
{
/* computes the address of the hints field if any */
WINPR_ASSERT(field->hintsField < descr->nfields);
WINPR_ASSERT((size_t)field->hintsField < descr->nfields);
const NdrFieldStruct* hintsField = &descr->fields[field->hintsField];
hints = (BYTE*)pptr + hintsField->structOffset;
@ -863,7 +862,7 @@ typedef struct
ndr_refid* presult;
} FindValueArgs;
BOOL findValueRefFn(const void* key, void* value, void* parg)
static BOOL findValueRefFn(const void* key, void* value, void* parg)
{
WINPR_ASSERT(parg);

View File

@ -23,6 +23,31 @@
#include <winpr/stream.h>
#include <freerdp/api.h>
#define NDR_PTR_NULL (0UL)
#define NDR_SIMPLE_TYPE_DECL(LOWER, UPPER) \
BOOL ndr_read_##LOWER(NdrContext* context, wStream* s, UPPER* v); \
BOOL ndr_read_##LOWER##_(NdrContext* context, wStream* s, const void* hints, void* v); \
BOOL ndr_write_##LOWER(NdrContext* context, wStream* s, UPPER v); \
BOOL ndr_write_##LOWER##_(NdrContext* context, wStream* s, const void* hints, const void* v); \
extern const NdrMessageDescr ndr_##LOWER##_descr_s; \
NdrMessageType ndr_##LOWER##_descr(void)
#define NDR_ARRAY_OF_TYPE_DECL(TYPE, UPPERTYPE) \
BOOL ndr_read_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, void* v); \
BOOL ndr_write_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, \
const void* v); \
void ndr_destroy_##TYPE##Array(NdrContext* context, const void* hints, void* obj); \
extern const NdrMessageDescr ndr_##TYPE##Array_descr_s; \
NdrMessageType ndr_##TYPE##Array_descr(void); \
\
BOOL ndr_read_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \
void* v); \
BOOL ndr_write_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \
const void* v); \
extern const NdrMessageDescr ndr_##TYPE##VaryingArray_descr_s; \
NdrMessageType ndr_##TYPE##VaryingArray_descr(void)
#ifdef __cplusplus
extern "C"
{
@ -31,7 +56,6 @@ extern "C"
typedef struct NdrContext_s NdrContext;
typedef UINT32 ndr_refid;
#define NDR_PTR_NULL (0UL)
typedef BOOL (*NDR_READER_FN)(NdrContext* context, wStream* s, const void* hints, void* target);
typedef BOOL (*NDR_WRITER_FN)(NdrContext* context, wStream* s, const void* hints,
@ -96,7 +120,7 @@ extern "C"
NdrMessageType msg;
} NdrDeferredEntry;
void ndr_context_free(NdrContext* pcontext);
void ndr_context_free(NdrContext* context);
static INLINE void ndr_context_destroy(NdrContext** pcontext)
{
@ -118,25 +142,13 @@ extern "C"
BOOL ndr_write_header(NdrContext* context, wStream* s);
BOOL ndr_write_uint8(NdrContext* context, wStream* s, BYTE v);
BOOL ndr_write_uint8_(NdrContext* context, wStream* s, const void* hints, const void* v);
NdrMessageType ndr_uint8_descr(void);
#define NDR_SIMPLE_TYPE_DECL(LOWER, UPPER) \
BOOL ndr_read_##LOWER(NdrContext* context, wStream* s, UPPER* v); \
BOOL ndr_write_##LOWER(NdrContext* context, wStream* s, UPPER v); \
BOOL ndr_write_##LOWER##_(NdrContext* context, wStream* s, const void* hints, const void* v); \
extern const NdrMessageDescr ndr_##LOWER##_descr_s; \
NdrMessageType ndr_##LOWER##_descr(void)
NDR_SIMPLE_TYPE_DECL(uint8, UINT8);
NDR_SIMPLE_TYPE_DECL(uint16, UINT16);
NDR_SIMPLE_TYPE_DECL(uint32, UINT32);
NDR_SIMPLE_TYPE_DECL(uint64, UINT64);
extern const NdrMessageDescr ndr_uint8Array_descr_s;
NdrMessageType ndr_uint8Array_descr(void);
NdrMessageType ndr_uint16Array_descr(void);
NdrMessageType ndr_uint16VaryingArray_descr(void);
NDR_ARRAY_OF_TYPE_DECL(uint8, BYTE);
NDR_ARRAY_OF_TYPE_DECL(uint16, UINT16);
BOOL ndr_skip_bytes(NdrContext* context, wStream* s, size_t nbytes);
BOOL ndr_read_align(NdrContext* context, wStream* s, size_t sz);