QUIC QLOG: Fix ANSI
authorHugo Landau <hlandau@openssl.org>
Mon, 4 Mar 2024 22:56:45 +0000 (22:56 +0000)
committerHugo Landau <hlandau@openssl.org>
Wed, 6 Mar 2024 20:44:48 +0000 (20:44 +0000)
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23744)

test/json_test.c
test/quic_qlog_test.c

index 8cde1be2e3e5c5da4358e28e24e48f8dae1d09ca..5a054b7c6dc57e75ae123db0223fb7f0ba78d190 100644 (file)
@@ -89,7 +89,7 @@ enum {
     OPK_CALL_D,         /* (OSSL_JSON_ENC *, double) */
     OPK_CALL_PZ,        /* (OSSL_JSON_ENC *, const void *, size_t) */
     OPK_ASSERT_ERROR,   /* (OSSL_JSON_ENC *, int expect_error) */
-    OPK_INIT_FLAGS,     /* (uint32_t flags) */
+    OPK_INIT_FLAGS      /* (uint32_t flags) */
 };
 
 typedef void (*fp_type)(OSSL_JSON_ENC *);
index fb945317339e04cf768cdfc0dbe468cd18665df6..e54ced2f0eb59d37bf55ecf2ee4b29511d286e48 100644 (file)
 #include "internal/qlog.h"
 #include "testutil.h"
 
-static const char expected[] =
-    "\x1e{\"qlog_version\":\"0.3\",\"qlog_format\":\"JSON-SEQ\",\"title\":"
-    "\"test title\",\"description\":\"test description\",\"trace\":{"
-    "\"common_fields\":{\"time_format\":\"delta\",\"protocol_type\":"
-    "[\"QUIC\"],\"group_id\":\"test group ID\",\"system_info\":{"
-    "\"process_id\":123}},\"vantage_point\":{\"type\":\"client\","
-    "\"name\":\"OpenSSL/x.y.z\"}}}\n"
-
-    "\x1e{\"name\":\"transport:packet_sent\",\"data\":{\"field1\":\"foo\","
-    "\"field2\":\"bar\",\"field3\":42,\"field4\":\"1152921504606846976\","
-    "\"field5\":\"18446744073709551615\",\"field6\":false,\"field7\":true,"
-    "\"field8\":\"01af\",\"field9\":\"55\",\"subgroup\":{\"field10\":\"baz\"},"
-    "\"array\":[\"a\",\"b\"]},\"time\":170653117000}\n"
-
-    "\x1e{\"name\":\"transport:packet_sent\",\"data\":{\"field1\":\"bar\"},"
-    "\"time\":1000}\n"
-    ;
+/*
+ * Unfortunately, this must be expressed as an array and not a string literal as
+ * ANSI C only guarantees support for up to 509 characters in a string literal.
+ */
+static const char expected[] = {
+     30, '{', '"', 'q', 'l', 'o', 'g', '_', 'v', 'e', 'r', 's', 'i', 'o', 'n',
+    '"', ':', '"', '0', '.', '3', '"', ',', '"', 'q', 'l', 'o', 'g', '_', 'f',
+    'o', 'r', 'm', 'a', 't', '"', ':', '"', 'J', 'S', 'O', 'N', '-', 'S', 'E',
+    'Q', '"', ',', '"', 't', 'i', 't', 'l', 'e', '"', ':', '"', 't', 'e', 's',
+    't', ' ', 't', 'i', 't', 'l', 'e', '"', ',', '"', 'd', 'e', 's', 'c', 'r',
+    'i', 'p', 't', 'i', 'o', 'n', '"', ':', '"', 't', 'e', 's', 't', ' ', 'd',
+    'e', 's', 'c', 'r', 'i', 'p', 't', 'i', 'o', 'n', '"', ',', '"', 't', 'r',
+    'a', 'c', 'e', '"', ':', '{', '"', 'c', 'o', 'm', 'm', 'o', 'n', '_', 'f',
+    'i', 'e', 'l', 'd', 's', '"', ':', '{', '"', 't', 'i', 'm', 'e', '_', 'f',
+    'o', 'r', 'm', 'a', 't', '"', ':', '"', 'd', 'e', 'l', 't', 'a', '"', ',',
+    '"', 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l', '_', 't', 'y', 'p', 'e', '"',
+    ':', '[', '"', 'Q', 'U', 'I', 'C', '"', ']', ',', '"', 'g', 'r', 'o', 'u',
+    'p', '_', 'i', 'd', '"', ':', '"', 't', 'e', 's', 't', ' ', 'g', 'r', 'o',
+    'u', 'p', ' ', 'I', 'D', '"', ',', '"', 's', 'y', 's', 't', 'e', 'm', '_',
+    'i', 'n', 'f', 'o', '"', ':', '{', '"', 'p', 'r', 'o', 'c', 'e', 's', 's',
+    '_', 'i', 'd', '"', ':', '1', '2', '3', '}', '}', ',', '"', 'v', 'a', 'n',
+    't', 'a', 'g', 'e', '_', 'p', 'o', 'i', 'n', 't', '"', ':', '{', '"', 't',
+    'y', 'p', 'e', '"', ':', '"', 'c', 'l', 'i', 'e', 'n', 't', '"', ',', '"',
+    'n', 'a', 'm', 'e', '"', ':', '"', 'O', 'p', 'e', 'n', 'S', 'S', 'L', '/',
+    'x', '.', 'y', '.', 'z', '"', '}', '}', '}',  10,  30, '{', '"', 'n', 'a',
+    'm', 'e', '"', ':', '"', 't', 'r', 'a', 'n', 's', 'p', 'o', 'r', 't', ':',
+    'p', 'a', 'c', 'k', 'e', 't', '_', 's', 'e', 'n', 't', '"', ',', '"', 'd',
+    'a', 't', 'a', '"', ':', '{', '"', 'f', 'i', 'e', 'l', 'd', '1', '"', ':',
+    '"', 'f', 'o', 'o', '"', ',', '"', 'f', 'i', 'e', 'l', 'd', '2', '"', ':',
+    '"', 'b', 'a', 'r', '"', ',', '"', 'f', 'i', 'e', 'l', 'd', '3', '"', ':',
+    '4', '2', ',', '"', 'f', 'i', 'e', 'l', 'd', '4', '"', ':', '"', '1', '1',
+    '5', '2', '9', '2', '1', '5', '0', '4', '6', '0', '6', '8', '4', '6', '9',
+    '7', '6', '"', ',', '"', 'f', 'i', 'e', 'l', 'd', '5', '"', ':', '"', '1',
+    '8', '4', '4', '6', '7', '4', '4', '0', '7', '3', '7', '0', '9', '5', '5',
+    '1', '6', '1', '5', '"', ',', '"', 'f', 'i', 'e', 'l', 'd', '6', '"', ':',
+    'f', 'a', 'l', 's', 'e', ',', '"', 'f', 'i', 'e', 'l', 'd', '7', '"', ':',
+    't', 'r', 'u', 'e', ',', '"', 'f', 'i', 'e', 'l', 'd', '8', '"', ':', '"',
+    '0', '1', 'a', 'f', '"', ',', '"', 'f', 'i', 'e', 'l', 'd', '9', '"', ':',
+    '"', '5', '5', '"', ',', '"', 's', 'u', 'b', 'g', 'r', 'o', 'u', 'p', '"',
+    ':', '{', '"', 'f', 'i', 'e', 'l', 'd', '1', '0', '"', ':', '"', 'b', 'a',
+    'z', '"', '}', ',', '"', 'a', 'r', 'r', 'a', 'y', '"', ':', '[', '"', 'a',
+    '"', ',', '"', 'b', '"', ']', '}', ',', '"', 't', 'i', 'm', 'e', '"', ':',
+    '1', '7', '0', '6', '5', '3', '1', '1', '7', '0', '0', '0', '}',  10,  30,
+    '{', '"', 'n', 'a', 'm', 'e', '"', ':', '"', 't', 'r', 'a', 'n', 's', 'p',
+    'o', 'r', 't', ':', 'p', 'a', 'c', 'k', 'e', 't', '_', 's', 'e', 'n', 't',
+    '"', ',', '"', 'd', 'a', 't', 'a', '"', ':', '{', '"', 'f', 'i', 'e', 'l',
+    'd', '1', '"', ':', '"', 'b', 'a', 'r', '"', '}', ',', '"', 't', 'i', 'm',
+    'e', '"', ':', '1', '0', '0', '0', '}',  10
+};
 
 static const unsigned char bin_buf[] = {
     0x01, 0xaf
@@ -110,7 +142,7 @@ static int test_qlog(void)
     if (!TEST_size_t_gt(buf_len, 0))
         goto err;
 
-    if (!TEST_mem_eq(buf, buf_len, expected, sizeof(expected) - 1))
+    if (!TEST_mem_eq(buf, buf_len, expected, sizeof(expected)))
         goto err;
 
     testresult = 1;