mirror of
https://github.com/tmux/tmux.git
synced 2024-12-26 03:19:16 +00:00
Add a nesting limit to source-file, from Fadi Afani in GitHub issue
4223.
This commit is contained in:
parent
bec6ce54c1
commit
6b32d195e8
@ -30,6 +30,9 @@
|
|||||||
* Sources a configuration file.
|
* Sources a configuration file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define CMD_SOURCE_FILE_DEPTH_LIMIT 50
|
||||||
|
static u_int cmd_source_file_depth;
|
||||||
|
|
||||||
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
|
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_source_file_entry = {
|
const struct cmd_entry cmd_source_file_entry = {
|
||||||
@ -60,6 +63,16 @@ struct cmd_source_file_data {
|
|||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
cmd_source_file_complete_cb(struct cmdq_item *item, __unused void *data)
|
cmd_source_file_complete_cb(struct cmdq_item *item, __unused void *data)
|
||||||
{
|
{
|
||||||
|
struct client *c = cmdq_get_client(item);
|
||||||
|
|
||||||
|
if (c == NULL) {
|
||||||
|
cmd_source_file_depth--;
|
||||||
|
log_debug("%s: depth now %u", __func__, cmd_source_file_depth);
|
||||||
|
} else {
|
||||||
|
c->source_file_depth--;
|
||||||
|
log_debug("%s: depth now %u", __func__, c->source_file_depth);
|
||||||
|
}
|
||||||
|
|
||||||
cfg_print_causes(item);
|
cfg_print_causes(item);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
@ -131,6 +144,7 @@ cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
|
|||||||
path = resolved;
|
path = resolved;
|
||||||
|
|
||||||
log_debug("%s: %s", __func__, path);
|
log_debug("%s: %s", __func__, path);
|
||||||
|
|
||||||
cdata->files = xreallocarray(cdata->files, cdata->nfiles + 1,
|
cdata->files = xreallocarray(cdata->files, cdata->nfiles + 1,
|
||||||
sizeof *cdata->files);
|
sizeof *cdata->files);
|
||||||
cdata->files[cdata->nfiles++] = xstrdup(path);
|
cdata->files[cdata->nfiles++] = xstrdup(path);
|
||||||
@ -149,6 +163,22 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
int result;
|
int result;
|
||||||
u_int i, j;
|
u_int i, j;
|
||||||
|
|
||||||
|
if (c == NULL) {
|
||||||
|
if (cmd_source_file_depth >= CMD_SOURCE_FILE_DEPTH_LIMIT) {
|
||||||
|
cmdq_error(item, "too many nested files");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
cmd_source_file_depth++;
|
||||||
|
log_debug("%s: depth now %u", __func__, cmd_source_file_depth);
|
||||||
|
} else {
|
||||||
|
if (c->source_file_depth >= CMD_SOURCE_FILE_DEPTH_LIMIT) {
|
||||||
|
cmdq_error(item, "too many nested files");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
c->source_file_depth++;
|
||||||
|
log_debug("%s: depth now %u", __func__, c->source_file_depth);
|
||||||
|
}
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
cdata->item = item;
|
cdata->item = item;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user