Author: tkreuzer Date: Fri Sep 14 09:56:23 2012 New Revision: 57295
URL: http://svn.reactos.org/svn/reactos?rev=57295&view=rev Log: [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
Modified: trunk/reactos/boot/freeldr/freeldr/rtl/libsupp.c trunk/reactos/dll/ntdll/rtl/libsupp.c trunk/reactos/lib/rtl/rtlp.h trunk/reactos/lib/rtl/unicode.c trunk/reactos/ntoskrnl/rtl/libsupp.c
Modified: trunk/reactos/boot/freeldr/freeldr/rtl/libsupp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/rtl/li... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/rtl/libsupp.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/rtl/libsupp.c [iso-8859-1] Fri Sep 14 09:56:23 2012 @@ -44,3 +44,14 @@ { 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; +}
Modified: trunk/reactos/dll/ntdll/rtl/libsupp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/rtl/libsupp.c?rev... ============================================================================== --- trunk/reactos/dll/ntdll/rtl/libsupp.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/rtl/libsupp.c [iso-8859-1] Fri Sep 14 09:56:23 2012 @@ -576,4 +576,24 @@ 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 */
Modified: trunk/reactos/lib/rtl/rtlp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/rtlp.h?rev=57295&am... ============================================================================== --- trunk/reactos/lib/rtl/rtlp.h [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/rtlp.h [iso-8859-1] Fri Sep 14 09:56:23 2012 @@ -33,6 +33,13 @@ ROUND_DOWN(((ULONG)(n)) + (align) - 1, (align))
#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
Modified: trunk/reactos/lib/rtl/unicode.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/unicode.c?rev=57295... ============================================================================== --- trunk/reactos/lib/rtl/unicode.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/unicode.c [iso-8859-1] Fri Sep 14 09:56:23 2012 @@ -1735,7 +1735,6 @@ IN OUT PCHAR String) { ULONGLONG Val = Value->QuadPart; - NTSTATUS Status = STATUS_SUCCESS; CHAR Buffer[65]; CHAR Digit; SIZE_T Len; @@ -1769,36 +1768,12 @@ if (Len > Length) return STATUS_BUFFER_OVERFLOW;
-#if 1 /* It needs to be removed, when will probably use SEH in rtl */ - - 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; + /* If possible, add the 0 termination */ + if (Len < Length) + Len += 1; + + /* Copy the string to the target using SEH */ + return RtlpSafeCopyMemory(String, Pos, Len); }
/*
Modified: trunk/reactos/ntoskrnl/rtl/libsupp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/rtl/libsupp.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/rtl/libsupp.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/rtl/libsupp.c [iso-8859-1] Fri Sep 14 09:56:23 2012 @@ -676,5 +676,25 @@ 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 */