summaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authornicm <nicm>2019-12-16 16:39:03 +0000
committernicm <nicm>2019-12-16 16:39:03 +0000
commit1bdd4828bd0a13d6fb81c903078ad99ff2429b5d (patch)
tree8b7a92b596096fff6dc031ebab92ce55490a494b /file.c
parentb4520aaf2cb56cd14519e2df9d99ea6efc8ddd03 (diff)
If /dev/fd/X is a symlink and realpath() expands symlinks, /dev/fd/X
ends up pointing to the wrong place before it is passed to the client. The path is only used internally so there is no real need for realpath(), remove it and move the get_path function to file.c where all the callers are.
Diffstat (limited to 'file.c')
-rw-r--r--file.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/file.c b/file.c
index 9a3e79de..439d3464 100644
--- a/file.c
+++ b/file.c
@@ -33,6 +33,18 @@ static int file_next_stream = 3;
RB_GENERATE(client_files, client_file, entry, file_cmp);
+static char *
+file_get_path(struct client *c, const char *file)
+{
+ char *path;
+
+ if (*file == '/')
+ path = xstrdup(file);
+ else
+ xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file);
+ return (path);
+}
+
int
file_cmp(struct client_file *cf1, struct client_file *cf2)
{
@@ -237,7 +249,7 @@ file_write(struct client *c, const char *path, int flags, const void *bdata,
}
cf = file_create(c, file_next_stream++, cb, cbdata);
- cf->path = server_client_get_path(c, path);
+ cf->path = file_get_path(c, path);
if (c == NULL || c->flags & CLIENT_ATTACHED) {
if (flags & O_APPEND)
@@ -306,7 +318,7 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
}
cf = file_create(c, file_next_stream++, cb, cbdata);
- cf->path = server_client_get_path(c, path);
+ cf->path = file_get_path(c, path);
if (c == NULL || c->flags & CLIENT_ATTACHED) {
f = fopen(cf->path, "rb");