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

Side by Side Diff: PC/winreg.c

Issue 25778: winreg.EnumValue does not truncate strings correctly
Patch Set: Created 4 years, 3 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « Lib/test/test_winreg.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 winreg.c 2 winreg.c
3 3
4 Windows Registry access module for Python. 4 Windows Registry access module for Python.
5 5
6 * Simple registry access written by Mark Hammond in win32api 6 * Simple registry access written by Mark Hammond in win32api
7 module circa 1995. 7 module circa 1995.
8 * Bill Tutt expanded the support significantly not long after. 8 * Bill Tutt expanded the support significantly not long after.
9 * Numerous other people have submitted patches since then. 9 * Numerous other people have submitted patches since then.
10 * Ripped from win32api module 03-Feb-2000 by Mark Hammond, and 10 * Ripped from win32api module 03-Feb-2000 by Mark Hammond, and
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 switch (typ) { 688 switch (typ) {
689 case REG_DWORD: 689 case REG_DWORD:
690 if (retDataSize == 0) 690 if (retDataSize == 0)
691 obData = PyLong_FromUnsignedLong(0); 691 obData = PyLong_FromUnsignedLong(0);
692 else 692 else
693 obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); 693 obData = PyLong_FromUnsignedLong(*(int *)retDataBuf);
694 break; 694 break;
695 case REG_SZ: 695 case REG_SZ:
696 case REG_EXPAND_SZ: 696 case REG_EXPAND_SZ:
697 { 697 {
698 /* the buffer may or may not have a trailing NULL */ 698 /* REG_SZ should be a NUL terminated string, but only by
699 * convention. The buffer may have been saved without a NUL
700 * or with embedded NULs. To be consistent with reg.exe and
701 * regedit.exe, consume only up to the first NUL. */
699 wchar_t *data = (wchar_t *)retDataBuf; 702 wchar_t *data = (wchar_t *)retDataBuf;
700 int len = retDataSize / 2; 703 size_t len = wcsnlen(data, retDataSize / sizeof(wchar_t));
701 if (retDataSize && data[len-1] == '\0') 704 obData = PyUnicode_FromWideChar(data, len);
702 retDataSize -= 2;
703 if (retDataSize <= 0)
704 data = L"";
705 obData = PyUnicode_FromWideChar(data, retDataSize/2);
706 break; 705 break;
707 } 706 }
708 case REG_MULTI_SZ: 707 case REG_MULTI_SZ:
709 if (retDataSize == 0) 708 if (retDataSize == 0)
710 obData = PyList_New(0); 709 obData = PyList_New(0);
711 else 710 else
712 { 711 {
713 int index = 0; 712 int index = 0;
714 wchar_t *data = (wchar_t *)retDataBuf; 713 wchar_t *data = (wchar_t *)retDataBuf;
715 int len = retDataSize / 2; 714 int len = retDataSize / 2;
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 ADD_INT(REG_DWORD_BIG_ENDIAN); 1919 ADD_INT(REG_DWORD_BIG_ENDIAN);
1921 ADD_INT(REG_LINK); 1920 ADD_INT(REG_LINK);
1922 ADD_INT(REG_MULTI_SZ); 1921 ADD_INT(REG_MULTI_SZ);
1923 ADD_INT(REG_RESOURCE_LIST); 1922 ADD_INT(REG_RESOURCE_LIST);
1924 ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR); 1923 ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
1925 ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST); 1924 ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
1926 return m; 1925 return m;
1927 } 1926 }
1928 1927
1929 1928
OLDNEW
« 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+