Add StrAllocConcatFormattedSecure.
Sean Hall committed
May 14, 2020 at 18:31 UTC
94f9303dabb5d28884ac05b179b004f37eae89eb
2 files changed
+40
-1
src/dutil/inc/strutil.h
+5
@@ -100,6 +100,11 @@ HRESULT __cdecl StrAllocConcatFormatted(
100
__in __format_string LPCWSTR wzFormat,
101
...
102
);
103
+HRESULT __cdecl StrAllocConcatFormattedSecure(
104
+ __deref_out_z LPWSTR* ppwz,
105
+ __in __format_string LPCWSTR wzFormat,
106
+ ...
107
+ );
108
HRESULT __cdecl StrAllocFormattedSecure(
109
__deref_out_z LPWSTR* ppwz,
110
__in __format_string LPCWSTR wzFormat,
src/dutil/strutil.cpp
+35
-1
@@ -919,9 +919,43 @@ LExit:
919
}
920
921
922
+/********************************************************************
923
+StrAllocConcatFormattedSecure - allocates or reuses dynamic string
924
+memory and adds a formatted string. If the memory needs to be
925
+reallocated, calls SecureZeroMemory on original block of memory after
926
+it is moved.
927
+
928
+NOTE: caller is responsible for freeing ppwz even if function fails
929
+********************************************************************/
930
+extern "C" HRESULT __cdecl StrAllocConcatFormattedSecure(
931
+ __deref_out_z LPWSTR* ppwz,
932
+ __in __format_string LPCWSTR wzFormat,
933
+ ...
934
+ )
935
+{
936
+ Assert(ppwz && wzFormat && *wzFormat);
937
+
938
+ HRESULT hr = S_OK;
939
+ LPWSTR sczFormatted = NULL;
940
+ va_list args;
941
+
942
+ va_start(args, wzFormat);
943
+ hr = StrAllocFormattedArgsSecure(&sczFormatted, wzFormat, args);
944
+ va_end(args);
945
+ ExitOnFailure(hr, "Failed to allocate formatted string");
946
+
947
+ hr = StrAllocConcatSecure(ppwz, sczFormatted, 0);
948
+
949
+LExit:
950
+ ReleaseStr(sczFormatted);
951
+
952
+ return hr;
953
+}
954
+
955
+
956
/********************************************************************
957
StrAllocFormattedSecure - allocates or reuses dynamic string memory
924
-and formats it. If the memory needs to reallocated,
958
+and formats it. If the memory needs to be reallocated,
959
calls SecureZeroMemory on original block of memory after it is moved.
960
961
NOTE: caller is responsible for freeing ppwz even if function fails