public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "E. Madison Bray" <erik.m.bray@gmail.com>
To: cygwin@cygwin.com
Subject: Cygwin's sqlite3 modifies DLL search order
Date: Thu, 16 Jul 2020 18:46:11 +0200	[thread overview]
Message-ID: <CAOTD34bQzhw6Vv+8Aeh9hZ1oNO8L_H7h1Jne0mkTWCH5vLAH1A@mail.gmail.com> (raw)

Hi all,

After some significant headache I discovered a problem introduced by
the Cygwin patches for sqlite3.  The effect of this patch is that it
modifies the DLL search order for all subsequent DLL loads (by
filename instead of absolute path) in the application.

It contains the following patch in code which is executed in the
library's initialization:

   sqlite3_vfs_register(&winVfs, 1);

+#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
+  if( cygwin_conv_path ){
+    WCHAR buf[MAX_PATH];
+    cygwin_conv_path(CCP_POSIX_TO_WIN_W, "/usr/bin",
+        buf, MAX_PATH*sizeof(WCHAR));
+    osSetDllDirectoryW(buf);
+#ifdef _WIN32
+  }else if( cygwin_conv_to_full_win32_path ){
+    WCHAR buf[MAX_PATH];
+    char *buf1 = (char *)buf;
+    int i = MAX_PATH;
+    cygwin_conv_to_full_win32_path("/usr/bin", buf1);
+    while(--i>=0) buf[i] = buf1[i];
+    osSetDllDirectoryW(buf);
+#endif
+  }
+#endif
+

The call to SetDllDirectoryW modifies the default DLL search path by
always inserting /usr/bin, superseding the normal $PATH search.  Why
it does this I'm not sure.  It seems related to this patch, though
it's taken on a rather different form over the years:

http://sqlite.1065341.n5.nabble.com/Wrong-filename-handling-in-sqlite3-load-extension-for-Cygwin-td74049.html

It is related to how sqlite3 searches for extension libraries.  Though
I'd argue this patch is not even correct, since if the sqlite3 DLL is
installed somewhere other than /usr/bin (say /usr/local/bin) this
patch still won't be correct.

This is a problem since after using sqlite3 in an application,
subsequent DLL searches will always default to looking in /usr/bin
before any overrides I have on $PATH.  Is there any way we can get
this fixed?

Thanks,
Madison

             reply	other threads:[~2020-07-16 16:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 16:46 E. Madison Bray [this message]
2020-07-17  7:33 ` Jan Nijtmans
2020-07-29 11:22   ` E. Madison Bray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOTD34bQzhw6Vv+8Aeh9hZ1oNO8L_H7h1Jne0mkTWCH5vLAH1A@mail.gmail.com \
    --to=erik.m.bray@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).