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

Fix handling of ST terminator when parsing OSC-52 reply #2942

Closed
wants to merge 1 commit into from

Conversation

dnkl
Copy link

@dnkl dnkl commented Oct 20, 2021

While parsing an OSC-52 reply, we search the input buffer for both BEL and ST.

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 is ESC, 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 including ESC 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, or end == len (and thus we return before using terminator).

Originally reported here: https://codeberg.org/dnkl/foot/issues/752

While parsing an OSC-52 reply, we search the input buffer for both BEL
and ST.

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 is ESC, 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 including ESC in the
payload. This in turn causes the base64 decode to fail, and no paste
buffer is created.
@nicm
Copy link
Member

nicm commented Oct 21, 2021

Nice one, I have applied this now to OpenBSD, it will be in GitHub later.

I didn't include the initialization since this is clearly a false positive in whatever compiler you are using, I don't see it in any of the compilers I have here anyway so they may have fixed it already.

Thanks!

@nicm nicm closed this Oct 21, 2021
@dnkl
Copy link
Author

dnkl commented Oct 21, 2021 via email

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 21, 2021
@dnkl dnkl deleted the st-terminator-in-osc-52-reply branch December 26, 2021 17:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants