[PATCH 2/4] msi: Avoid using awstring in MsiFormatRecordW().
Zebediah Figura
z.figura12 at gmail.com
Tue May 15 23:03:34 CDT 2018
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/msi/format.c | 12 +++---------
dlls/msi/install.c | 19 +++++++++++++++++++
dlls/msi/msipriv.h | 1 +
dlls/msi/tests/custom.c | 11 +++++++++++
4 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/dlls/msi/format.c b/dlls/msi/format.c
index d34fb2b..9356c9e 100644
--- a/dlls/msi/format.c
+++ b/dlls/msi/format.c
@@ -916,22 +916,16 @@ UINT WINAPI MsiFormatRecordW( MSIHANDLE hInstall, MSIHANDLE hRecord,
{
LPWSTR value = NULL;
MSIHANDLE remote;
- awstring wstr;
if ((remote = msi_get_remote(hInstall)))
{
r = remote_FormatRecord(remote, (struct wire_record *)&record->count, &value);
- if (r)
- {
- midl_user_free(value);
- return r;
- }
- wstr.unicode = TRUE;
- wstr.str.w = szResult;
- r = msi_strcpy_to_awstring(value, -1, &wstr, sz);
+ if (!r)
+ r = msi_strncpyW(value, -1, szResult, sz);
midl_user_free(value);
+ msiobj_release(&record->hdr);
return r;
}
}
diff --git a/dlls/msi/install.c b/dlls/msi/install.c
index ca277d3..b54daff 100644
--- a/dlls/msi/install.c
+++ b/dlls/msi/install.c
@@ -191,6 +191,25 @@ UINT msi_strncpyWtoA(const WCHAR *str, int lenW, char *buf, DWORD *sz, BOOL remo
return r;
}
+UINT msi_strncpyW(const WCHAR *str, int len, WCHAR *buf, DWORD *sz)
+{
+ UINT r = ERROR_SUCCESS;
+
+ if (!sz)
+ return buf ? ERROR_INVALID_PARAMETER : ERROR_SUCCESS;
+
+ if (len < 0) len = strlenW(str);
+ if (buf)
+ memcpy(buf, str, min(len + 1, *sz) * sizeof(WCHAR));
+ if (buf && len >= *sz)
+ {
+ if (*sz) buf[*sz - 1] = 0;
+ r = ERROR_MORE_DATA;
+ }
+ *sz = len;
+ return r;
+}
+
const WCHAR *msi_get_target_folder( MSIPACKAGE *package, const WCHAR *name )
{
MSIFOLDER *folder = msi_get_loaded_folder( package, name );
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index 5c6cd40..707144f 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -1046,6 +1046,7 @@ extern WCHAR **msi_split_string(const WCHAR *, WCHAR) DECLSPEC_HIDDEN;
extern UINT msi_set_original_database_property(MSIDATABASE *, const WCHAR *) DECLSPEC_HIDDEN;
extern WCHAR *msi_get_error_message(MSIDATABASE *, int) DECLSPEC_HIDDEN;
extern UINT msi_strncpyWtoA(const WCHAR *str, int len, char *buf, DWORD *sz, BOOL remote) DECLSPEC_HIDDEN;
+extern UINT msi_strncpyW(const WCHAR *str, int len, WCHAR *buf, DWORD *sz) DECLSPEC_HIDDEN;
/* media */
diff --git a/dlls/msi/tests/custom.c b/dlls/msi/tests/custom.c
index 320aa6f..723b2b5 100644
--- a/dlls/msi/tests/custom.c
+++ b/dlls/msi/tests/custom.c
@@ -815,6 +815,17 @@ static void test_format_record(MSIHANDLE hinst)
ok(hinst, !strcmp(buffer, "foo 123"), "got \"%s\"\n", buffer);
ok(hinst, sz == 7, "got size %u\n", sz);
+ r = MsiFormatRecordW(hinst, rec, NULL, NULL);
+ ok(hinst, !r, "got %u\n", r);
+
+ r = MsiFormatRecordW(hinst, rec, bufferW, NULL);
+ ok(hinst, r == ERROR_INVALID_PARAMETER, "got %u\n", r);
+
+ sz = 0;
+ r = MsiFormatRecordW(hinst, rec, NULL, &sz);
+ ok(hinst, !r, "got %u\n", r);
+ ok(hinst, sz == 7, "got size %u\n", sz);
+
sz = 0;
bufferW[0] = 'q';
r = MsiFormatRecordW(hinst, rec, bufferW, &sz);
--
2.7.4
More information about the wine-devel
mailing list