fix: prevent infinite loop in multiline string preprocessing#16
Open
novusr wants to merge 1 commit intoopenmultiplayer:masterfrom
Open
fix: prevent infinite loop in multiline string preprocessing#16novusr wants to merge 1 commit intoopenmultiplayer:masterfrom
novusr wants to merge 1 commit intoopenmultiplayer:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed a critical bug where the compiler could enter an infinite loop during multiline string preprocessing if file reading unexpectedly stopped or reached EOF.
Description
In
source/compiler/sc2.c, the functionsunpackedstringandpackedstringhandle multiline strings by callingpreprocess()to fetch subsequent lines. Previously, there was no check to see ifpreprocess()actually succeeded in reading more data. If the file ended abruptly (EOF) or reading failed, the loop would continue indefinitely because the termination condition was never met.Example of Bug (Reproduction)
To see this issue in action, create a file named
test_bug.pwncontaining an unclosed multiline string right at the end of the file:Before the patch:
If you compile this file using the older compiler version, it gets stuck in an infinite loop and hangs indefinitely parsing the string, taking 100% CPU on a single core until forcibly killed.
After the patch:
With the fix, the compiler successfully detects the end of the file, breaks out of the string parse loop, and displays the correct invalid string errors:
This patch adds a check for the
freadingflag immediately after callingpreprocess(). Iffreadingis false, it resets theimlstringstate and breaks out of the loop.