Eryk Sun <[email protected]> added the comment:
Currently countStrings and fixupMultiSZ halt the outer loop as soon as they hit
an empty string. Basically, we'd be getting rid of that check. Then we have to
prevent including an empty string for the final NUL in the normal case. We can
do this by decrementing the length by 1 if the data ends on a NUL. We also need
a check in the inner loop of fixupMultiSZ to ensure it doesn't get out of
bounds.
Example:
static void
fixupMultiSZ(wchar_t **str, wchar_t *data, int len)
{
int i;
wchar_t *P, *Q;
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++)
;
}
}
static int
countStrings(wchar_t *data, int len)
{
int strings;
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++, strings++) {
for (; P < Q && *P != '\0'; P++)
;
}
return strings;
}
Also, the REG_MULTI_SZ case in Reg2Py should use wcsnlen instead of wcslen, in
case of malformed data that doesn't end on at least one NUL character. The
upper limit would be the remaining length.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32587>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com