Fix reading of not NUL-terminated strings using wxRegKey.

Even though this is typically the case, some strings in Windows registry are
not NUL-terminated, deal with them correctly by using the explicit length.

Closes #16719.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78327 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-12-27 14:24:58 +00:00
parent 7dd75c8844
commit 957f3c5b50
2 changed files with 22 additions and 6 deletions

View File

@@ -126,6 +126,7 @@ wxMSW:
- Fix wxMenuEvent::GetMenu() for wxEVT_MENU_{OPEN,CLOSE} in MDI frames. - Fix wxMenuEvent::GetMenu() for wxEVT_MENU_{OPEN,CLOSE} in MDI frames.
- Fix updating wxSpinCtrlDouble tooltip text (Laurent Poujoulat). - Fix updating wxSpinCtrlDouble tooltip text (Laurent Poujoulat).
- Fix appearance of checked disabled wxToolBar tools with custom images. - Fix appearance of checked disabled wxToolBar tools with custom images.
- Fix reading of not NUL-terminated strings using wxRegKey (Steffen Olszewski).
wxOSX/Cocoa: wxOSX/Cocoa:

View File

@@ -995,12 +995,27 @@ bool wxRegKey::QueryValue(const wxString& szValue,
} }
else else
{ {
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, // extra scope for wxStringBufferLength
RegValueStr(szValue), {
RESERVED, // We need length in characters, not bytes.
&dwType, DWORD chars = dwSize / sizeof(wxChar);
(RegString)(wxChar*)wxStringBuffer(strValue, dwSize),
&dwSize); wxStringBufferLength strBuf(strValue, chars);
m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
RegValueStr(szValue),
RESERVED,
&dwType,
(RegString)(wxChar*)strBuf,
&dwSize);
// The returned string may or not be NUL-terminated,
// exclude the trailing NUL if it's there (which is
// typically the case but is not guaranteed to always be).
if ( strBuf[chars - 1] == '\0' )
chars--;
strBuf.SetLength(chars);
}
// expand the var expansions in the string unless disabled // expand the var expansions in the string unless disabled
#ifndef __WXWINCE__ #ifndef __WXWINCE__