Skip to content

Commit

Permalink
test_pkcs11.c: set file offset to 0 after ftruncate
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg29010.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
selvanair authored and mrbff committed Sep 9, 2024
1 parent 9276731 commit fca22e6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unit_tests/openvpn/test_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down

0 comments on commit fca22e6

Please sign in to comment.