diff --git a/src/api/InkAPITest.cc b/src/api/InkAPITest.cc index 3ba3d903a96..738bd2ad461 100644 --- a/src/api/InkAPITest.cc +++ b/src/api/InkAPITest.cc @@ -6022,6 +6022,9 @@ REGRESSION_TEST(SDK_API_TSMimeHdrParse)(RegressionTest *test, int /* atype ATS_U if (TSMBufferDestroy(bufp1) == TS_ERROR) { SDK_RPRINT(test, "TSMimeHdrParse", "TestCase1", TC_FAIL, "Error in Destroying MBuffer"); } + TSMimeParserDestroy(parser); + *pstatus = REGRESSION_TEST_FAILED; + return; } else { start = parse_string; end = parse_string + strlen(parse_string) + 1; @@ -6087,7 +6090,9 @@ REGRESSION_TEST(SDK_API_TSMimeHdrParse)(RegressionTest *test, int /* atype ATS_U } field_loc2 = TSMimeHdrFieldNextDup(bufp1, mime_hdr_loc1, field_loc1); - if (compare_field_names(test, bufp1, mime_hdr_loc1, field_loc1, bufp1, mime_hdr_loc1, field_loc2) == TS_ERROR) { + if (field_loc2 == TS_NULL_MLOC) { + SDK_RPRINT(test, "TSMimeHdrFieldNextDup", "TestCase1", TC_FAIL, "TSMimeHdrFieldNextDup returns TS_NULL_MLOC"); + } else if (compare_field_names(test, bufp1, mime_hdr_loc1, field_loc1, bufp1, mime_hdr_loc1, field_loc2) == TS_ERROR) { SDK_RPRINT(test, "TSMimeHdrFieldNextDup", "TestCase1", TC_FAIL, "Incorrect Pointer"); } else { SDK_RPRINT(test, "TSMimeHdrFieldNextDup", "TestCase1", TC_PASS, "ok"); @@ -6401,6 +6406,7 @@ REGRESSION_TEST(SDK_API_TSUrlParse)(RegressionTest *test, int /* atype ATS_UNUSE if (TSMBufferDestroy(bufp) == TS_ERROR) { SDK_RPRINT(test, "TSUrlParse", url, TC_FAIL, "Error in Destroying MBuffer"); } + continue; } else { start = url; end = url + strlen(url); diff --git a/src/iocore/aio/test_AIO.cc b/src/iocore/aio/test_AIO.cc index 3ae808bbd17..44f60416524 100644 --- a/src/iocore/aio/test_AIO.cc +++ b/src/iocore/aio/test_AIO.cc @@ -187,7 +187,7 @@ dump_summary() double total_secs = 0.0; for (int i = 0; i < orig_n_accessors; i++) { double secs = (dev[i]->time_end - dev[i]->time_start) / 1000000000.0; - double ops_sec = (dev[i]->seq_reads + dev[i]->seq_writes + dev[i]->rand_reads) / secs; + double ops_sec = secs > 0.0 ? (dev[i]->seq_reads + dev[i]->seq_writes + dev[i]->rand_reads) / secs : 0.0; printf("%s: #sr:%d #sw:%d #rr:%d %0.1f secs %0.1f ops/sec\n", dev[i]->path, dev[i]->seq_reads, dev[i]->seq_writes, dev[i]->rand_reads, secs, ops_sec); total_secs += secs; @@ -198,20 +198,28 @@ dump_summary() printf("-----------------\n"); printf("aggregate results\n"); printf("-----------------\n"); - total_secs /= orig_n_accessors; - float sr = (total_seq_reads * seq_read_size) / total_secs; - sr /= 1024.0 * 1024.0; - float sw = (total_seq_writes * seq_write_size) / total_secs; - sw /= 1024.0 * 1024.0; - float rr = (total_rand_reads * rand_read_size) / total_secs; - rr /= 1024.0 * 1024.0; - printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_read\n", total_seq_reads, sr, total_seq_reads / total_secs, - total_seq_reads / total_secs / n_disk_path); - printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_write\n", total_seq_writes, sw, - total_seq_writes / total_secs, total_seq_writes / total_secs / n_disk_path); - printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk rand_read\n", total_rand_reads, rr, - total_rand_reads / total_secs, total_rand_reads / total_secs / n_disk_path); - printf("%0.2f total mbytes/sec\n", sr + sw + rr); + if (orig_n_accessors > 0) { + total_secs /= orig_n_accessors; + } + + if (total_secs > 0.0 && n_disk_path > 0) { + float sr = (total_seq_reads * seq_read_size) / total_secs; + sr /= 1024.0 * 1024.0; + float sw = (total_seq_writes * seq_write_size) / total_secs; + sw /= 1024.0 * 1024.0; + float rr = (total_rand_reads * rand_read_size) / total_secs; + rr /= 1024.0 * 1024.0; + + printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_read\n", total_seq_reads, sr, total_seq_reads / total_secs, + total_seq_reads / total_secs / n_disk_path); + printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk seq_write\n", total_seq_writes, sw, + total_seq_writes / total_secs, total_seq_writes / total_secs / n_disk_path); + printf("%f ops %0.2f mbytes/sec %0.1f ops/sec %0.1f ops/sec/disk rand_read\n", total_rand_reads, rr, + total_rand_reads / total_secs, total_rand_reads / total_secs / n_disk_path); + printf("%0.2f total mbytes/sec\n", sr + sw + rr); + } else { + printf("no measurable elapsed time, skipping aggregate rates\n"); + } printf("----------------------------------------------------------\n"); #if TS_USE_LINUX_IO_URING diff --git a/src/iocore/net/unit_tests/test_OCSPStapling.cc b/src/iocore/net/unit_tests/test_OCSPStapling.cc index dbeb71e6cb1..26a9f5e411f 100644 --- a/src/iocore/net/unit_tests/test_OCSPStapling.cc +++ b/src/iocore/net/unit_tests/test_OCSPStapling.cc @@ -97,8 +97,14 @@ TEST_CASE("OCSP stapling keeps SSL_CTX certificate map after later init failure" REQUIRE(SSL_CTX_use_certificate(ctx.get(), good.get()) == 1); - REQUIRE(SSL_CTX_add_extra_chain_cert(ctx.get(), issuer.get()) == 1); - issuer.release(); + // SSL_CTX_add_extra_chain_cert() takes ownership of the certificate only when it succeeds, so + // hand the raw pointer over and give it back to the unique_ptr if the call fails. + X509 *issuer_raw = issuer.release(); + + if (SSL_CTX_add_extra_chain_cert(ctx.get(), issuer_raw) != 1) { + issuer.reset(issuer_raw); + FAIL("SSL_CTX_add_extra_chain_cert failed"); + } REQUIRE(ssl_stapling_init_cert(ctx.get(), good.get(), "server.ocsp.pem", nullptr)); CHECK_FALSE(ssl_stapling_init_cert(ctx.get(), bad.get(), "signed-foo.pem", nullptr)); diff --git a/src/proxy/hdrs/unit_tests/test_Huffmancode.cc b/src/proxy/hdrs/unit_tests/test_Huffmancode.cc index 6a7c2cb22a3..b1d3ca75b4a 100644 --- a/src/proxy/hdrs/unit_tests/test_Huffmancode.cc +++ b/src/proxy/hdrs/unit_tests/test_Huffmancode.cc @@ -155,8 +155,8 @@ TEST_CASE("values_test", "[proxy][huffman]") REQUIRE(bytes == -1); continue; } - REQUIRE(dst_start[0] == ascii_value); REQUIRE(bytes == 1); + REQUIRE(dst_start[0] == ascii_value); } } @@ -336,10 +336,11 @@ TEST_CASE("decoder_roundtrip_fuzz", "[proxy][huffman]") std::vector encoded(src_len * 4 + 8); int64_t enc_len = huffman_encode(encoded.data(), encoded.size(), src.data(), src_len); REQUIRE(enc_len >= 0); + REQUIRE(enc_len <= static_cast(encoded.size())); // One byte of headroom guarantees success (see require_decoder_parity). std::vector decoded(src_len + 1); - int64_t dec_len = huffman_decode(decoded.data(), src_len + 1, encoded.data(), enc_len); + int64_t dec_len = huffman_decode(decoded.data(), src_len + 1, encoded.data(), static_cast(enc_len)); REQUIRE(dec_len == static_cast(src_len)); REQUIRE(memcmp(decoded.data(), src.data(), src_len) == 0); } diff --git a/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc b/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc index bf76965cf5d..758a1a1ccf5 100644 --- a/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc +++ b/src/proxy/http/remap/unit-tests/nexthop_test_stubs.cc @@ -105,7 +105,7 @@ build_request(int64_t sm_id, HttpSM *sm, sockaddr_in *ip, const char *os_hostnam } sm->t_state.request_data.api_info = new HttpApiInfo(); if (ip != nullptr) { - memcpy(&sm->t_state.request_data.src_ip.sa, ip, sizeof(sm->t_state.request_data.src_ip.sa)); + memcpy(&sm->t_state.request_data.src_ip.sin, ip, sizeof(*ip)); } sm->t_state.request_data.xact_start = time(0); diff --git a/src/proxy/http/remap/unit-tests/test_RemapPlugin.cc b/src/proxy/http/remap/unit-tests/test_RemapPlugin.cc index d2aaf3d3bc7..df890a59334 100644 --- a/src/proxy/http/remap/unit-tests/test_RemapPlugin.cc +++ b/src/proxy/http/remap/unit-tests/test_RemapPlugin.cc @@ -358,13 +358,13 @@ SCENARIO("unloading the plugin", "[plugin][core]") { REQUIRE_FALSE(sandboxDir.empty()); - std::string error; - PluginDebugObject *debugObject = nullptr; + std::string error; GIVEN("a 'done' function") { fs::path pluginConfigPath = fs::path("plugin_testing_calls.so"); RemapPluginUnitTest::Ptr plugin{setupSandBox(pluginConfigPath)}; + PluginDebugObject *debugObject = nullptr; bool result = loadPlugin(plugin.get(), error, debugObject); CHECK(true == result); @@ -387,6 +387,7 @@ SCENARIO("unloading the plugin", "[plugin][core]") { fs::path pluginConfigPath = fs::path("plugin_testing_calls.so"); RemapPluginUnitTest::Ptr plugin{setupSandBox(pluginConfigPath)}; + PluginDebugObject *debugObject = nullptr; bool result = loadPlugin(plugin.get(), error, debugObject); CHECK(true == result); diff --git a/src/proxy/http2/test_HPACK.cc b/src/proxy/http2/test_HPACK.cc index cde31b7c13f..94e9ae97d1f 100644 --- a/src/proxy/http2/test_HPACK.cc +++ b/src/proxy/http2/test_HPACK.cc @@ -331,13 +331,13 @@ prepare() cerr << "Cannot open " << input_dir << endl; return 1; } - struct stat st; - char name[PATH_MAX + 1] = ""; - strcat(name, input_dir.c_str()); while ((d = readdir(dir)) != nullptr) { - name[input_dir.length()] = '\0'; - ink_strlcat(name, d->d_name, sizeof(name)); - stat(name, &st); + struct stat st; + string name = input_dir + d->d_name; + + if (stat(name.c_str(), &st) != 0) { + continue; + } if (!S_ISDIR(st.st_mode)) { ++last; } diff --git a/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc b/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc index 291549135b4..4f5ddb21433 100644 --- a/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc +++ b/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc @@ -125,13 +125,18 @@ TEST_CASE("HPACK low level APIs", "[hpack]") uint8_t buf[BUFSIZE_FOR_REGRESSION_TEST]; int64_t encoded_len = encode_oversized_hpack_index(buf, sizeof(buf), 7, 0x80); + REQUIRE(encoded_len > 0); + REQUIRE(encoded_len <= static_cast(sizeof(buf))); + + size_t const block_len = static_cast(encoded_len); + HpackIndexingTable indexing_table(4096); std::unique_ptr headers(new HTTPHdr, destroy_http_hdr); headers->create(HTTPType::REQUEST); MIMEField *field = mime_field_create(headers->m_heap, headers->m_http->m_fields_impl); MIMEFieldWrapper header(field, headers->m_heap, headers->m_http->m_fields_impl); - int64_t len = decode_indexed_header_field(header, buf, buf + encoded_len, indexing_table); + int64_t len = decode_indexed_header_field(header, buf, buf + block_len, indexing_table); REQUIRE(len == HPACK_ERROR_COMPRESSION_ERROR); } @@ -286,8 +291,14 @@ TEST_CASE("HPACK low level APIs", "[hpack]") uint8_t buf[BUFSIZE_FOR_REGRESSION_TEST]; int64_t encoded_len = encode_oversized_hpack_index(buf, sizeof(buf), i.prefix, i.flag); uint8_t value[] = {0x05, 'v', 'a', 'l', 'u', 'e'}; - memcpy(buf + encoded_len, value, sizeof(value)); - encoded_len += sizeof(value); + + REQUIRE(encoded_len > 0); + REQUIRE(encoded_len <= static_cast(sizeof(buf) - sizeof(value))); + + size_t block_len = static_cast(encoded_len); + + memcpy(buf + block_len, value, sizeof(value)); + block_len += sizeof(value); HpackIndexingTable indexing_table(4096); std::unique_ptr headers(new HTTPHdr, destroy_http_hdr); @@ -295,7 +306,7 @@ TEST_CASE("HPACK low level APIs", "[hpack]") MIMEField *field = mime_field_create(headers->m_heap, headers->m_http->m_fields_impl); MIMEFieldWrapper header(field, headers->m_heap, headers->m_http->m_fields_impl); - int64_t len = decode_literal_header_field(header, buf, buf + encoded_len, indexing_table, MAX_FIELD_SIZE); + int64_t len = decode_literal_header_field(header, buf, buf + block_len, indexing_table, MAX_FIELD_SIZE); REQUIRE(len == HPACK_ERROR_COMPRESSION_ERROR); } diff --git a/src/proxy/http2/unit_tests/test_Http2Frame.cc b/src/proxy/http2/unit_tests/test_Http2Frame.cc index 6973f9f3867..6ce95929aa8 100644 --- a/src/proxy/http2/unit_tests/test_Http2Frame.cc +++ b/src/proxy/http2/unit_tests/test_Http2Frame.cc @@ -41,12 +41,17 @@ TEST_CASE("Http2Frame", "[http2][Http2Frame]") Http2PushPromiseFrame frame(id, flags, pp, hdr_block, hdr_block_len); int64_t written = frame.write_to(miob); - REQUIRE(written != -1); + REQUIRE(written > 0); CHECK(written == static_cast(HTTP2_FRAME_HEADER_LEN + sizeof(Http2StreamId) + hdr_block_len)); CHECK(written == miob_r->read_avail()); uint8_t buf[32] = {0}; - int64_t read = miob_r->read(buf, written); + + REQUIRE(written <= static_cast(sizeof(buf))); + + size_t const frame_len = static_cast(written); + int64_t read = miob_r->read(buf, written); + CHECK(read == written); uint8_t expected[] = { @@ -58,7 +63,8 @@ TEST_CASE("Http2Frame", "[http2][Http2Frame]") 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef ///< Header Block Fragment }; - CHECK(memcmp(buf, expected, written) == 0); + REQUIRE(frame_len == sizeof(expected)); + CHECK(memcmp(buf, expected, frame_len) == 0); } free_MIOBuffer(miob); diff --git a/src/proxy/logging/unit-tests/test_LogAccess.cc b/src/proxy/logging/unit-tests/test_LogAccess.cc index 0a33a6d8df7..40fc131d59c 100644 --- a/src/proxy/logging/unit-tests/test_LogAccess.cc +++ b/src/proxy/logging/unit-tests/test_LogAccess.cc @@ -122,7 +122,7 @@ populate_non_http_sm_data(NonHttpSmLogData &data, std::string_view method, std:: data.owned_path.assign(path.data(), path.size()); data.owned_url = synthesize_target(method, scheme, authority, path); set_socket_address(data.owned_client_addr, "192.0.2.10:4321"sv); - ats_ip_copy(&data.owned_client_src_addr.sa, &data.owned_client_addr.sa); + ats_ip_copy(&data.owned_client_src_addr, &data.owned_client_addr); data.m_client_port = ats_ip_port_host_order(&data.owned_client_addr.sa); add_header_field(data.owned_client_request, PSEUDO_HEADER_METHOD, method);