From nobody Mon May 20 13:33:13 2024 X-Original-To: dev-commits-src-all@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 4Vjdmp3QQLz5LGvk; Mon, 20 May 2024 13:33:14 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vjdmp0vFtz4Nwb; Mon, 20 May 2024 13:33:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716211994; 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=rpkUYWUzHhaPdfnTN/qjWdIM63B53FbAnNqmi478gMc=; b=jnFtBotsdLNiU8oya6DwsdjiHzG1G5ieZj2hWM8BdBw2VUr8pqdQkop6OUcuJtkVxeyOf2 jx3A3id27ybz6n1agH3EMewyzjddYWwxd86trHQguJFkGpQjW4BOx89dwxfL7xo/S4LVjl 7Vqr/ZepK6RPkdM3ia6Qzsp4aWoMrR7PIohfPtoIW1XObHlHNdMt4E09j6ql9ICZEhoKzI 4Ky996fuxmPKL0wKPBj92s8+YydtoWpA43qcU9X3u5n+Wya8ZSMhpJHcmbVs6YNAZfOtn9 NrTCsTr6hwS/KaIBNMb9SjgMo8kmIKly7dEOc5otHxELoHqEQe97Y9FPVCUCsg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716211994; a=rsa-sha256; cv=none; b=Avkug74CyXYENTI8WXQneHBk3m37ukfLvMZEeexxzc5ytoYYGw4Q8l3sKzNAUzeLv+5UXv ZHHYpTwkWCkbxTphD598Uzl9MPca1NcE5vGbCOV83d0VA36b6nrX2VE/7wIqwXs3JexMQP JfxeSqZKS2E3oBIvqSywO3MOUoDd4dlrNwqkAqDGQwdBWp0kdHL5EF2UmHDfVWqHQDxqzi gs3NDT8qJEbpW7r2TlOo8Ru24zsHLUWh4kThBHl6xRQL4IgSfIC/BoGM1Qg4L8eNznt4i5 1k3pz5VRB8s/BuKE3VUKohk15qQlYJr+ssrWtWVy8czUVbArpy+AdKlK+lAFDg== 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=1716211994; 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=rpkUYWUzHhaPdfnTN/qjWdIM63B53FbAnNqmi478gMc=; b=sZ+Sfk55vxCElPQvHm1nE7pGurCbgZxMp7TzQuwDVNC7uSnvYm2+YExKcE7Xumsk+aTq9Z kS2Ob43UYdHELDD1YPMWc6b9bsPtrPFTg9Hr1cTBJSPtNlTJYLqIcLXt70XAfmYa6En3KS wQQeyC23awsgxH0FmDVVCFSQ7rWV2refYFg1eHITeYGJUJc//WD0Dw8KoVUILw6WHRU4jG Lsj5gV880Nn54lN54Y7jf9uLv78HIiC7u0UWIXvbndWTVZwOdyaGF5pWHtJFCzYhcCfetc RUUEC8p/VHLoo9sepnTwAbbsL4hNxAU81YKptq9rzLqZTTpFLK7JL+cC9G369Q== 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 4Vjdmp0W0DzgL7; Mon, 20 May 2024 13:33:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44KDXDLq045803; Mon, 20 May 2024 13:33:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44KDXD6D045800; Mon, 20 May 2024 13:33:13 GMT (envelope-from git) Date: Mon, 20 May 2024 13:33:13 GMT Message-Id: <202405201333.44KDXD6D045800@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 02d98d1850f8 - main - libdiff: Add a test for the truncation issue. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 02d98d1850f870e535b93dccb7284dffe81d65d7 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=02d98d1850f870e535b93dccb7284dffe81d65d7 commit 02d98d1850f870e535b93dccb7284dffe81d65d7 Author: Dag-Erling Smørgrav AuthorDate: 2024-05-20 13:26:42 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-20 13:26:42 +0000 libdiff: Add a test for the truncation issue. Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D45218 --- etc/mtree/BSD.tests.dist | 2 ++ lib/libdiff/Makefile | 5 ++++ lib/libdiff/tests/Makefile | 8 ++++++ lib/libdiff/tests/libdiff_test.c | 61 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index d0451081022b..3f447f9ec25e 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -419,6 +419,8 @@ .. libdevdctl .. + libdiff + .. libexecinfo .. libkvm diff --git a/lib/libdiff/Makefile b/lib/libdiff/Makefile index 3fa8e6b05d2d..8541ff424de2 100644 --- a/lib/libdiff/Makefile +++ b/lib/libdiff/Makefile @@ -1,3 +1,5 @@ +.include + LIB= diff INTERNALLIB= # API not published or supported. @@ -12,4 +14,7 @@ WARNS= CFLAGS+= -I${SRCTOP}/contrib/libdiff/compat/include CFLAGS+= -I${SRCTOP}/contrib/libdiff/include +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/lib/libdiff/tests/Makefile b/lib/libdiff/tests/Makefile new file mode 100644 index 000000000000..278ad7c95dcf --- /dev/null +++ b/lib/libdiff/tests/Makefile @@ -0,0 +1,8 @@ +PACKAGE= tests + +ATF_TESTS_C= libdiff_test + +CFLAGS = -I${SRCTOP}/contrib/libdiff/lib -I${SRCTOP}/contrib/libdiff/include +LIBADD = diff + +.include diff --git a/lib/libdiff/tests/libdiff_test.c b/lib/libdiff/tests/libdiff_test.c new file mode 100644 index 000000000000..f12717686721 --- /dev/null +++ b/lib/libdiff/tests/libdiff_test.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2024 Klara, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +ATF_TC_WITH_CLEANUP(diff_atomize_truncated); +ATF_TC_HEAD(diff_atomize_truncated, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verify that the atomizer " + "does not crash when an input file is truncated"); +} +ATF_TC_BODY(diff_atomize_truncated, tc) +{ + char line[128]; + struct diff_config cfg = { .atomize_func = diff_atomize_text_by_line }; + struct diff_data d = { }; + const char *fn = atf_tc_get_ident(tc); + FILE *f; + unsigned char *p; + size_t size = 65536; + + ATF_REQUIRE((f = fopen(fn, "w+")) != NULL); + line[sizeof(line) - 1] = '\n'; + for (unsigned int i = 0; i <= size / sizeof(line); i++) { + memset(line, 'a' + i % 26, sizeof(line) - 1); + ATF_REQUIRE(fwrite(line, sizeof(line), 1, f) == 1); + } + ATF_REQUIRE(fsync(fileno(f)) == 0); + rewind(f); + ATF_REQUIRE(truncate(fn, size / 2) == 0); + ATF_REQUIRE((p = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fileno(f), 0)) != MAP_FAILED); + ATF_REQUIRE(diff_atomize_file(&d, &cfg, f, p, size, 0) == 0); + ATF_REQUIRE((size_t)d.len <= size / 2); + ATF_REQUIRE((size_t)d.len >= size / 2 - sizeof(line)); + ATF_REQUIRE(d.atomizer_flags & DIFF_ATOMIZER_FILE_TRUNCATED); +} +ATF_TC_CLEANUP(diff_atomize_truncated, tc) +{ + unlink(atf_tc_get_ident(tc)); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, diff_atomize_truncated); + return atf_no_error(); +}