gkdbus: Fix underflow and unreachable code bug
[platform/upstream/glib.git] / gio / glocalvfs.c
index f8d85e4..00fec8e 100644 (file)
@@ -2,6 +2,8 @@
  * 
  * Copyright (C) 2006-2007 Red Hat, Inc.
  *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -80,7 +82,10 @@ static GFile *
 g_local_vfs_get_file_for_path (GVfs       *vfs,
                                const char *path)
 {
-  return _g_local_file_new (path);
+  if (*path == '\0')
+    return _g_dummy_file_new (path);
+  else
+    return _g_local_file_new (path);
 }
 
 static GFile *
@@ -89,14 +94,24 @@ g_local_vfs_get_file_for_uri (GVfs       *vfs,
 {
   char *path;
   GFile *file;
-  char *stripped_uri, *hash;
-  
+  char *stripped_uri, *hash, *question_mark;
+
+  /* As per https://url.spec.whatwg.org/#file-state, file: URIs can contain
+   * query and fragment sections. We ignore them in order to get only the file
+   * path. Compliance to this part of the WhatWG spec doesn’t necessarily mean
+   * we comply with the entire spec. */
   if (strchr (uri, '#') != NULL)
     {
       stripped_uri = g_strdup (uri);
       hash = strchr (stripped_uri, '#');
       *hash = 0;
     }
+  else if (strchr (uri, '?') != NULL)
+    {
+      stripped_uri = g_strdup (uri);
+      question_mark = strchr (stripped_uri, '?');
+      *question_mark = 0;
+    }
   else
     stripped_uri = (char *)uri;