Author eryksun
Recipients eryksun, nanonyme, paul.moore, steve.dower, tim.golden, zach.ware
Date 2018-01-19.00:50:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1516323033.1.0.467229070634.issue32587@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-01-19 00:50:33eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, nanonyme
2018-01-19 00:50:33eryksunsetmessageid: <1516323033.1.0.467229070634.issue32587@psf.upfronthosting.co.za>
2018-01-19 00:50:33eryksunlinkissue32587 messages
2018-01-19 00:50:33eryksuncreate