Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash handling SpvOpSourceContinued #142

Open
ccottrellnv opened this issue Apr 4, 2022 · 0 comments
Open

Crash handling SpvOpSourceContinued #142

ccottrellnv opened this issue Apr 4, 2022 · 0 comments

Comments

@ccottrellnv
Copy link

On Windows systems, the handling of SpvOpSourceContinued will crash in the call to strcat_s in cases where both source_len and embedded_source_len are not zero. According to the strcat_s documentation:

“The behavior is undefined if the size of the character array pointed to by dest < strlen(dest)+strlen(src)+1 <= destsz”

In the case both source_len and embedded_source_len are not zero, the current code will have “destsz” < “strlen(dest)+strlen(src)+1”.

I think the code should read as follows:

        if (embedded_source_len) {
            strcpy_s(p_continued_source, embedded_source_len + 1, p_parser->source_embedded);
            strcat_s(p_continued_source, source_len + embedded_source_len + 1, p_source);
        }
        else {
            strcpy_s(p_continued_source, source_len + 1, p_source);
        }

It is also more correct to define embedded_source_len as follows:

const size_t embedded_source_len = p_parser->source_embedded ? strlen(p_parser->source_embedded) : 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant