From af7fefa73f3127467379caf5f27988bd3e5617b5 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Thu, 17 Mar 2011 16:53:29 +0100 Subject: [PATCH] qrexec: handle buffered writes correctly In case when we have a buffered write, always append to the buffer, even if the pipe happens to be writable now. If not, in case of certain tight race we might end up writing buffered data in wrong order. --- qrexec/write_stdin.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qrexec/write_stdin.c b/qrexec/write_stdin.c index 9eec24be..9da24bed 100644 --- a/qrexec/write_stdin.c +++ b/qrexec/write_stdin.c @@ -60,6 +60,12 @@ int write_stdin(int fd, int clid, char *data, int len, struct buffer *buffer) { int ret; + + if (buffer_len(buffer)) { + buffer_append(buffer, data, len); + return WRITE_STDIN_BUFFERED; + } + ret = write(fd, data, len); if (ret == len) return WRITE_STDIN_OK;