Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Unified Diff: PC/winreg.c

Issue 25778: winreg.EnumValue does not truncate strings correctly
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_winreg.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/PC/winreg.c Fri Jan 01 12:24:12 2016 -0600
+++ b/PC/winreg.c Fri Jan 01 20:32:35 2016 -0600
@@ -695,14 +695,13 @@
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:
« no previous file with comments | « Lib/test/test_winreg.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+