summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-12-17 21:31:58 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-12-17 21:31:58 (GMT)
commitbbc587742719492168d250f3dcd53d82defaa0a9 (patch)
treee371fe565047782977a8afdb939e6a42b5e3a38a /PC
parentec38bcb66e48bdb266e1d30ed167ab701f7dfa95 (diff)
parent40fa26606d0dc3adfa05ae4a760b3b6b189df075 (diff)
downloadcpython-bbc587742719492168d250f3dcd53d82defaa0a9.zip
cpython-bbc587742719492168d250f3dcd53d82defaa0a9.tar.gz
cpython-bbc587742719492168d250f3dcd53d82defaa0a9.tar.bz2
Issue #25778: winreg does not truncase string correctly (Patch by Eryk Sun)
Diffstat (limited to 'PC')
-rw-r--r--PC/winreg.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/PC/winreg.c b/PC/winreg.c
index 9524838..5efdc5e 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -719,14 +719,13 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
case REG_SZ:
case REG_EXPAND_SZ:
{
- /* the buffer may or may not have a trailing NULL */
+ /* REG_SZ should be a NUL terminated string, but only by
+ * convention. The buffer may have been saved without a NUL
+ * or with embedded NULs. To be consistent with reg.exe and
+ * regedit.exe, consume only up to the first NUL. */
wchar_t *data = (wchar_t *)retDataBuf;
- int len = retDataSize / 2;
- if (retDataSize && data[len-1] == '\0')
- retDataSize -= 2;
- if (retDataSize <= 0)
- data = L"";
- obData = PyUnicode_FromWideChar(data, retDataSize/2);
+ size_t len = wcsnlen(data, retDataSize / sizeof(wchar_t));
+ obData = PyUnicode_FromWideChar(data, len);
break;
}
case REG_MULTI_SZ: