summaryrefslogtreecommitdiff
path: root/PC
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-09-09 03:04:54 -0700
committerGitHub <noreply@github.com>2019-09-09 03:04:54 -0700
commitbbf02da42e2368ae6b40015d6e92eaac4120f2dc (patch)
treeccd82ca3a48bf0cde90f23baec782eab4cde2243 /PC
parent1af2c0ec2f63cc6516eb814c3e29d94451a52194 (diff)
downloadcpython-git-bbf02da42e2368ae6b40015d6e92eaac4120f2dc.tar.gz
bpo-32587: Make winreg.REG_MULTI_SZ support zero-length strings (GH-13239)
* bpo-32587: Make winreg.REG_MULTI_SZ support PendingFileRenameOperations * Address review comments. (cherry picked from commit e223ba13d8d871ee58570dfca4e82a591189cc2f) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'PC')
-rw-r--r--PC/winreg.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/PC/winreg.c b/PC/winreg.c
index 5f18876895..0016b320ca 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -517,11 +517,18 @@ fixupMultiSZ(wchar_t **str, wchar_t *data, int len)
int i;
wchar_t *Q;
- Q = data + len;
- for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) {
+ if (len > 0 && data[len - 1] == '\0') {
+ Q = data + len - 1;
+ }
+ else {
+ Q = data + len;
+ }
+
+ for (P = data, i = 0; P < Q; P++, i++) {
str[i] = P;
- for (; P < Q && *P != '\0'; P++)
+ for (; P < Q && *P != '\0'; P++) {
;
+ }
}
}
@@ -529,12 +536,20 @@ static int
countStrings(wchar_t *data, int len)
{
int strings;
- wchar_t *P;
- wchar_t *Q = data + len;
+ wchar_t *P, *Q;
+
+ if (len > 0 && data[len - 1] == '\0') {
+ Q = data + len - 1;
+ }
+ else {
+ Q = data + len;
+ }
- for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++)
- for (; P < Q && *P != '\0'; P++)
+ for (P = data, strings = 0; P < Q; P++, strings++) {
+ for (; P < Q && *P != '\0'; P++) {
;
+ }
+ }
return strings;
}
@@ -749,21 +764,15 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
}
for (index = 0; index < s; index++)
{
- size_t len = wcslen(str[index]);
- if (len > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "registry string is too long for a Python string");
- Py_DECREF(obData);
- PyMem_Free(str);
- return NULL;
- }
- PyObject *uni = PyUnicode_FromWideChar(str[index], len);
+ size_t slen = wcsnlen(str[index], len);
+ PyObject *uni = PyUnicode_FromWideChar(str[index], slen);
if (uni == NULL) {
Py_DECREF(obData);
PyMem_Free(str);
return NULL;
}
PyList_SET_ITEM(obData, index, uni);
+ len -= slen + 1;
}
PyMem_Free(str);