Skip to content

Commit 9d03391

Browse files
authored
ProcessExecutor: fixed handling of messages with zero length (danmar#7180)
1 parent 9871a09 commit 9d03391

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

cli/processexecutor.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ namespace {
125125
writeToPipeInternal(type, &len, l_size);
126126
}
127127

128-
writeToPipeInternal(type, data.c_str(), len);
128+
if (len > 0)
129+
writeToPipeInternal(type, data.c_str(), len);
129130
}
130131

131132
const int mWpipe;
@@ -174,18 +175,20 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
174175
}
175176

176177
std::string buf(len, '\0');
177-
char *data_start = &buf[0];
178-
bytes_to_read = len;
179-
do {
180-
bytes_read = read(rpipe, data_start, bytes_to_read);
181-
if (bytes_read <= 0) {
182-
const int err = errno;
183-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
184-
std::exit(EXIT_FAILURE);
185-
}
186-
bytes_to_read -= bytes_read;
187-
data_start += bytes_read;
188-
} while (bytes_to_read != 0);
178+
if (len > 0) {
179+
char *data_start = &buf[0];
180+
bytes_to_read = len;
181+
do {
182+
bytes_read = read(rpipe, data_start, bytes_to_read);
183+
if (bytes_read <= 0) {
184+
const int err = errno;
185+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
186+
std::exit(EXIT_FAILURE);
187+
}
188+
bytes_to_read -= bytes_read;
189+
data_start += bytes_read;
190+
} while (bytes_to_read != 0);
191+
}
189192

190193
bool res = true;
191194
if (type == PipeWriter::REPORT_OUT) {

0 commit comments

Comments
 (0)