From 64c1fddb253061a9773c6c4ed2a9c5a54702d21b Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Fri, 20 Apr 2018 15:53:58 +0200 Subject: dirmngr: More binary I/O on Windows for CRLs * dirmngr/crlcache.c (lock_db_file, crl_cache_insert): Open cache file in binary mode. -- CRLs on Windows would have line ending entries converted. This did not cause problems in a surprising amount of cases but can lead to unexpected and random parse / read errors. Especially with large CRLs like cacert. This bug has been around since 2004. GnuPG-Bug-Id: T3923 Signed-off-by: Andre Heinecke --- dirmngr/crlcache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'dirmngr/crlcache.c') diff --git a/dirmngr/crlcache.c b/dirmngr/crlcache.c index 6eeeb8dd3..0b2fe1641 100644 --- a/dirmngr/crlcache.c +++ b/dirmngr/crlcache.c @@ -125,6 +125,9 @@ idea anyway to limit the number of opened cache files. */ #define MAX_OPEN_DB_FILES 5 +#ifndef O_BINARY +# define O_BINARY 0 +#endif static const char oidstr_crlNumber[] = "2.5.29.20"; /* static const char oidstr_issuingDistributionPoint[] = "2.5.29.28"; */ @@ -1139,7 +1142,7 @@ lock_db_file (crl_cache_t cache, crl_cache_entry_t entry) xfree (fname); return NULL; } - fd = open (fname, O_RDONLY); + fd = open (fname, O_RDONLY | O_BINARY); if (fd == -1) { log_error (_("error opening cache file '%s': %s\n"), @@ -2051,7 +2054,7 @@ crl_cache_insert (ctrl_t ctrl, const char *url, ksba_reader_t reader) } } - fd_cdb = open (fname, O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd_cdb = open (fname, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd_cdb == -1) { err = gpg_error_from_errno (errno); -- cgit v1.2.3