Use realpath for path
[babeltrace.git] / formats / ctf / ctf.c
index 33287524f51d7b7aeb0b533f012cd60423b1469d..0f216933b6c06c215e8fba048c23f03e7c24fd22 100644 (file)
@@ -1146,10 +1146,11 @@ init_domain_name(struct ctf_trace *td)
        char *start, *end;
 
        start = td->path + strlen(td->collection_path);
-       start++;        /* skip / */
+       while (start[0] == '/')
+               start++;        /* skip / */
        end = strchr(start, '/');
        if (!end)
-               return;
+               end = start + strlen(start);
        memcpy(td->domain, start, end - start);
        td->domain[end - start] = '\0';
 }
@@ -1164,11 +1165,13 @@ init_proc_name(struct ctf_trace *td)
                return;
        memcpy(buf, td->path, PATH_MAX);
        start = buf + strlen(td->collection_path);
-       start++;        /* skip / */
+       while (start[0] == '/')
+               start++;        /* skip / */
        start = strchr(start, '/');     /* get begin of domain content */
        if (!start)
                return;
-       start++;        /* skip / */
+       while (start[0] == '/')
+               start++;        /* skip / */
        /* find last -, skips time */
        end = strrchr(start, '-');
        if (!end)
@@ -1199,11 +1202,13 @@ init_vpid(struct ctf_trace *td)
                return;
        memcpy(buf, td->path, PATH_MAX);
        start = buf + strlen(td->collection_path);
-       start++;        /* skip / */
+       while (start[0] == '/')
+               start++;        /* skip / */
        start = strchr(start, '/');     /* get begin of domain content */
        if (!start)
                return;
-       start++;        /* skip / */
+       while (start[0] == '/')
+               start++;        /* skip / */
        /* find last -, skips time */
        end = strrchr(start, '-');
        if (!end)
@@ -1234,6 +1239,7 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *collection_path,
        struct dirent *dirent;
        struct dirent *diriter;
        size_t dirent_len;
+       char *respath, *rescolpath;
 
        td->flags = flags;
 
@@ -1252,10 +1258,16 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *collection_path,
                ret = -errno;
                goto error_dirfd;
        }
-       strncpy(td->collection_path, collection_path, PATH_MAX);
-       td->collection_path[PATH_MAX - 1] = '\0';
-       strncpy(td->path, path, PATH_MAX);
-       td->path[PATH_MAX - 1] = '\0';
+       rescolpath = realpath(collection_path, td->collection_path);
+       if (!rescolpath) {
+               fprintf(stdout, "[error] collection path resolution failure\n");
+               return -EINVAL;
+       }
+       respath = realpath(path, td->path);
+       if (!rescolpath) {
+               fprintf(stdout, "[error] path resolution failure\n");
+               return -EINVAL;
+       }
        init_domain_name(td);
        init_proc_name(td);
        init_vpid(td);
This page took 0.023798 seconds and 4 git commands to generate.