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 readFile to observe requested read size #6569

Merged
merged 1 commit into from
Aug 2, 2020

Conversation

uptycs-rmack
Copy link
Contributor

The readFile function in the filesystem package takes a size param, however this size param is ignored unless the file is a "special" file (I suppose a device file). This change fixes the readFile function to observe the requested read size.

@Smjert
Copy link
Member

Smjert commented Jul 27, 2020

readFile it's a bit of an interesting beast that probably tries to do too many things all together.
As far as I know, due to the name, what it does and how it's used, its purpose it's to read an entire file.
The special file (normally a device) is a special case, and to be fair although it permits partial reads, I think it shouldn't.

Currently as far as I can see is used 90% or more to read an entire file and then there are a few cases where it chooses if it's synchronous or not.

I would much prefer for it to be splitted in multiple functions with less arguments.

@uptycs-rmack
Copy link
Contributor Author

I'm probably not the right person to split out the function. I can at least update the function comment in the header file so it matches the behavior though instead of change the behavior though if that's preferable.

@theopolis theopolis added the bug label Jul 29, 2020
@theopolis
Copy link
Member

100% yes, readFile could use love and a refactor. I think we should merge this fix as the intention of this overload is to only read the requested size.

@theopolis theopolis merged commit 4be1191 into osquery:master Aug 2, 2020
@uptycs-rmack
Copy link
Contributor Author

Prescient comment on the need to refactor readFile. I've tracked down a bug this change tickled in the pidfile handling code in osquery/core/system.cpp createPidFile(). I'll have a PR up shortly. If you're seeing unit test failures on Windows shutting down the osquery service, this is why.

@uptycs-rmack
Copy link
Contributor Author

I've opened the follow-up fix as PR6578.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants