]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
libpts: Respect path separators when concatenating database filenames
authorMartin Willi <martin@revosec.ch>
Fri, 7 Mar 2014 11:28:07 +0000 (12:28 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:53:10 +0000 (15:53 +0200)
As we can't use the system native directory separator on cross-platform
measurements, we determine the path separator from the base directory format.

src/libpts/pts/pts_database.c

index e9a0e5faae08edeba7cbe2b81f1ce732a9a22ea3..f2e2c9c74df81a73d1267757788f60faf1c108f1 100644 (file)
@@ -48,7 +48,7 @@ METHOD(pts_database_t, get_pathname, char*,
        private_pts_database_t *this, bool is_dir, int id)
 {
        enumerator_t *e;
-       char *path, *name, *pathname;
+       char *path, *name, *sep, *pathname = NULL;
 
        if (is_dir)
        {
@@ -70,11 +70,21 @@ METHOD(pts_database_t, get_pathname, char*,
                                "SELECT d.path, f.name FROM files AS f "
                                "JOIN directories AS d ON d.id = f.dir WHERE f.id = ?",
                                 DB_INT, id, DB_TEXT, DB_TEXT);
-               if (!e || !e->enumerate(e, &path, &name) ||
-                       asprintf(&pathname, "%s%s%s",
-                                        path, streq(path, "/") ? "" : "/", name) == -1)
+               if (e && e->enumerate(e, &path, &name))
                {
-                       pathname = NULL;
+                       if (path[0] == '/')
+                       {       /* Unix style absolute path */
+                               sep = "/";
+                       }
+                       else
+                       {       /* Windows absolute path */
+                               sep = "\\";
+                       }
+                       if (asprintf(&pathname, "%s%s%s",
+                                                path, streq(path, "/") ? "" : sep, name) == -1)
+                       {
+                               pathname = NULL;
+                       }
                }
        }
        DESTROY_IF(e);
@@ -420,4 +430,3 @@ pts_database_t *pts_database_create(imv_database_t *imv_db)
 
        return &this->public;
 }
-