From ad26240c79b472f7cc880a4ede801e811b278dd3 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Fri, 14 Sep 2012 09:56:23 +0000 Subject: [PATCH] [RTL] Implement RtlpSafeCopyMemory, which uses SEH to copy the memory (not in freeldr) Make RtlLargeIntegerToChar use RtlpSafeCopyMemory to copy the string to the target buffer. CORE-3767 #resolve svn path=/trunk/; revision=57295 --- reactos/boot/freeldr/freeldr/rtl/libsupp.c | 11 +++++++ reactos/dll/ntdll/rtl/libsupp.c | 20 +++++++++++++ reactos/lib/rtl/rtlp.h | 7 +++++ reactos/lib/rtl/unicode.c | 35 ++++------------------ reactos/ntoskrnl/rtl/libsupp.c | 20 +++++++++++++ 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/rtl/libsupp.c b/reactos/boot/freeldr/freeldr/rtl/libsupp.c index 2eb9fdff1fc..72a9f7d5f8f 100644 --- a/reactos/boot/freeldr/freeldr/rtl/libsupp.c +++ b/reactos/boot/freeldr/freeldr/rtl/libsupp.c @@ -44,3 +44,14 @@ RtlpFreeMemory(PVOID Mem, { MmHeapFree(Mem); } + +NTSTATUS +NTAPI +RtlpSafeCopyMemory( + _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, + _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, + _In_ SIZE_T Length) +{ + RtlCopyMemory(Destination, Source, Length); + return STATUS_SUCCESS; +} diff --git a/reactos/dll/ntdll/rtl/libsupp.c b/reactos/dll/ntdll/rtl/libsupp.c index 0fbe0c9d7b9..6e63a9183bc 100644 --- a/reactos/dll/ntdll/rtl/libsupp.c +++ b/reactos/dll/ntdll/rtl/libsupp.c @@ -576,4 +576,24 @@ RtlComputeImportTableHash(IN HANDLE FileHandle, return STATUS_NOT_IMPLEMENTED; } +NTSTATUS +NTAPI +RtlpSafeCopyMemory( + _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, + _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, + _In_ SIZE_T Length) +{ + _SEH2_TRY + { + RtlCopyMemory(Destination, Source, Length); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + _SEH2_YIELD(return _SEH2_GetExceptionCode()); + } + _SEH2_END; + + return STATUS_SUCCESS; +} + /* EOF */ diff --git a/reactos/lib/rtl/rtlp.h b/reactos/lib/rtl/rtlp.h index d3accf0c1b1..3996c178bd4 100644 --- a/reactos/lib/rtl/rtlp.h +++ b/reactos/lib/rtl/rtlp.h @@ -34,6 +34,13 @@ extern VOID FASTCALL CHECK_PAGED_CODE_RTL(char *file, int line); #define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m))) +NTSTATUS +NTAPI +RtlpSafeCopyMemory( + _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, + _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, + _In_ SIZE_T Length); + VOID NTAPI RtlpGetStackLimits(PULONG_PTR LowLimit, diff --git a/reactos/lib/rtl/unicode.c b/reactos/lib/rtl/unicode.c index 2e73272a354..491fd88b032 100644 --- a/reactos/lib/rtl/unicode.c +++ b/reactos/lib/rtl/unicode.c @@ -1735,7 +1735,6 @@ RtlLargeIntegerToChar( IN OUT PCHAR String) { ULONGLONG Val = Value->QuadPart; - NTSTATUS Status = STATUS_SUCCESS; CHAR Buffer[65]; CHAR Digit; SIZE_T Len; @@ -1769,36 +1768,12 @@ RtlLargeIntegerToChar( if (Len > Length) return STATUS_BUFFER_OVERFLOW; -#if 1 /* It needs to be removed, when will probably use SEH in rtl */ + /* If possible, add the 0 termination */ + if (Len < Length) + Len += 1; - if (String == NULL) - { - return STATUS_ACCESS_VIOLATION; - } - -#endif - -#if 0 - _SEH2_TRY - { -#endif - - if (Len == Length) - RtlCopyMemory(String, Pos, Len); - else - RtlCopyMemory(String, Pos, Len + 1); - -#if 0 - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - /* Get the error code */ - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END; -#endif - - return Status; + /* Copy the string to the target using SEH */ + return RtlpSafeCopyMemory(String, Pos, Len); } /* diff --git a/reactos/ntoskrnl/rtl/libsupp.c b/reactos/ntoskrnl/rtl/libsupp.c index e1218047017..f9e4d603706 100644 --- a/reactos/ntoskrnl/rtl/libsupp.c +++ b/reactos/ntoskrnl/rtl/libsupp.c @@ -676,5 +676,25 @@ done: return STATUS_SUCCESS; } +NTSTATUS +NTAPI +RtlpSafeCopyMemory( + _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, + _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, + _In_ SIZE_T Length) +{ + _SEH2_TRY + { + RtlCopyMemory(Destination, Source, Length); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + _SEH2_YIELD(return _SEH2_GetExceptionCode()); + } + _SEH2_END; + + return STATUS_SUCCESS; +} + /* EOF */