Module: check_mk
Branch: master
Commit: 9074b51b75a477f20f369de6b4546bf1f61c631d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9074b51b75a477…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Fri Dec 11 12:01:34 2015 +0100
windows agent: fixed buffer breakage with very large plugin output (i.e. inventory)
---
agents/windows/OutputProxy.cc | 27 ++++++++++++++++++----
agents/windows/OutputProxy.h | 2 +-
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 878592 -> 879104 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 878592 -> 879104 bytes
agents/windows/check_mk_agent.exe | Bin 798208 -> 799744 bytes
agents/windows/check_mk_agent.msi | Bin 1935872 -> 1937920 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 798208 -> 799744 bytes
agents/windows/install_agent-64.exe | Bin 401627 -> 402341 bytes
agents/windows/install_agent.exe | Bin 392384 -> 393176 bytes
10 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/agents/windows/OutputProxy.cc b/agents/windows/OutputProxy.cc
index 56b23f7..a87d20e 100644
--- a/agents/windows/OutputProxy.cc
+++ b/agents/windows/OutputProxy.cc
@@ -73,7 +73,20 @@ void BufferedSocketProxy::output(const char *format, ...)
va_list ap;
va_start(ap, format);
- int written_len = vsnprintf(&_buffer[0] + _length, _buffer.size() - _length,
format, ap);
+ size_t buffer_left = _buffer.size() - _length;
+
+ int written_len = vsnprintf(&_buffer[0] + _length, buffer_left, format, ap);
+
+ if (written_len >= (int)buffer_left) {
+ size_t target_size = _length + written_len + 1;
+ size_t new_size = _buffer.size() * 2;
+ while (new_size < target_size) {
+ new_size *= 2;
+ }
+ _buffer.resize(new_size);
+ vsnprintf(&_buffer[0] + _length, _buffer.size() - _length, format, ap);
+ }
+
va_end(ap);
_length += written_len;
@@ -103,7 +116,9 @@ void BufferedSocketProxy::flush()
int tries = 10;
while ((_length > 0) && (tries > 0)) {
--tries;
- flushInt();
+ if (!flushInt()) {
+ return;
+ }
if (_length > 0) {
::Sleep(100);
}
@@ -114,8 +129,9 @@ void BufferedSocketProxy::flush()
}
-void BufferedSocketProxy::flushInt()
+bool BufferedSocketProxy::flushInt()
{
+ bool error = false;
size_t offset = 0;
while (!g_should_terminate) {
ssize_t result = send(_socket, &_buffer[0] + offset, _length - offset, 0);
@@ -129,11 +145,13 @@ void BufferedSocketProxy::flushInt()
}
else if (error == WSAEWOULDBLOCK) {
verbose("send to socket would block");
+ error = true;
break;
}
else {
verbose("send to socket failed with error code %d",
error);
+ error = true;
break;
}
}
@@ -148,10 +166,11 @@ void BufferedSocketProxy::flushInt()
break;
}
_length -= offset;
- if (_length != 0) {
+ if ((_length != 0) && (offset != 0)) {
// not the whole buffer has been sent, shift up the remaining data
memmove(&_buffer[0], &_buffer[0] + offset, _length);
}
+ return !error;
}
diff --git a/agents/windows/OutputProxy.h b/agents/windows/OutputProxy.h
index e933286..47251ca 100644
--- a/agents/windows/OutputProxy.h
+++ b/agents/windows/OutputProxy.h
@@ -82,7 +82,7 @@ public:
protected:
- void flushInt();
+ bool flushInt();
private:
diff --git a/agents/windows/build_version b/agents/windows/build_version
index acbef43..eeb072e 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-982
+997
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index 19ca67b..f76757a 100755
Binary files a/agents/windows/check_mk_agent-64.exe and
b/agents/windows/check_mk_agent-64.exe differ
diff --git a/agents/windows/check_mk_agent-64.unversioned.exe
b/agents/windows/check_mk_agent-64.unversioned.exe
index 7a64469..ad7560b 100755
Binary files a/agents/windows/check_mk_agent-64.unversioned.exe and
b/agents/windows/check_mk_agent-64.unversioned.exe differ
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index b8f6218..aa1836d 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/check_mk_agent.msi b/agents/windows/check_mk_agent.msi
index db7dfb8..a73db0b 100755
Binary files a/agents/windows/check_mk_agent.msi and b/agents/windows/check_mk_agent.msi
differ
diff --git a/agents/windows/check_mk_agent.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index 42cd6a4..f762679 100755
Binary files a/agents/windows/check_mk_agent.unversioned.exe and
b/agents/windows/check_mk_agent.unversioned.exe differ
diff --git a/agents/windows/install_agent-64.exe b/agents/windows/install_agent-64.exe
index 8ce0750..a24c0d9 100755
Binary files a/agents/windows/install_agent-64.exe and
b/agents/windows/install_agent-64.exe differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index 8e5ce50..c76021f 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ