Cygwin's sqlite3 modifies DLL search order

E. Madison Bray
Thu Jul 16 16:46:11 GMT 2020

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( 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);
+  }

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:

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?


More information about the Cygwin mailing list