From nobody Wed Sep 04 12:22:30 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WzM7p3G6Bz5TnL5; Wed, 04 Sep 2024 12:22:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WzM7p2Vp4z54bb; Wed, 4 Sep 2024 12:22:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725452550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XWkK/egcMQKQCVVAxlU9j5K8vMWbL6G/f5hMKYlwejg=; b=PEkwRshCjT8RpWac9daT6614qFyq6bHYRgl1buJrwpZgVsedgcOSVuyiYQGiSLZBvOx+7s +xg7qIwmLgEAPTQajZJ0yZcVXYLpE4UWqK+yvLkxdLTTanRKjq8BH2IX7oCCoq5SVRH6ST F4nMgWKuKVZMLSPkDGglvXvITGaQebMSi5FRo750pGA0sEWs71Zs7pKuh+TJe8/gSE2NqD HDMaTDPZbz4bcJeV6A8Nwpm/xFHoRfUMbVHPr05jNroYWfgE2fx4B7nQMpib5880orm4eg g2Bq2tnpK5Y00bPpwYEB2SNGxs39va7UC48jCla8fBei32k/4PFrD+HN5c9knw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725452550; a=rsa-sha256; cv=none; b=lxYMheLTlWKGWHJet/kMAmiT31sQgWVoeGFql1ux5ujogTxeYrdymt8ZYf0070bfKDDzQx LZZzDzWYzsSD/3wZVDZVR3nFe4x+q2os1kJ/N3TFT+MWUZDZUsP5xTRROb8qAaSGfYQ9lw j5J1wW7eyL+vofg1HUhvCP5D+JJo3UkQKfmQAD5PY8ocVgEr/h2NJTmPDWQjnlO99ShtSg 3bZltFZ9YUFpV+ykL6a10NJea/3getuVl8t0Pi3rdvuH51HQVGlKkb5WqGwme2FttL3rN7 hg6D/ZwYpu08G4guRu4IwJN3ciYYN3Fp0UDWml86VjCrZdHNzjADmLRx3imxqw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725452550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XWkK/egcMQKQCVVAxlU9j5K8vMWbL6G/f5hMKYlwejg=; b=hlxVoAuzb1UxZpJGXLd/y36gqlsQz6fF93klhLESSaUv0y5mpQqEwvAuy/RBV6+kabKJ1M LxaHnkV46AEZkoTFu1NhQUkVtmx+GB3pva6nkrSnaiytDgdIew5eJJuZTTy9Ch5c0vL9Em b6ImzD6Yqj/6fdoScOkIICMWmp2HqH0x2sirrLrlBej7tL9tUv3cDHQp732Pv2sRSF6e93 xWcdVBy+ZdE4AH6xa5ihVwtLEoqOsCqr4nPkw9yy/EF6uHuzdxel3vuOTxrvzJj1Q8RTSg AnAQ8qVu/ZMo0VWlTrY/XgZ4SyMhI/cpZr1wSwyr+f9dvDrI3FcSIDIGqU669w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WzM7p26QKzPdw; Wed, 4 Sep 2024 12:22:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 484CMUgS061744; Wed, 4 Sep 2024 12:22:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 484CMUoR061741; Wed, 4 Sep 2024 12:22:30 GMT (envelope-from git) Date: Wed, 4 Sep 2024 12:22:30 GMT Message-Id: <202409041222.484CMUoR061741@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mariusz Zaborski Subject: git: 2981431e044f - main - libnv: add test to verify null termination of string in array List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: oshogbo X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2981431e044fae3bc87e6fa891b8230b484dc84b Auto-Submitted: auto-generated The branch main has been updated by oshogbo: URL: https://cgit.FreeBSD.org/src/commit/?id=2981431e044fae3bc87e6fa891b8230b484dc84b commit 2981431e044fae3bc87e6fa891b8230b484dc84b Author: Mariusz Zaborski AuthorDate: 2024-08-29 13:44:03 +0000 Commit: Mariusz Zaborski CommitDate: 2024-09-04 11:43:07 +0000 libnv: add test to verify null termination of string in array Differential Revision: https://reviews.freebsd.org/D46138 --- lib/libnv/tests/nv_array_tests.cc | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/libnv/tests/nv_array_tests.cc b/lib/libnv/tests/nv_array_tests.cc index 06d7525c3e1d..9acbaef67eba 100644 --- a/lib/libnv/tests/nv_array_tests.cc +++ b/lib/libnv/tests/nv_array_tests.cc @@ -1,6 +1,5 @@ /*- - * Copyright (c) 2015 Mariusz Zaborski - * All rights reserved. + * Copyright (c) 2015-2024 Mariusz Zaborski * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,6 +26,7 @@ #include #include #include +#include #include #include @@ -1161,6 +1161,58 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__pack) free(packed); } + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_string_array_nonull__pack); +ATF_TEST_CASE_BODY(nvlist_string_array_nonull__pack) +{ + nvlist_t *testnvl, *unpacked; + const char *somestr[3] = { "a", "b", "XXX" }; + uint8_t *packed, *twopages, *dataptr, *secondpage; + size_t packed_size, page_size; + bool found; + + page_size = sysconf(_SC_PAGESIZE); + testnvl = nvlist_create(0); + ATF_REQUIRE(testnvl != NULL); + ATF_REQUIRE_EQ(nvlist_error(testnvl), 0); + nvlist_add_string_array(testnvl, "nvl/string", somestr, + nitems(somestr)); + ATF_REQUIRE_EQ(nvlist_error(testnvl), 0); + + packed = (uint8_t *)nvlist_pack(testnvl, &packed_size); + ATF_REQUIRE(packed != NULL); + + twopages = (uint8_t *)mmap(NULL, page_size * 2, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + ATF_REQUIRE(twopages != MAP_FAILED); + dataptr = &twopages[page_size - packed_size]; + secondpage = &twopages[page_size]; + + memset(twopages, 'A', page_size * 2); + + mprotect(secondpage, page_size, PROT_NONE); + memcpy(dataptr, packed, packed_size); + + found = false; + for (size_t i = 0; i < packed_size - 3; i++) { + if (dataptr[i] == 'X' && dataptr[i + 1] == 'X' && + dataptr[i + 2] == 'X' && dataptr[i + 3] == '\0') { + dataptr[i + 3] = 'X'; + found = true; + break; + } + } + ATF_REQUIRE(found == true); + + unpacked = nvlist_unpack(dataptr, packed_size, 0); + ATF_REQUIRE(unpacked == NULL); + + nvlist_destroy(testnvl); + free(packed); + munmap(twopages, page_size * 2); +} + + ATF_INIT_TEST_CASES(tp) { @@ -1190,5 +1242,7 @@ ATF_INIT_TEST_CASES(tp) ATF_ADD_TEST_CASE(tp, nvlist_descriptor_array__pack) ATF_ADD_TEST_CASE(tp, nvlist_string_array__pack) ATF_ADD_TEST_CASE(tp, nvlist_nvlist_array__pack) + + ATF_ADD_TEST_CASE(tp, nvlist_string_array_nonull__pack) }