version 1.48, 2017/01/06 13:26:09 |
version 1.49, 2017/02/14 18:13:05 |
|
|
struct args *args = self->args; |
struct args *args = self->args; |
struct cmd_load_buffer_data *cdata; |
struct cmd_load_buffer_data *cdata; |
struct client *c = item->client; |
struct client *c = item->client; |
struct session *s; |
|
FILE *f; |
FILE *f; |
const char *path, *bufname, *cwd; |
const char *path, *bufname; |
char *pdata, *new_pdata, *cause, *file; |
char *pdata, *new_pdata, *cause, *file; |
char resolved[PATH_MAX]; |
|
size_t psize; |
size_t psize; |
int ch, error; |
int ch, error; |
|
|
|
|
return (CMD_RETURN_WAIT); |
return (CMD_RETURN_WAIT); |
} |
} |
|
|
if (c != NULL && c->session == NULL && c->cwd != NULL) |
file = server_client_get_path(c, path); |
cwd = c->cwd; |
f = fopen(file, "rb"); |
else if (c != NULL && (s = c->session) != NULL && s->cwd != NULL) |
|
cwd = s->cwd; |
|
else |
|
cwd = "."; |
|
|
|
if (*path == '/') |
|
file = xstrdup(path); |
|
else |
|
xasprintf(&file, "%s/%s", cwd, path); |
|
if (realpath(file, resolved) == NULL && |
|
strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { |
|
cmdq_error(item, "%s: %s", file, strerror(ENAMETOOLONG)); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
f = fopen(resolved, "rb"); |
|
free(file); |
|
if (f == NULL) { |
if (f == NULL) { |
cmdq_error(item, "%s: %s", resolved, strerror(errno)); |
cmdq_error(item, "%s: %s", file, strerror(errno)); |
|
free(file); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
|
|
pdata[psize++] = ch; |
pdata[psize++] = ch; |
} |
} |
if (ferror(f)) { |
if (ferror(f)) { |
cmdq_error(item, "%s: read error", resolved); |
cmdq_error(item, "%s: read error", file); |
goto error; |
goto error; |
} |
} |
if (pdata != NULL) |
if (pdata != NULL) |
pdata[psize] = '\0'; |
pdata[psize] = '\0'; |
|
|
fclose(f); |
fclose(f); |
|
free(file); |
|
|
if (paste_set(pdata, psize, bufname, &cause) != 0) { |
if (paste_set(pdata, psize, bufname, &cause) != 0) { |
cmdq_error(item, "%s", cause); |
cmdq_error(item, "%s", cause); |