Skip to content

Commit 50785f7

Browse files
committed
C++: Add tests with missing flow.
1 parent 49ecc60 commit 50785f7

File tree

1 file changed

+107
-0
lines changed
  • cpp/ql/test/library-tests/dataflow/external-models

1 file changed

+107
-0
lines changed

cpp/ql/test/library-tests/dataflow/external-models/windows.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,111 @@ void test_create_thread()
466466
&attrList,
467467
&threadId);
468468
}
469+
}
470+
471+
using size_t = decltype(sizeof(0));
472+
473+
volatile void * RtlCopyVolatileMemory(
474+
volatile void *Destination,
475+
volatile const void *Source,
476+
size_t Length
477+
);
478+
479+
volatile void * RtlCopyDeviceMemory(
480+
volatile void *Destination,
481+
volatile const void *Source,
482+
size_t Length
483+
);
484+
485+
void RtlCopyMemory(
486+
void* Destination,
487+
const void* Source,
488+
size_t Length
489+
);
490+
491+
using VOID = void;
492+
493+
VOID RtlCopyMemoryNonTemporal(
494+
VOID *Destination,
495+
const VOID *Source,
496+
SIZE_T Length
497+
);
498+
499+
using USHORT = unsigned short;
500+
using PWSTR = wchar_t*;
501+
using PCWSTR = const wchar_t*;
502+
using PCUNICODE_STRING = const struct _UNICODE_STRING*;
503+
504+
typedef struct _UNICODE_STRING {
505+
USHORT Length;
506+
USHORT MaximumLength;
507+
PWSTR Buffer;
508+
} UNICODE_STRING, *PUNICODE_STRING;
509+
510+
VOID RtlCopyUnicodeString(
511+
PUNICODE_STRING DestinationString,
512+
PCUNICODE_STRING SourceString
513+
);
514+
515+
void RtlMoveMemory(
516+
void* Destination,
517+
const void* Source,
518+
size_t Length
519+
);
520+
521+
volatile void * RtlMoveVolatileMemory(
522+
volatile void *Destination,
523+
volatile const void *Source,
524+
size_t Length
525+
);
526+
527+
void RtlInitUnicodeString(
528+
PUNICODE_STRING DestinationString,
529+
PCWSTR SourceString
530+
);
531+
532+
void test_copy_and_move_memory() {
533+
int x = source();
534+
535+
{
536+
char dest_buffer[1024];
537+
RtlCopyVolatileMemory(dest_buffer, &x, sizeof(x));
538+
sink(dest_buffer[0]); // $ MISSING: ir
539+
}
540+
{
541+
char dest_buffer[1024];
542+
RtlCopyDeviceMemory(dest_buffer, &x, sizeof(x));
543+
sink(dest_buffer[0]); // $ MISSING: ir
544+
}
545+
{
546+
char dest_buffer[1024];
547+
RtlCopyMemory(dest_buffer, &x, sizeof(x));
548+
sink(dest_buffer[0]); // $ MISSING: ir
549+
}
550+
{
551+
char dest_buffer[1024];
552+
RtlCopyMemoryNonTemporal(dest_buffer, &x, sizeof(x));
553+
sink(dest_buffer[0]); // $ MISSING: ir
554+
}
555+
{
556+
UNICODE_STRING dest_string;
557+
UNICODE_STRING src_string;
558+
wchar_t buffer[1024];
559+
buffer[0] = source();
560+
561+
RtlInitUnicodeString(&src_string, buffer);
562+
sink(src_string.Buffer[0]); // $ MISSING: ir
563+
RtlCopyUnicodeString(&dest_string, &src_string);
564+
sink(dest_string.Buffer[0]); // $ MISSING: ir
565+
}
566+
{
567+
char dest_buffer[1024];
568+
RtlMoveMemory(dest_buffer, &x, sizeof(x));
569+
sink(dest_buffer[0]); // $ MISSING: ir
570+
}
571+
{
572+
volatile char dest_buffer[1024];
573+
RtlMoveVolatileMemory(dest_buffer, &x, sizeof(x));
574+
sink(dest_buffer[0]); // $ MISSING: ir
575+
}
469576
}

0 commit comments

Comments
 (0)