diff options
author | Steve Dower <steve.dower@microsoft.com> | 2016-12-17 13:31:58 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2016-12-17 13:31:58 -0800 |
commit | ada27ff7010090e4d2a53a666ece366e86c0f570 (patch) | |
tree | 9446851b9c0fc728c86247d045f8a50e910c6613 /PC | |
parent | 2387e4c60588d93ccd00fb200f526b8178e8b4ef (diff) | |
parent | 8c537f03dd3a32b887541168252d7cd8e13154a1 (diff) | |
download | cpython-ada27ff7010090e4d2a53a666ece366e86c0f570.tar.gz |
Issue #25778: winreg does not truncase string correctly (Patch by Eryk Sun)
Diffstat (limited to 'PC')
-rw-r--r-- | PC/winreg.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/PC/winreg.c b/PC/winreg.c index 9524838c08..5efdc5e0ef 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: |