From 39f559a7ec2fbdc2bf3829a2a067bd41990e2ad2 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Tue, 4 Aug 2015 20:58:59 +0100 Subject: [PATCH] gpgme: Fix mkstemp bug Fixes https://github.com/Alexpux/MINGW-packages/issues/724 kind of .. issue 724 is down to the fact that GetModuleFileName is used as a landmark to locate other executables needed by gpgme. However if the static library is linked to then the executable will often not be in /mingw64/bin and the landmark location is irrelevant. I need to come up with something else instead, but the only idea I've got at present is to use a registry key for where MSYS2 was installed. .. breaking multiple installations ... and using the registry, two things that we've worked hard to avoid so far. Perhaps an env. var. is the best we can do here. Anyway, the landmark problem can be mitigated by putting the exe in the /mingw64/bin folder or perhaps moving the gnupg programs to the same folder as the exe. Both options are horrible. Whith that issue avoided, the next bug is the temporary files used by gpgme to communicate with gnupg are opened with _O_TEMPORARY meaning they get deleted when they're closed before the spawnee has had a chance to read them. To avoid this the file is reopened with the _O_TEMPORARY flag removed. --- .../0001-fix-incorrect-fd-pointer-check.patch | 12 +++++++ ...n-mkstemp-files-without-_O_TEMPORARY.patch | 31 +++++++++++++++++++ ...mkstemp.patch => 0003-mingw-mkstemp.patch} | 9 +++--- ...nupg.patch => 0004-gpgme-find-gnupg.patch} | 20 ++++++------ mingw-w64-gpgme/PKGBUILD | 28 ++++++++--------- .../debugging-dont-DeleteFileA-tmpfiles.patch | 29 ----------------- 6 files changed, 73 insertions(+), 56 deletions(-) create mode 100644 mingw-w64-gpgme/0001-fix-incorrect-fd-pointer-check.patch create mode 100644 mingw-w64-gpgme/0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch rename mingw-w64-gpgme/{gpgme-1.5.4-mingw-mkstemp.patch => 0003-mingw-mkstemp.patch} (69%) rename mingw-w64-gpgme/{gpgme-find-gnupg.patch => 0004-gpgme-find-gnupg.patch} (85%) delete mode 100644 mingw-w64-gpgme/debugging-dont-DeleteFileA-tmpfiles.patch diff --git a/mingw-w64-gpgme/0001-fix-incorrect-fd-pointer-check.patch b/mingw-w64-gpgme/0001-fix-incorrect-fd-pointer-check.patch new file mode 100644 index 0000000000..5b19fb4145 --- /dev/null +++ b/mingw-w64-gpgme/0001-fix-incorrect-fd-pointer-check.patch @@ -0,0 +1,12 @@ +diff -urN a/src/w32-util.c b/src/w32-util.c +--- a/src/w32-util.c 2014-07-30 10:40:16.000000000 +0100 ++++ b/src/w32-util.c 2015-08-04 22:35:22.308898700 +0100 +@@ -709,7 +709,7 @@ + return -1; + strcpy (stpcpy (tmpname, tmp), "\\gpgme-XXXXXX"); + *fd = mkstemp (tmpname); +- if (fd < 0) ++ if (*fd < 0) + { + free (tmpname); + return -1; diff --git a/mingw-w64-gpgme/0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch b/mingw-w64-gpgme/0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch new file mode 100644 index 0000000000..baac622506 --- /dev/null +++ b/mingw-w64-gpgme/0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch @@ -0,0 +1,31 @@ +diff -urN a/src/w32-util.c b/src/w32-util.c +--- a/src/w32-util.c 2015-08-04 22:35:22.574099100 +0100 ++++ b/src/w32-util.c 2015-08-04 22:35:22.948499800 +0100 +@@ -42,6 +42,7 @@ + #endif + #include + #include ++#include + + #if __MINGW64_VERSION_MAJOR >= 2 + # define _WIN32_IE 0x0501 /* Required by mingw64 toolkit. */ +@@ -715,6 +716,19 @@ + return -1; + } + ++ /* mingw-w64's mkstemp implementation opens files with _O_TEMPORARY ++ meaning they get deleted when the last handle to them is closed. ++ While ReOpenFile () could be used to work around this, it is not ++ available until Vista. Instead, close and recreate. */ ++ close (*fd); ++ *fd = _sopen(tmpname, ++ _O_RDWR | _O_CREAT | _O_EXCL | _O_BINARY, ++ _SH_DENYRW, _S_IREAD | _S_IWRITE); ++ if (*fd < 0) ++ { ++ free (tmpname); ++ return -1; ++ } + *name = tmpname; + return 0; + } diff --git a/mingw-w64-gpgme/gpgme-1.5.4-mingw-mkstemp.patch b/mingw-w64-gpgme/0003-mingw-mkstemp.patch similarity index 69% rename from mingw-w64-gpgme/gpgme-1.5.4-mingw-mkstemp.patch rename to mingw-w64-gpgme/0003-mingw-mkstemp.patch index 32a3c29a30..84d9b95ca1 100644 --- a/mingw-w64-gpgme/gpgme-1.5.4-mingw-mkstemp.patch +++ b/mingw-w64-gpgme/0003-mingw-mkstemp.patch @@ -1,6 +1,7 @@ ---- gpgme-1.5.4/src/w32-util.c.orig 2015-04-30 09:13:53.846200000 +0300 -+++ gpgme-1.5.4/src/w32-util.c 2015-04-30 09:14:42.224800000 +0300 -@@ -595,6 +595,7 @@ +diff -urN a/src/w32-util.c b/src/w32-util.c +--- a/src/w32-util.c 2015-08-04 22:35:23.135700100 +0100 ++++ b/src/w32-util.c 2015-08-04 22:35:23.354100500 +0100 +@@ -596,6 +596,7 @@ static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -8,7 +9,7 @@ /* Generate a temporary file name based on TMPL. TMPL must match the rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed does not exist at the time of the call to mkstemp. TMPL is -@@ -677,7 +678,7 @@ +@@ -678,7 +679,7 @@ gpg_err_set_errno (EEXIST); return -1; } diff --git a/mingw-w64-gpgme/gpgme-find-gnupg.patch b/mingw-w64-gpgme/0004-gpgme-find-gnupg.patch similarity index 85% rename from mingw-w64-gpgme/gpgme-find-gnupg.patch rename to mingw-w64-gpgme/0004-gpgme-find-gnupg.patch index 8f05a2c0da..3a14604978 100644 --- a/mingw-w64-gpgme/gpgme-find-gnupg.patch +++ b/mingw-w64-gpgme/0004-gpgme-find-gnupg.patch @@ -1,5 +1,6 @@ ---- gpgme-1.5.5/configure.ac.orig 2015-07-31 09:24:13.396403000 +0300 -+++ gpgme-1.5.5/configure.ac 2015-07-31 09:24:48.701872100 +0300 +diff -urN a/configure.ac b/configure.ac +--- a/configure.ac 2015-08-04 22:35:23.556900900 +0100 ++++ b/configure.ac 2015-08-04 22:35:24.087301800 +0100 @@ -161,10 +161,10 @@ *-mingw32ce*|*-mingw32*) have_dosish_system=yes @@ -15,9 +16,10 @@ #component_system='COM+' AM_PATH_GLIB_2_0 ---- gpgme-1.5.5/src/w32-util.c.orig 2015-07-31 09:27:08.507890100 +0300 -+++ gpgme-1.5.5/src/w32-util.c 2015-07-31 09:51:04.830243500 +0300 -@@ -418,6 +418,7 @@ +diff -urN a/src/w32-util.c b/src/w32-util.c +--- a/src/w32-util.c 2015-08-04 22:35:23.525700800 +0100 ++++ b/src/w32-util.c 2015-08-04 22:35:24.087301800 +0100 +@@ -419,6 +419,7 @@ return result; } @@ -25,7 +27,7 @@ dir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", "Software\\GNU\\GnuPG", "Install Directory"); -@@ -427,6 +428,7 @@ +@@ -428,6 +429,7 @@ free (dir); return result; } @@ -33,7 +35,7 @@ return NULL; } -@@ -503,13 +505,15 @@ +@@ -504,13 +506,15 @@ inst_dir = _gpgme_get_inst_dir (); gpg = find_program_in_inst_dir (inst_dir, @@ -51,7 +53,7 @@ _gpgme_debug (DEBUG_ENGINE, "_gpgme_get_gpg_path: '%s' not found", name); } -@@ -529,13 +533,15 @@ +@@ -530,13 +534,15 @@ inst_dir = _gpgme_get_inst_dir (); gpgconf = find_program_in_inst_dir (inst_dir, @@ -69,7 +71,7 @@ _gpgme_debug (DEBUG_ENGINE, "_gpgme_get_gpgconf_path: '%s' not found", name); } -@@ -553,9 +559,11 @@ +@@ -554,9 +560,11 @@ LOCK (get_path_lock); if (!w32spawn_program) w32spawn_program = find_program_in_inst_dir (inst_dir,"gpgme-w32spawn.exe"); diff --git a/mingw-w64-gpgme/PKGBUILD b/mingw-w64-gpgme/PKGBUILD index 555b9328e0..fa8f3766ed 100644 --- a/mingw-w64-gpgme/PKGBUILD +++ b/mingw-w64-gpgme/PKGBUILD @@ -4,7 +4,7 @@ _realname=gpgme pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}" pkgver=1.5.5 -pkgrel=4 +pkgrel=5 pkgdesc="A C wrapper library for GnuPG (mingw-w64)" arch=('any') url="http://www.gnupg.org/related_software/gpgme/" @@ -16,23 +16,23 @@ depends=("${MINGW_PACKAGE_PREFIX}-glib2" "${MINGW_PACKAGE_PREFIX}-npth" ) options=('!emptydirs') # '!strip' 'debug') -source=(ftp://ftp.gnupg.org/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2{,.sig} - gpgme-1.5.4-mingw-mkstemp.patch - gpgme-find-gnupg.patch - debugging-dont-DeleteFileA-tmpfiles.patch) +source=(https://www.gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2 + 0001-fix-incorrect-fd-pointer-check.patch + 0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch + 0003-mingw-mkstemp.patch + 0004-gpgme-find-gnupg.patch) sha1sums=('88476d72cb099e179de4040760502886f7a54926' - 'SKIP' - '8c7d7648772c29620b7fd23e867f60386ba92790' - '6dbd6f52c918facbe8fee5c5521ebad724ec9653' - '305408eb39c03d72aab15029f85bd8d629b87a2c') + '1828be3a0fcab854325295bc4a1d026b8d711d82' + '6f70ede9db1c86f7e4d04ade0dc0aee720221ee9' + '471223b20b8181dc6c09278901bb546434d46568' + 'e7d6fb6b1c99dd265eef363bce4ab2443662d383') prepare() { cd "${srcdir}"/${_realname}-${pkgver} - patch -p1 -i "${srcdir}"/gpgme-1.5.4-mingw-mkstemp.patch - patch -p1 -i "${srcdir}"/gpgme-find-gnupg.patch - if check_option "debug" "y"; then - patch -p1 -i "${srcdir}"/debugging-dont-DeleteFileA-tmpfiles.patch - fi + patch -p1 -i "${srcdir}"/0001-fix-incorrect-fd-pointer-check.patch + patch -p1 -i "${srcdir}"/0002-reopen-mkstemp-files-without-_O_TEMPORARY.patch + patch -p1 -i "${srcdir}"/0003-mingw-mkstemp.patch + patch -p1 -i "${srcdir}"/0004-gpgme-find-gnupg.patch autoreconf -ivf } diff --git a/mingw-w64-gpgme/debugging-dont-DeleteFileA-tmpfiles.patch b/mingw-w64-gpgme/debugging-dont-DeleteFileA-tmpfiles.patch deleted file mode 100644 index 6fa00a4991..0000000000 --- a/mingw-w64-gpgme/debugging-dont-DeleteFileA-tmpfiles.patch +++ /dev/null @@ -1,29 +0,0 @@ ---- gpgme-1.5.5/src/w32-io.c.orig 2014-07-30 10:40:16.000000000 +0100 -+++ gpgme-1.5.5/src/w32-io.c 2015-08-04 00:27:52.274897800 +0100 -@@ -1587,7 +1587,7 @@ - if (!arg_string) - { - close (tmp_fd); -- DeleteFileA (tmp_name); -+/* DeleteFileA (tmp_name); */ - return TRACE_SYSRES (-1); - } - -@@ -1617,7 +1617,7 @@ - TRACE_LOG1 ("CreateProcess failed: ec=%d", (int) GetLastError ()); - free (arg_string); - close (tmp_fd); -- DeleteFileA (tmp_name); -+/* DeleteFileA (tmp_name); */ - - /* FIXME: Should translate the error code. */ - gpg_err_set_errno (EIO); -@@ -1652,7 +1652,7 @@ - CloseHandle (pi.hProcess); - - close (tmp_fd); -- DeleteFileA (tmp_name); -+/* DeleteFileA (tmp_name); */ - - /* FIXME: Should translate the error code. */ - gpg_err_set_errno (EIO);