Skip to content

Commit

Permalink
Merge pull request microsoft#165: VirtualFileSystemHook: ensure strin…
Browse files Browse the repository at this point in the history
…g is properly null terminated

VirtualFileSystemHook: ensure string is properly null terminated
  • Loading branch information
jamill authored Aug 15, 2018
2 parents 7b5b425 + 32cb916 commit 8431ab2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions GVFS/GVFS.VirtualFileSystemHook/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ enum VirtualFileSystemErrorReturnCode
ErrorVirtualFileSystemProtocol = ReturnCode::LastError + 1,
};

const int PIPE_BUFFER_SIZE = 1024;

int main(int argc, char *argv[])
{
if (argc != 2)
Expand Down Expand Up @@ -39,7 +41,10 @@ int main(int argc, char *argv[])
die(ReturnCode::PipeWriteFailed, "Failed to write to pipe (%d)\n", error);
}

char message[1024];
// Allow for 1 extra character in case we need to
// null terminate the message, and the message
// is PIPE_BUFFER_SIZE chars long.
char message[PIPE_BUFFER_SIZE + 1];
unsigned long bytesRead;
int lastError;
bool finishedReading = false;
Expand All @@ -51,22 +56,23 @@ int main(int argc, char *argv[])
success = ReadFromPipe(
pipeHandle,
message,
sizeof(message),
PIPE_BUFFER_SIZE,
&bytesRead,
&lastError);

if (!success)
{
break;
}

messageLength = bytesRead;

if (firstRead)
{
firstRead = false;
if (message[0] != 'S')
{
message[bytesRead] = 0;
die(ReturnCode::PipeReadFailed, "Read response from pipe failed (%s)\n", message);
}

Expand Down

0 comments on commit 8431ab2

Please sign in to comment.