Fix handling of ST terminator when parsing OSC-52 reply #2942
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.
While parsing an OSC-52 reply, we search the input buffer for both
BEL
andST
.Once one of them has been found, we proceed to copy and base64 decode the payload, and then adding the decoded data to a new paste buffer.
The check for
ST
looks backward in the buffer. I.e. it checks if the previous character isESC
, and the current character is\
.This means, our ‘end’ index points to the end of the terminator. This is correct when calculating the length of the entire escape sequence, which is done immediately after having found the terminator.
It is however not correct when copying out the payload. When an OSC-52 reply is
ST
terminated, we end up includingESC
in the payload. This in turn causes the base64 decode to fail, and no paste buffer is created.Note: I had to initialize
terminator
to silence a "may be used uninitialized" warning. Not sure why the assignment to*size
a couple of lines up doesn't trigger this warning. In any case, the warning should be a false positive, since we'll either have found a terminator, orend == len
(and thus we return before usingterminator
).Originally reported here: https://codeberg.org/dnkl/foot/issues/752