From 005e462e01b58015f3e1d841b185186e6b5d4e14 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 10 Nov 2015 22:29:33 +0000 Subject: Handle absolute paths properly, and don't use resolved path in realpath() fails. --- cmd-load-buffer.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cmd-load-buffer.c') diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index c55e6c11..d81288f3 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -77,11 +77,15 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) else cwd = "."; - xasprintf(&file, "%s/%s", cwd, path); - if (realpath(file, resolved) == NULL) - f = NULL; + if (*path == '/') + file = xstrdup(path); else - f = fopen(resolved, "rb"); + xasprintf(&file, "%s/%s", cwd, path); + if (realpath(file, resolved) == NULL) { + cmdq_error(cmdq, "%s: %s", file, strerror(errno)); + return (CMD_RETURN_ERROR); + } + f = fopen(resolved, "rb"); free(file); if (f == NULL) { cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); -- cgit From 6f3475c6c713245f5ec760298af9a04b8465b844 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 10 Nov 2015 22:33:47 +0000 Subject: If realpath() fails just try the original path. --- cmd-load-buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cmd-load-buffer.c') diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index d81288f3..9352cbe5 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -81,8 +81,9 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) file = xstrdup(path); else xasprintf(&file, "%s/%s", cwd, path); - if (realpath(file, resolved) == NULL) { - cmdq_error(cmdq, "%s: %s", file, strerror(errno)); + if (realpath(file, resolved) == NULL && + strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { + cmdq_error(cmdq, "%s: %s", file, strerror(ENAMETOOLONG)); return (CMD_RETURN_ERROR); } f = fopen(resolved, "rb"); -- cgit