Merge pull request #6393 from Icinga/bugfix/elasticsearchwriter-not-writing-6354

Stream#ReadLine(): fix false positive buffer underflow indicator
This commit is contained in:
Michael Friedrich 2018-06-21 15:06:21 +02:00 committed by GitHub
commit cc294e14d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 19 deletions

View File

@ -129,31 +129,19 @@ StreamReadStatus Stream::ReadLine(String *line, StreamReadContext& context, bool
}
}
int count = 0;
size_t first_newline;
for (size_t i = 0; i < context.Size; i++) {
if (context.Buffer[i] == '\n') {
count++;
*line = String(context.Buffer, context.Buffer + i);
boost::algorithm::trim_right(*line);
if (count == 1)
first_newline = i;
else if (count > 1)
break;
context.DropData(i + 1u);
context.MustRead = !context.Size;
return StatusNewItem;
}
}
context.MustRead = (count <= 1);
if (count > 0) {
*line = String(context.Buffer, &(context.Buffer[first_newline]));
boost::algorithm::trim_right(*line);
context.DropData(first_newline + 1);
return StatusNewItem;
}
context.MustRead = true;
return StatusNeedData;
}