diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-05-14 18:31:02 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-05-16 21:26:53 +1000 |
| commit | 94f9303dabb5d28884ac05b179b004f37eae89eb (patch) | |
| tree | 7ee90e3d3e1ce17a1efa77e695a67d1eb98f4bad /src | |
| parent | 05781eabd0e71261959aabe27ab5ff2d3d859ca2 (diff) | |
| download | wix-94f9303dabb5d28884ac05b179b004f37eae89eb.tar.gz wix-94f9303dabb5d28884ac05b179b004f37eae89eb.tar.bz2 wix-94f9303dabb5d28884ac05b179b004f37eae89eb.zip | |
Add StrAllocConcatFormattedSecure.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dutil/inc/strutil.h | 5 | ||||
| -rw-r--r-- | src/dutil/strutil.cpp | 36 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/dutil/inc/strutil.h b/src/dutil/inc/strutil.h index 1a2ed1d8..c73615aa 100644 --- a/src/dutil/inc/strutil.h +++ b/src/dutil/inc/strutil.h | |||
| @@ -100,6 +100,11 @@ HRESULT __cdecl StrAllocConcatFormatted( | |||
| 100 | __in __format_string LPCWSTR wzFormat, | 100 | __in __format_string LPCWSTR wzFormat, |
| 101 | ... | 101 | ... |
| 102 | ); | 102 | ); |
| 103 | HRESULT __cdecl StrAllocConcatFormattedSecure( | ||
| 104 | __deref_out_z LPWSTR* ppwz, | ||
| 105 | __in __format_string LPCWSTR wzFormat, | ||
| 106 | ... | ||
| 107 | ); | ||
| 103 | HRESULT __cdecl StrAllocFormattedSecure( | 108 | HRESULT __cdecl StrAllocFormattedSecure( |
| 104 | __deref_out_z LPWSTR* ppwz, | 109 | __deref_out_z LPWSTR* ppwz, |
| 105 | __in __format_string LPCWSTR wzFormat, | 110 | __in __format_string LPCWSTR wzFormat, |
diff --git a/src/dutil/strutil.cpp b/src/dutil/strutil.cpp index 2e5e2f96..4e184c34 100644 --- a/src/dutil/strutil.cpp +++ b/src/dutil/strutil.cpp | |||
| @@ -920,8 +920,42 @@ LExit: | |||
| 920 | 920 | ||
| 921 | 921 | ||
| 922 | /******************************************************************** | 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 | /******************************************************************** | ||
| 923 | StrAllocFormattedSecure - allocates or reuses dynamic string memory | 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, |
| 925 | calls SecureZeroMemory on original block of memory after it is moved. | 959 | calls SecureZeroMemory on original block of memory after it is moved. |
| 926 | 960 | ||
| 927 | NOTE: caller is responsible for freeing ppwz even if function fails | 961 | NOTE: caller is responsible for freeing ppwz even if function fails |
