From d0bc5466148b6afa65aa9d1bb71ba3cd2ec912e1 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 26 May 2026 17:56:01 +0900 Subject: [PATCH] OpenBSD: fix CLI build and PCSC exit handling OpenBSD builds were relying on ggod to generate embedded resource headers. That tool is not available on a stock OpenBSD 7.9 install, and using base od directly is not a safe substitute because it emits zero-padded decimal values such as 060 and 098. Those tokens are then included in C++ source and parsed as octal constants, which either changes values or fails compilation. Use hexdump with an explicit unsigned-byte format for OpenBSD. It is part of the base system and emits unpadded decimal byte values suitable for the existing resource-header pipeline. The text-mode binary also crashed on normal process exit on OpenBSD, including after --version, --test, create, mount, list, and dismount. GDB showed the crash in libpcsclite_real during SCardReleaseContext(), called from the static SCardManager destructor. This happened even for commands that did not use EMV or security-token support because the static manager constructor eagerly initialized PC/SC at startup. Avoid eager PC/SC initialization and exit-time finalization on OpenBSD. The existing call sites still initialize PC/SC lazily when EMV/token operations need it, while ordinary CLI commands no longer touch pcsc-lite and no longer crash during static destruction. Validated on OpenBSD 7.9 amd64 with: - gmake NOGUI=1 -j2 - veracrypt --text --version - veracrypt --text --test - device-hosted create/mount/list/dismount smoke test through doas/vnd Refs #1589. Refs #1593. --- src/Build/Include/Makefile.inc | 2 +- src/Common/SCardManager.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Build/Include/Makefile.inc b/src/Build/Include/Makefile.inc index 52e0d650..be534871 100644 --- a/src/Build/Include/Makefile.inc +++ b/src/Build/Include/Makefile.inc @@ -96,7 +96,7 @@ endif # Embedded files ifeq "$(PLATFORM)" "OpenBSD" -OD_BIN := ggod -v -t u1 -A n +OD_BIN := hexdump -v -e '1/1 "%u "' else OD_BIN := od -v -t u1 -A n endif diff --git a/src/Common/SCardManager.cpp b/src/Common/SCardManager.cpp index 40578d39..cb97c1a0 100644 --- a/src/Common/SCardManager.cpp +++ b/src/Common/SCardManager.cpp @@ -7,12 +7,16 @@ namespace VeraCrypt SCardManager::SCardManager() { +#ifndef TC_OPENBSD loader->Initialize(); +#endif } SCardManager::~SCardManager() { +#ifndef TC_OPENBSD loader->Finalize(); +#endif } vector SCardManager::GetReaders() @@ -106,4 +110,4 @@ namespace VeraCrypt throw InvalidEMVPath(); } -} \ No newline at end of file +}