[12/13] msi: Add a length parameter to msi_strcpy_to_awstring and use it where appropriate.
Hans Leidekker
hans at codeweavers.com
Mon Oct 29 06:16:42 CDT 2012
---
dlls/msi/format.c | 2 +-
dlls/msi/install.c | 39 +++++++++++++++++----------------------
dlls/msi/msi.c | 33 ++++++++++++++-------------------
dlls/msi/msipriv.h | 2 +-
dlls/msi/package.c | 9 ++++-----
dlls/msi/registry.c | 7 +++----
6 files changed, 40 insertions(+), 52 deletions(-)
diff --git a/dlls/msi/format.c b/dlls/msi/format.c
index 08522a0..15367e5 100644
--- a/dlls/msi/format.c
+++ b/dlls/msi/format.c
@@ -934,7 +934,7 @@ UINT WINAPI MsiFormatRecordW( MSIHANDLE hInstall, MSIHANDLE hRecord,
wstr.unicode = TRUE;
wstr.str.w = szResult;
- r = msi_strcpy_to_awstring( value, &wstr, sz );
+ r = msi_strcpy_to_awstring( value, SysStringLen(value), &wstr, sz );
done:
IWineMsiRemotePackage_Release( remote_package );
diff --git a/dlls/msi/install.c b/dlls/msi/install.c
index e787714..5810a1e 100644
--- a/dlls/msi/install.c
+++ b/dlls/msi/install.c
@@ -178,32 +178,28 @@ UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode
return ret;
}
-UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
+UINT msi_strcpy_to_awstring( const WCHAR *str, int len, awstring *awbuf, DWORD *sz )
{
- UINT len, r = ERROR_SUCCESS;
+ UINT r = ERROR_SUCCESS;
- if (awbuf->str.w && !sz )
+ if (awbuf->str.w && !sz)
return ERROR_INVALID_PARAMETER;
-
if (!sz)
- return r;
+ return ERROR_SUCCESS;
+
+ if (len < 0) len = strlenW( str );
- if (awbuf->unicode)
- {
- len = lstrlenW( str );
- if (awbuf->str.w)
- lstrcpynW( awbuf->str.w, str, *sz );
- }
+ if (awbuf->unicode && awbuf->str.w)
+ memcpy( awbuf->str.w, str, min(len + 1, *sz) * sizeof(WCHAR) );
else
{
- len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
- if (len)
- len--;
- WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
- if ( awbuf->str.a && *sz && (len >= *sz) )
+ int lenA = WideCharToMultiByte( CP_ACP, 0, str, len + 1, NULL, 0, NULL, NULL );
+ if (lenA) lenA--;
+ WideCharToMultiByte( CP_ACP, 0, str, len + 1, awbuf->str.a, *sz, NULL, NULL );
+ if (awbuf->str.a && *sz && lenA >= *sz)
awbuf->str.a[*sz - 1] = 0;
+ len = lenA;
}
-
if (awbuf->str.w && len >= *sz)
r = ERROR_MORE_DATA;
*sz = len;
@@ -277,7 +273,7 @@ static UINT MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
if (FAILED(hr))
goto done;
- r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
+ r = msi_strcpy_to_awstring( value, len, szPathBuf, pcchPathBuf );
done:
IWineMsiRemotePackage_Release( remote_package );
@@ -301,8 +297,7 @@ done:
if (!path)
return ERROR_DIRECTORY;
- r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
- return r;
+ return msi_strcpy_to_awstring( path, -1, szPathBuf, pcchPathBuf );
}
/***********************************************************************
@@ -447,7 +442,7 @@ static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
if (FAILED(hr))
goto done;
- r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
+ r = msi_strcpy_to_awstring( value, len, szPathBuf, pcchPathBuf );
done:
IWineMsiRemotePackage_Release( remote_package );
@@ -478,7 +473,7 @@ done:
if (!path)
return ERROR_DIRECTORY;
- r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
+ r = msi_strcpy_to_awstring( path, -1, szPathBuf, pcchPathBuf );
msi_free( path );
return r;
}
diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c
index 68e9f81..4bcb5c5 100644
--- a/dlls/msi/msi.c
+++ b/dlls/msi/msi.c
@@ -1101,6 +1101,11 @@ static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
awstring *szValue, LPDWORD pcchValueBuf)
{
+ static WCHAR empty[] = {0};
+ static const WCHAR sourcelist[] = {'S','o','u','r','c','e','L','i','s','t',0};
+ static const WCHAR display_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
+ static const WCHAR display_version[] = {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
+ static const WCHAR assignment[] = {'A','s','s','i','g','n','m','e','n','t',0};
MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
UINT r = ERROR_UNKNOWN_PROPERTY;
HKEY prodkey, userdata, source;
@@ -1111,16 +1116,6 @@ static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
LONG res;
DWORD type = REG_NONE;
- static WCHAR empty[] = {0};
- static const WCHAR sourcelist[] = {
- 'S','o','u','r','c','e','L','i','s','t',0};
- static const WCHAR display_name[] = {
- 'D','i','s','p','l','a','y','N','a','m','e',0};
- static const WCHAR display_version[] = {
- 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
- static const WCHAR assignment[] = {
- 'A','s','s','i','g','n','m','e','n','t',0};
-
TRACE("%s %s %p %p\n", debugstr_w(szProduct),
debugstr_w(szAttribute), szValue, pcchValueBuf);
@@ -1244,6 +1239,8 @@ static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
if (pcchValueBuf)
{
+ int len = strlenW( val );
+
/* If szBuffer (szValue->str) is NULL, there's no need to copy the value
* out. Also, *pcchValueBuf may be uninitialized in this case, so we
* can't rely on its value.
@@ -1251,16 +1248,14 @@ static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
if (szValue->str.a || szValue->str.w)
{
DWORD size = *pcchValueBuf;
- if (strlenW(val) < size)
- r = msi_strcpy_to_awstring(val, szValue, &size);
+ if (len < size)
+ r = msi_strcpy_to_awstring( val, len, szValue, &size );
else
- {
r = ERROR_MORE_DATA;
- }
}
if (!badconfig)
- *pcchValueBuf = lstrlenW(val);
+ *pcchValueBuf = len;
}
if (badconfig)
@@ -2867,7 +2862,7 @@ static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
if (state == INSTALLSTATE_LOCAL && !*path)
state = INSTALLSTATE_NOTUSED;
- msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
+ msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf);
msi_free(path);
return state;
}
@@ -3521,7 +3516,7 @@ static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
goto done;
}
- r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
+ r = msi_strcpy_to_awstring(user, -1, lpUserNameBuf, pcchUserNameBuf);
if (r == ERROR_MORE_DATA)
{
state = USERINFOSTATE_MOREDATA;
@@ -3534,7 +3529,7 @@ static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
orgptr = org;
if (!orgptr) orgptr = szEmpty;
- r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
+ r = msi_strcpy_to_awstring(orgptr, -1, lpOrgNameBuf, pcchOrgNameBuf);
if (r == ERROR_MORE_DATA)
{
state = USERINFOSTATE_MOREDATA;
@@ -3550,7 +3545,7 @@ static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
goto done;
}
- r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
+ r = msi_strcpy_to_awstring(serial, -1, lpSerialBuf, pcchSerialBuf);
if (r == ERROR_MORE_DATA)
state = USERINFOSTATE_MOREDATA;
}
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index 6d858f8..e526d4d 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -724,7 +724,7 @@ typedef struct {
} str;
} awcstring;
-UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz ) DECLSPEC_HIDDEN;
+UINT msi_strcpy_to_awstring(const WCHAR *, int, awstring *, DWORD *) DECLSPEC_HIDDEN;
/* msi server interface */
extern HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj ) DECLSPEC_HIDDEN;
diff --git a/dlls/msi/package.c b/dlls/msi/package.c
index 3feddac..f398c10 100644
--- a/dlls/msi/package.c
+++ b/dlls/msi/package.c
@@ -2232,6 +2232,7 @@ static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
MSIRECORD *row = NULL;
UINT r = ERROR_FUNCTION_FAILED;
LPCWSTR val = NULL;
+ DWORD len = 0;
TRACE("%u %s %p %p\n", handle, debugstr_w(name),
szValueBuf->str.w, pchValueBuf );
@@ -2246,7 +2247,6 @@ static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
IWineMsiRemotePackage *remote_package;
LPWSTR value = NULL;
BSTR bname;
- DWORD len;
remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
if (!remote_package)
@@ -2259,7 +2259,6 @@ static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
return ERROR_OUTOFMEMORY;
}
- len = 0;
hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
if (FAILED(hr))
goto done;
@@ -2276,7 +2275,7 @@ static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
if (FAILED(hr))
goto done;
- r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
+ r = msi_strcpy_to_awstring( value, len, szValueBuf, pchValueBuf );
/* Bug required by Adobe installers */
if (!szValueBuf->unicode && !szValueBuf->str.a)
@@ -2300,12 +2299,12 @@ done:
row = msi_get_property_row( package->db, name );
if (row)
- val = MSI_RecordGetString( row, 1 );
+ val = msi_record_get_string( row, 1, (int *)&len );
if (!val)
val = szEmpty;
- r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
+ r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
if (row)
msiobj_release( &row->hdr );
diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c
index 4143a79..388c077 100644
--- a/dlls/msi/registry.c
+++ b/dlls/msi/registry.c
@@ -1557,7 +1557,7 @@ static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
}
r = ERROR_OUTOFMEMORY;
- if ((name_sz+1) >= name_max)
+ if (name_sz + 1 >= name_max)
{
name_max *= 2;
msi_free( name );
@@ -1586,8 +1586,8 @@ static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
- r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
- r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
+ r = msi_strcpy_to_awstring( name, -1, lpQualBuf, pcchQual );
+ r2 = msi_strcpy_to_awstring( val+ofs, -1, lpAppBuf, pcchAppBuf );
if (r2 != ERROR_SUCCESS)
r = r2;
@@ -1596,7 +1596,6 @@ end:
msi_free(val);
msi_free(name);
RegCloseKey(key);
-
return r;
}
--
1.7.10.4
More information about the wine-patches
mailing list