Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152490409
D45218.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D45218.id.diff
View Options
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
--- 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
--- a/lib/libdiff/Makefile
+++ b/lib/libdiff/Makefile
@@ -1,3 +1,5 @@
+.include <src.opts.mk>
+
LIB= diff
INTERNALLIB= # API not published or supported.
@@ -12,4 +14,7 @@
CFLAGS+= -I${SRCTOP}/contrib/libdiff/compat/include
CFLAGS+= -I${SRCTOP}/contrib/libdiff/include
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
.include <bsd.lib.mk>
diff --git a/lib/libdiff/tests/Makefile b/lib/libdiff/tests/Makefile
new file mode 100644
--- /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 <bsd.test.mk>
diff --git a/lib/libdiff/tests/libdiff_test.c b/lib/libdiff/tests/libdiff_test.c
new file mode 100644
--- /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 <sys/types.h>
+#include <sys/mman.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <arraylist.h>
+#include <diff_main.h>
+
+#include <atf-c.h>
+
+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();
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 16, 7:14 AM (8 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31566270
Default Alt Text
D45218.id.diff (2 KB)
Attached To
Mode
D45218: libdiff: Add a test for the truncation issue.
Attached
Detach File
Event Timeline
Log In to Comment