diff options
Diffstat (limited to 'crypto/openssl/ssl/quic/json_enc.c')
| -rw-r--r-- | crypto/openssl/ssl/quic/json_enc.c | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/crypto/openssl/ssl/quic/json_enc.c b/crypto/openssl/ssl/quic/json_enc.c index 527230137ec2..9e14e821f1cc 100644 --- a/crypto/openssl/ssl/quic/json_enc.c +++ b/crypto/openssl/ssl/quic/json_enc.c @@ -24,16 +24,16 @@ static int wbuf_init(struct json_write_buf *wbuf, BIO *bio, size_t alloc) if (wbuf->buf == NULL) return 0; - wbuf->cur = 0; + wbuf->cur = 0; wbuf->alloc = alloc; - wbuf->bio = bio; + wbuf->bio = bio; return 1; } static void wbuf_cleanup(struct json_write_buf *wbuf) { OPENSSL_free(wbuf->buf); - wbuf->buf = NULL; + wbuf->buf = NULL; wbuf->alloc = 0; } @@ -87,12 +87,12 @@ static int wbuf_flush(struct json_write_buf *wbuf, int full) while (total_written < wbuf->cur) { if (!BIO_write_ex(wbuf->bio, - wbuf->buf + total_written, - wbuf->cur - total_written, - &written)) { + wbuf->buf + total_written, + wbuf->cur - total_written, + &written)) { memmove(wbuf->buf, - wbuf->buf + total_written, - wbuf->cur - total_written); + wbuf->buf + total_written, + wbuf->cur - total_written); wbuf->cur = 0; return 0; } @@ -131,8 +131,8 @@ static int json_ensure_stack_size(OSSL_JSON_ENC *json, size_t num_bytes) return 0; } - json->stack = stack; - json->stack_bytes = num_bytes; + json->stack = stack; + json->stack_bytes = num_bytes; return 1; } @@ -193,10 +193,10 @@ static int json_peek(OSSL_JSON_ENC *json) size_t obyte, obit; obyte = json->stack_end_byte; - obit = json->stack_end_bit; + obit = json->stack_end_bit; if (obit == 0) { - if (obyte == 0) - return -1; + if (obyte == 0) + return -1; --obyte; obit = CHAR_BIT - 1; @@ -236,8 +236,8 @@ static ossl_inline int in_pretty(const OSSL_JSON_ENC *json) int ossl_json_init(OSSL_JSON_ENC *json, BIO *bio, uint32_t flags) { memset(json, 0, sizeof(*json)); - json->flags = flags; - json->error = 0; + json->flags = flags; + json->error = 0; if (!wbuf_init(&json->wbuf, bio, 4096)) return 0; @@ -266,9 +266,9 @@ int ossl_json_flush_cleanup(OSSL_JSON_ENC *json) int ossl_json_reset(OSSL_JSON_ENC *json) { wbuf_clean(&json->wbuf); - json->stack_end_byte = 0; - json->stack_end_bit = 0; - json->error = 0; + json->stack_end_byte = 0; + json->stack_end_bit = 0; + json->error = 0; return 1; } @@ -605,7 +605,7 @@ static ossl_inline int hex_digit(int v) static ossl_inline void json_write_qstring_inner(OSSL_JSON_ENC *json, const char *str, size_t str_len, - int nul_term) + int nul_term) { char c, *o, obuf[7]; unsigned char *u_str; @@ -619,19 +619,33 @@ json_write_qstring_inner(OSSL_JSON_ENC *json, const char *str, size_t str_len, for (j = nul_term ? strlen(str) : str_len; j > 0; str++, j--) { c = *str; - u_str = (unsigned char*)str; + u_str = (unsigned char *)str; switch (c) { - case '\n': o = "\\n"; break; - case '\r': o = "\\r"; break; - case '\t': o = "\\t"; break; - case '\b': o = "\\b"; break; - case '\f': o = "\\f"; break; - case '"': o = "\\\""; break; - case '\\': o = "\\\\"; break; + case '\n': + o = "\\n"; + break; + case '\r': + o = "\\r"; + break; + case '\t': + o = "\\t"; + break; + case '\b': + o = "\\b"; + break; + case '\f': + o = "\\f"; + break; + case '"': + o = "\\\""; + break; + case '\\': + o = "\\\\"; + break; default: /* valid UTF-8 sequences according to RFC-3629 */ if (u_str[0] >= 0xc2 && u_str[0] <= 0xdf && j >= 2 - && u_str[1] >= 0x80 && u_str[1] <= 0xbf) { + && u_str[1] >= 0x80 && u_str[1] <= 0xbf) { memcpy(obuf, str, 2); obuf[2] = '\0'; str++, j--; @@ -639,10 +653,10 @@ json_write_qstring_inner(OSSL_JSON_ENC *json, const char *str, size_t str_len, break; } if (u_str[0] >= 0xe0 && u_str[0] <= 0xef && j >= 3 - && u_str[1] >= 0x80 && u_str[1] <= 0xbf - && u_str[2] >= 0x80 && u_str[2] <= 0xbf - && !(u_str[0] == 0xe0 && u_str[1] <= 0x9f) - && !(u_str[0] == 0xed && u_str[1] >= 0xa0)) { + && u_str[1] >= 0x80 && u_str[1] <= 0xbf + && u_str[2] >= 0x80 && u_str[2] <= 0xbf + && !(u_str[0] == 0xe0 && u_str[1] <= 0x9f) + && !(u_str[0] == 0xed && u_str[1] >= 0xa0)) { memcpy(obuf, str, 3); obuf[3] = '\0'; str += 2; @@ -651,11 +665,11 @@ json_write_qstring_inner(OSSL_JSON_ENC *json, const char *str, size_t str_len, break; } if (u_str[0] >= 0xf0 && u_str[0] <= 0xf4 && j >= 4 - && u_str[1] >= 0x80 && u_str[1] <= 0xbf - && u_str[2] >= 0x80 && u_str[2] <= 0xbf - && u_str[3] >= 0x80 && u_str[3] <= 0xbf - && !(u_str[0] == 0xf0 && u_str[1] <= 0x8f) - && !(u_str[0] == 0xf4 && u_str[1] >= 0x90)) { + && u_str[1] >= 0x80 && u_str[1] <= 0xbf + && u_str[2] >= 0x80 && u_str[2] <= 0xbf + && u_str[3] >= 0x80 && u_str[3] <= 0xbf + && !(u_str[0] == 0xf0 && u_str[1] <= 0x8f) + && !(u_str[0] == 0xf4 && u_str[1] >= 0x90)) { memcpy(obuf, str, 4); obuf[4] = '\0'; str += 3; |
