From dcf735009c8caabf5e4a9feeb0d32907aafe8f17 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 12 Aug 2024 19:21:58 -0400 Subject: [PATCH] test_pkcs11.c: set file offset to 0 after ftruncate Currently key and cert file fd's are reused after ftruncate() without setting the offset to zero. This causes subsequent data to be written at some finite offset with the hole in the file automatically filled by zeros. Fix it by calling lseek() to set the offset to zero. The test works nevertheless because p11tool seem to generously ignore any junk before the "BEGIN" marker. Change-Id: Ib0fe15a4ba18d89216b0288e6cd6be66ed377bd4 Signed-off-by: Selva Nair Acked-by: Gert Doering Message-Id: <20240812232158.3776869-1-selva.nair@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29010.html Signed-off-by: Gert Doering --- tests/unit_tests/openvpn/test_pkcs11.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit_tests/openvpn/test_pkcs11.c b/tests/unit_tests/openvpn/test_pkcs11.c index 5518fa15..3fe3e460 100644 --- a/tests/unit_tests/openvpn/test_pkcs11.c +++ b/tests/unit_tests/openvpn/test_pkcs11.c @@ -273,6 +273,8 @@ init(void **state) assert_int_equal(ftruncate(cert_fd, 0), 0); assert_int_equal(ftruncate(key_fd, 0), 0); + assert_int_equal(lseek(cert_fd, 0, SEEK_SET), 0); + assert_int_equal(lseek(key_fd, 0, SEEK_SET), 0); num_certs++; }