Skip to content

Commit b3f9092

Browse files
committed
in_http: fix handling of URL encoded value
Updated the URL-encoded form parser to keep the original value when URI decoding fails and log a warning about the offending field instead of aborting processing. Signed-off-by: Eduardo Silva <[email protected]>
1 parent fa79fc1 commit b3f9092

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

plugins/in_http/http_prot.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <fluent-bit/flb_error.h>
2323
#include <fluent-bit/flb_pack.h>
2424

25+
#include <ctype.h>
26+
2527
#include <fluent-bit/flb_gzip.h>
2628
#include <fluent-bit/flb_zstd.h>
2729
#include <fluent-bit/flb_snappy.h>
@@ -60,7 +62,11 @@ static int sds_uri_decode(flb_sds_t s)
6062

6163
for (optr = buf, iptr = s; iptr < s + flb_sds_len(s) && optr-buf < sizeof(buf); iptr++) {
6264
if (*iptr == '%') {
63-
if (iptr+2 > (s + flb_sds_len(s))) {
65+
if (iptr + 2 >= (s + flb_sds_len(s))) {
66+
return -1;
67+
}
68+
if (!isxdigit((unsigned char) *(iptr + 1)) ||
69+
!isxdigit((unsigned char) *(iptr + 2))) {
6470
return -1;
6571
}
6672
*optr++ = hex2nibble(*(iptr+1)) << 4 | hex2nibble(*(iptr+2));
@@ -219,7 +225,7 @@ static flb_sds_t tag_key(struct flb_http *ctx, msgpack_object *map)
219225
}
220226

221227

222-
flb_plg_error(ctx->ins, "Could not find tag_key %s in record", ctx->tag_key);
228+
flb_plg_warn(ctx->ins, "Could not find tag_key %s in record", ctx->tag_key);
223229
return NULL;
224230
}
225231

@@ -423,7 +429,7 @@ static ssize_t parse_payload_urlencoded(struct flb_http *ctx, flb_sds_t tag,
423429
char *start;
424430
msgpack_packer pck;
425431
msgpack_sbuffer sbuf;
426-
432+
const char *field_name;
427433

428434
/* initialize buffers */
429435
msgpack_sbuffer_init(&sbuf);
@@ -493,12 +499,13 @@ static ssize_t parse_payload_urlencoded(struct flb_http *ctx, flb_sds_t tag,
493499
msgpack_pack_str_body(&pck, keys[i], flb_sds_len(keys[i]));
494500

495501
if (sds_uri_decode(vals[i]) != 0) {
496-
goto decode_error;
497-
}
498-
else {
499-
msgpack_pack_str(&pck, flb_sds_len(vals[i]));
500-
msgpack_pack_str_body(&pck, vals[i], flb_sds_len(vals[i]));
502+
field_name = keys[i] ? keys[i] : "";
503+
flb_plg_warn(ctx->ins,
504+
"invalid percent-encoding for field '%s', keeping raw value",
505+
field_name);
501506
}
507+
msgpack_pack_str(&pck, flb_sds_len(vals[i]));
508+
msgpack_pack_str_body(&pck, vals[i], flb_sds_len(vals[i]));
502509
}
503510

504511
ret = process_pack(ctx, tag, sbuf.data, sbuf.size);

0 commit comments

Comments
 (0)