fix sender parsing when receiving remote input (#17696)
* fix sender parsing when receiving remote input * moved obsolete statement
Costa Tsaousis committed
May 17, 2024 at 18:54 UTC
f3e0205be0243d8055b8e7da9dd2fe073f2e213d
1 file changed
+17
-7
src/streaming/sender.c
+17
-7
@@ -1232,12 +1232,23 @@ void execute_commands(struct sender_state *s) {
1232
ND_LOG_STACK_PUSH(lgs);
1233
1234
char *start = s->read_buffer, *end = &s->read_buffer[s->read_len], *newline;
1235
- *end = 0;
1236
- while( start < end && (newline = strchr(start, '\n')) ) {
1235
+ *end = '\0';
1236
+ for( ; start < end ; start = newline + 1) {
1237
+ newline = strchr(start, '\n');
1238
+
1239
+ if(!newline) {
1240
+ if(s->functions.intercept_input) {
1241
+ buffer_strcat(s->functions.payload, start);
1242
+ start = end;
1243
+ }
1244
+ break;
1245
+ }
1246
+
1247
+ *newline = '\0';
1248
s->line.count++;
1249
1250
if(s->functions.intercept_input) {
1240
- if(strcmp(start, PLUGINSD_CALL_FUNCTION_PAYLOAD_END "\n") == 0) {
1251
+ if(strcmp(start, PLUGINSD_CALL_FUNCTION_PAYLOAD_END) == 0) {
1252
execute_commands_function(s,
1253
PLUGINSD_CALL_FUNCTION_PAYLOAD_END,
1254
s->functions.transaction, s->functions.timeout_s,
@@ -1246,14 +1257,14 @@ void execute_commands(struct sender_state *s) {
1257
1258
cleanup_intercepting_input(s);
1259
}
1249
- else
1260
+ else {
1261
buffer_strcat(s->functions.payload, start);
1262
+ buffer_fast_charcat(s->functions.payload, '\n');
1263
+ }
1264
1252
- start = newline + 1;
1265
continue;
1266
}
1267
1256
- *newline = '\0';
1268
s->line.num_words = quoted_strings_splitter_pluginsd(start, s->line.words, PLUGINSD_MAX_WORDS);
1269
const char *command = get_word(s->line.words, s->line.num_words, 0);
1270
@@ -1332,7 +1343,6 @@ void execute_commands(struct sender_state *s) {
1343
1344
line_splitter_reset(&s->line);
1345
worker_is_busy(WORKER_SENDER_JOB_EXECUTE);
1335
- start = newline + 1;
1346
}
1347
1348
if (start < end) {