From e24503a8e9a9125e4471b89cc5ea0b881579c066 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 2 Jul 2019 12:08:45 +0100 Subject: [PATCH 1/3] gvfs: Add an assertion to check that get_file_for_uri() is never NULL It cannot return a NULL value, as none of its callers have error handlng. Add an assertion to check the values returned by the VFS implementations. Signed-off-by: Philip Withnall Helps: #1819 --- gio/gvfs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gio/gvfs.c b/gio/gvfs.c index 5805a7904..3475624cf 100644 --- a/gio/gvfs.c +++ b/gio/gvfs.c @@ -236,7 +236,7 @@ g_vfs_get_file_for_uri (GVfs *vfs, const char *uri) { GVfsClass *class; - GFile *ret; + GFile *ret = NULL; g_return_val_if_fail (G_IS_VFS (vfs), NULL); g_return_val_if_fail (uri != NULL, NULL); @@ -244,10 +244,12 @@ g_vfs_get_file_for_uri (GVfs *vfs, class = G_VFS_GET_CLASS (vfs); ret = get_file_for_uri_internal (vfs, uri); - if (ret) - return ret; + if (!ret) + ret = (* class->get_file_for_uri) (vfs, uri); - return (* class->get_file_for_uri) (vfs, uri); + g_assert (ret != NULL); + + return g_steal_pointer (&ret); } /** From 4b0421a73048f51031bba710bc0d155e35098cb5 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 2 Jul 2019 12:09:42 +0100 Subject: [PATCH 2/3] gwinhttpfile: Document constructor as potentially returning NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can return NULL if the URI was badly encoded or couldn’t be handled by Windows’ API. Signed-off-by: Philip Withnall Helps: #1819 --- gio/win32/gwinhttpfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c index 465f41b6b..cf5eed31d 100644 --- a/gio/win32/gwinhttpfile.c +++ b/gio/win32/gwinhttpfile.c @@ -80,7 +80,7 @@ g_winhttp_file_init (GWinHttpFile *winhttp) * @vfs: GWinHttpVfs to use * @uri: URI of the GWinHttpFile to create. * - * Returns: new winhttp #GFile. + * Returns: (nullable): new winhttp #GFile, or %NULL if there was an error constructing it. */ GFile * _g_winhttp_file_new (GWinHttpVfs *vfs, From 562ac9de4354c34b5518e17a184102bf1eef5667 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 2 Jul 2019 12:10:21 +0100 Subject: [PATCH 3/3] gwinhttpvfs: Fall back to wrapped VFS if creating a HTTP file fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we fail to create a GWinhttpFile for a URI (for example, because it’s an invalid URI or is badly encoded), don’t just return NULL. Instead, fall back to the wrapped VFS which might be able to handle it instead. Signed-off-by: Philip Withnall Fixes: #1819 --- gio/win32/gwinhttpvfs.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gio/win32/gwinhttpvfs.c b/gio/win32/gwinhttpvfs.c index 038368f81..91d7fed9d 100644 --- a/gio/win32/gwinhttpvfs.c +++ b/gio/win32/gwinhttpvfs.c @@ -165,15 +165,25 @@ g_winhttp_vfs_get_file_for_uri (GVfs *vfs, { GWinHttpVfs *winhttp_vfs = G_WINHTTP_VFS (vfs); int i; + GFile *ret = NULL; /* If it matches one of "our" schemes, handle it */ for (i = 0; i < G_N_ELEMENTS (winhttp_uri_schemes); i++) - if (g_ascii_strncasecmp (uri, winhttp_uri_schemes[i], strlen (winhttp_uri_schemes[i])) == 0 && - uri[strlen (winhttp_uri_schemes[i])] == ':') - return _g_winhttp_file_new (winhttp_vfs, uri); + { + if (g_ascii_strncasecmp (uri, winhttp_uri_schemes[i], strlen (winhttp_uri_schemes[i])) == 0 && + uri[strlen (winhttp_uri_schemes[i])] == ':') + { + ret = _g_winhttp_file_new (winhttp_vfs, uri); + } + } /* For other URIs fallback to the wrapped GVfs */ - return g_vfs_get_file_for_uri (winhttp_vfs->wrapped_vfs, uri); + if (ret == NULL) + ret = g_vfs_get_file_for_uri (winhttp_vfs->wrapped_vfs, uri); + + g_assert (ret != NULL); + + return g_steal_pointer (&ret); } static const gchar * const *