Thursday, 27 July 2017

Use nsws_find_resource to find ca-bundle.crt

I cross compiled the Windows version of NetSurf on Linux and ran it under Wine.  It failed to find the ca-bundle.crt file.

I think nsws_find_resource() should be used to find the file instead of the Windows SearchPathA() API so that NetSurf will look in the NetSurf resources directory.

I have attached a patch, which should do the trick.

diff --git a/frontends/windows/main.c b/frontends/windows/main.c
index d019f10..8e86a29 100644
--- a/frontends/windows/main.c
+++ b/frontends/windows/main.c
@@ -156,32 +156,14 @@ static nserror set_defaults(struct nsoption_s *defaults)
        /* locate CA bundle and set as default, cannot rely on curl
         * compiled in default on windows.
         */
-       DWORD res_len;
-       DWORD buf_tchar_size = PATH_MAX + 1;
-       DWORD buf_bytes_size = sizeof(TCHAR) * buf_tchar_size;
-       char *ptr = NULL;
-       char *buf;
+       char buf[PATH_MAX];
        char *fname;
        HRESULT hres;
        char dldir[] = "Downloads";

-       buf = malloc(buf_bytes_size);
-       if (buf== NULL) {
-               return NSERROR_NOMEM;
-       }
-       buf[0] = '\0';
-
        /* locate certificate bundle */
-       res_len = SearchPathA(NULL,
-                             "ca-bundle.crt",
-                             NULL,
-                             buf_tchar_size,
-                             buf,
-                             &ptr);
-       if (res_len > 0) {
-               nsoption_setnull_charp(ca_bundle, strdup(buf));
-       }
-
+       nsws_find_resource(buf, "ca-bundle.crt", "windows/res/ca-bundle.crt");
+       nsoption_setnull_charp(ca_bundle, strdup(buf));

        /* download directory default
         *
@@ -204,8 +186,6 @@ static nserror set_defaults(struct nsoption_s *defaults)
                }
        }

-       free(buf);
-
        /* ensure homepage option has a default */
        nsoption_setnull_charp(homepage_url, strdup(NETSURF_HOMEPAGE));

No comments:

Post a Comment