Skip to content

VirtualFileSystemHook: ensure string is properly null terminated#165

Merged
jamill merged 1 commit intomicrosoft:masterfrom
jamill:virtual_file_system
Aug 15, 2018
Merged

VirtualFileSystemHook: ensure string is properly null terminated#165
jamill merged 1 commit intomicrosoft:masterfrom
jamill:virtual_file_system

Conversation

@jamill
Copy link
Member

@jamill jamill commented Aug 14, 2018

When the VirtualFileSystem hook receives an error reading data from GVFS
over a named pipe, it will include the pipe message in the error
message. The pipe message is not necassarily null terminated, so we need
to append a null terminating character before passing it to string
formatting functions that expect a null terminated string.

This change makes sure the message is null terminated.

@jamill jamill requested review from benpeart and kewillford August 14, 2018 19:15

messageLength = bytesRead;
message[bytesRead] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benpeart can check my thinking here, but the paths are NUL separated so couldn't this create an invalid path by putting a NUL in the middle of a path? The read from the pipe is not guaranteed to send based on the paths is it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid concern - and maybe we should only add the null character if we are about to write the message out to string.

However, the null character is being added outside of the message, and is not part of the bytesRead (and hence not part of the actual pipe message)?

Copy link
Contributor

@benpeart benpeart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that GVFS doesn't null terminate the error message passed across the named pipe but the hook assumes it does. We can fix either end. Fixing the hook works.

@jamill jamill force-pushed the virtual_file_system branch from 103b701 to a22b04e Compare August 14, 2018 20:51
Copy link
Contributor

@benpeart benpeart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks better. It's safer to only munge with the buffer in the case of an error.

@jamill jamill force-pushed the virtual_file_system branch 2 times, most recently from 266e0af to 696985d Compare August 15, 2018 13:01
When the VirtualFileSystem hook receives an error reading data from GVFS
over a named pipe, it will include the pipe message in the error
message. The pipe message is not necassarily null terminated, so we need
to append a null terminating character before passing it to string
formatting functions that expect a null terminated string.

This change makes sure the message is null terminated.
@jamill jamill force-pushed the virtual_file_system branch from 696985d to 32cb916 Compare August 15, 2018 13:05
Copy link

@jeffhostetler jeffhostetler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks fine.

@jamill jamill changed the title VirtualFileSystemHook: fix buffer overrun in reading pipe message VirtualFileSystemHook: ensure string is properly null terminated Aug 15, 2018
@jamill jamill merged commit 8431ab2 into microsoft:master Aug 15, 2018
@jamill jamill deleted the virtual_file_system branch August 15, 2018 14:46
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

Successfully merging this pull request may close these issues.

4 participants