| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ | |||
| 41 | 41 | ("String Val", "A string value", REG_SZ), | |
| 42 | 42 | ("StringExpand", "The path is %path%", REG_EXPAND_SZ), | |
| 43 | 43 | ("Multi-string", ["Lots", "of", "string", "values"], REG_MULTI_SZ), | |
| 44 | + ("Multi-nul", ["", "", "", ""], REG_MULTI_SZ), | ||
| 44 | 45 | ("Raw Data", b"binary\x00data", REG_BINARY), | |
| 45 | 46 | ("Big String", "x"*(2**14-1), REG_SZ), | |
| 46 | 47 | ("Big Binary", b"x"*(2**14), REG_BINARY), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Make :data:`winreg.REG_MULTI_SZ` support zero-length strings. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -518,24 +518,39 @@ fixupMultiSZ(wchar_t **str, wchar_t *data, int len) | |||
| 518 | 518 | int i; | |
| 519 | 519 | wchar_t *Q; | |
| 520 | 520 | ||
| 521 | - Q = data + len; | ||
| 522 | - for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) { | ||
| 521 | + if (len > 0 && data[len - 1] == '\0') { | ||
| 522 | + Q = data + len - 1; | ||
| 523 | + } | ||
| 524 | + else { | ||
| 525 | + Q = data + len; | ||
| 526 | + } | ||
| 527 | + | ||
| 528 | + for (P = data, i = 0; P < Q; P++, i++) { | ||
| 523 | 529 | str[i] = P; | |
| 524 | - for (; P < Q && *P != '\0'; P++) | ||
| 530 | + for (; P < Q && *P != '\0'; P++) { | ||
| 525 | 531 | ; | |
| 532 | + } | ||
| 526 | 533 | } | |
| 527 | 534 | } | |
| 528 | 535 | ||
| 529 | 536 | static int | |
| 530 | 537 | countStrings(wchar_t *data, int len) | |
| 531 | 538 | { | |
| 532 | 539 | int strings; | |
| 533 | - wchar_t *P; | ||
| 534 | - wchar_t *Q = data + len; | ||
| 540 | + wchar_t *P, *Q; | ||
| 541 | + | ||
| 542 | + if (len > 0 && data[len - 1] == '\0') { | ||
| 543 | + Q = data + len - 1; | ||
| 544 | + } | ||
| 545 | + else { | ||
| 546 | + Q = data + len; | ||
| 547 | + } | ||
| 535 | 548 | ||
| 536 | - for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++) | ||
| 537 | - for (; P < Q && *P != '\0'; P++) | ||
| 549 | + for (P = data, strings = 0; P < Q; P++, strings++) { | ||
| 550 | + for (; P < Q && *P != '\0'; P++) { | ||
| 538 | 551 | ; | |
| 552 | + } | ||
| 553 | + } | ||
| 539 | 554 | return strings; | |
| 540 | 555 | } | |
| 541 | 556 | ||
@@ -749,21 +764,15 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ) | |||
| 749 | 764 | } | |
| 750 | 765 | for (index = 0; index < s; index++) | |
| 751 | 766 | { | |
| 752 | - size_t len = wcslen(str[index]); | ||
| 753 | - if (len > INT_MAX) { | ||
| 754 | - PyErr_SetString(PyExc_OverflowError, | ||
| 755 | - "registry string is too long for a Python string"); | ||
| 756 | - Py_DECREF(obData); | ||
| 757 | - PyMem_Free(str); | ||
| 758 | - return NULL; | ||
| 759 | - } | ||
| 760 | - PyObject *uni = PyUnicode_FromWideChar(str[index], len); | ||
| 767 | + size_t slen = wcsnlen(str[index], len); | ||
| 768 | + PyObject *uni = PyUnicode_FromWideChar(str[index], slen); | ||
| 761 | 769 | if (uni == NULL) { | |
| 762 | 770 | Py_DECREF(obData); | |
| 763 | 771 | PyMem_Free(str); | |
| 764 | 772 | return NULL; | |
| 765 | 773 | } | |
| 766 | 774 | PyList_SET_ITEM(obData, index, uni); | |
| 775 | + len -= slen + 1; | ||
| 767 | 776 | } | |
| 768 | 777 | PyMem_Free(str); | |
| 769 | 778 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments