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

TOCTOU race in prompt redraw #220

Open
slingamn opened this issue Feb 13, 2023 · 0 comments
Open

TOCTOU race in prompt redraw #220

slingamn opened this issue Feb 13, 2023 · 0 comments

Comments

@slingamn
Copy link
Collaborator

Using the test case from #217 (calling (*Instance).Write() concurrently with (*Instance).Readline()), with v1.5.1 on go 1.20, there is a race condition (although not a data race) where the prompt is not always redrawn correctly. Example output:

> a
received a
> b
> received b
> c
received c
> d
> received d
> e
received e
> f
received f
> g
received g
> 
received 
> 
received 
> 
received 
> 
received 
> 
> received 
> 
received 
> 
received 
> 
> received 

The lines where > is followed by text are failures to redraw the prompt.

This appears to be caused by a TOCTOU race here:

readline/operation.go

Lines 48 to 50 in 7f93d88

if !w.t.IsReading() {
return w.target.Write(b)
}

Removing this fast path fixes the issue, but I'm wondering if it might have negative performance implications?

slingamn added a commit to slingamn/readline that referenced this issue Feb 13, 2023
Fixes racey redraw of the prompt:

chzyer#220
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