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

Reading from a pipe is messed up #14

Closed
matthijskooijman opened this issue Apr 14, 2018 · 4 comments
Closed

Reading from a pipe is messed up #14

matthijskooijman opened this issue Apr 14, 2018 · 4 comments

Comments

@matthijskooijman
Copy link

matthijskooijman commented Apr 14, 2018

I tried reading output from stderr from a process, and it gets all messed up. It seems the length of the buffer returned is correct, but only the first couple of hundred bytes are filled, the rest are zeroes.

Looking at the code, it seems that read_atmost_n does not handle partial reads correctly. Changing this line to the following seems to fix this.

int read_bytes = read(fd, buf + rbytes, read_upto - rbytes)

On a related note, I suspect that if read_all resizes the buffer and causes a realloc, then the buffer variable might become invalid.

@arun11299
Copy link
Owner

Thanks for reporting the bug @matthijskooijman
Would you be able to create a pull request which addresses both the issues ? I think both are valid bugs.

If you are unable to do it, I will of course patch it.

@matthijskooijman
Copy link
Author

Sorry, I really can't spare the time right now.

arun11299 added a commit that referenced this issue Apr 16, 2018
@arun11299
Copy link
Owner

No problem. I have pushed the fix.

Thanks!

@matthijskooijman
Copy link
Author

Looks good, thanks.

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

2 participants