From: Willy Tarreau Date: Mon, 28 Sep 2026 03:19:48 +0000 (+0200) Subject: MINOR: log: pass the input end to the _lf_encode_bytes() byte encoders X-Git-Tag: v3.5-dev8~108 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=9375ed867e92e543ecb5a3c0053e05be6fd20f17;p=haproxy.git MINOR: log: pass the input end to the _lf_encode_bytes() byte encoders The byte encoding callbacks used by _lf_encode_bytes() only receive the current byte, so they cannot look at the following ones. This will be needed by the json encoder to detect multi-byte UTF-8 sequences. Let's pass them as well as an end pointer, which is NULL for NUL-terminated inputs. --- diff --git a/src/log.c b/src/log.c index ed8354a4e..8c1beb304 100644 --- a/src/log.c +++ b/src/log.c @@ -2123,13 +2123,16 @@ static inline char *_lf_cbor_escape_byte(char *start, char *stop, /* helper function for _lf_encode_bytes() to encode a single byte * and escape it with if found in * + * All these helpers receive the current byte in and the end of the + * input in , which is NULL when the input is NUL-terminated. + * * The function assumes that at least 1 byte is available for writing * * Returns the address of the byte immediately after the last written byte * on success, or NULL on error. It will not append terminating NULL byte. */ static inline char *_lf_map_escape_byte(char *start, char *stop, - const char *byte, + const char *byte, const char *end, const char escape, const long *map, const char **pending, uint8_t cbor_string_prefix, struct lf_buildctx *ctx) @@ -2152,7 +2155,7 @@ static inline char *_lf_map_escape_byte(char *start, char *stop, * on success, or NULL on error. It will not append terminating NULL byte. */ static inline char *_lf_cbor_map_escape_byte(char *start, char *stop, - const char *byte, + const char *byte, const char *end, const char escape, const long *map, const char **pending, uint8_t cbor_string_prefix, struct lf_buildctx *ctx) @@ -2201,7 +2204,7 @@ static inline char *_lf_cbor_map_escape_byte(char *start, char *stop, * on success, or NULL on error. It will not append terminating NULL byte. */ static inline char *_lf_rfc5424_escape_byte(char *start, char *stop, - const char *byte, + const char *byte, const char *end, const char escape, const long *map, const char **pending, uint8_t cbor_string_prefix, struct lf_buildctx *ctx) @@ -2274,7 +2277,7 @@ static inline char *_lf_json_escape_seq(char *start, char *stop, unsigned char b * on success, or NULL on error. It will not append terminating NULL byte. */ static inline char *_lf_json_escape_byte(char *start, char *stop, - const char *byte, + const char *byte, const char *end, const char escape, const long *map, const char **pending, uint8_t cbor_string_prefix, struct lf_buildctx *ctx) @@ -2318,7 +2321,7 @@ static char *_lf_encode_bytes(char *start, char *stop, const char *pending; uint8_t cbor_string_prefix = 0; char *(*encode_byte)(char *start, char *stop, - const char *byte, + const char *byte, const char *bytes_stop, const char escape, const long *map, const char **pending, uint8_t cbor_string_prefix, struct lf_buildctx *ctx); @@ -2362,7 +2365,8 @@ static char *_lf_encode_bytes(char *start, char *stop, */ if (bytes && !bytes_stop) { while (start < stop && *bytes != '\0') { - ret = encode_byte(start, stop, bytes, escape, map, + ret = encode_byte(start, stop, bytes, bytes_stop, + escape, map, &pending, cbor_string_prefix, ctx); if (ret == NULL) @@ -2372,7 +2376,8 @@ static char *_lf_encode_bytes(char *start, char *stop, } } else if (bytes) { while (start < stop && bytes < bytes_stop) { - ret = encode_byte(start, stop, bytes, escape, map, + ret = encode_byte(start, stop, bytes, bytes_stop, + escape, map, &pending, cbor_string_prefix, ctx); if (ret == NULL)