Skip to content

Commit

Permalink
Merge branch 'obsd-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAdam committed Dec 16, 2024
2 parents 6b470c5 + 6b32d19 commit 190ddda
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd-source-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* 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 *);

const struct cmd_entry cmd_source_file_entry = {
Expand Down Expand Up @@ -59,6 +62,16 @@ struct cmd_source_file_data {
static enum cmd_retval
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);
return (CMD_RETURN_NORMAL);
}
Expand Down Expand Up @@ -130,6 +143,7 @@ cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
path = resolved;

log_debug("%s: %s", __func__, path);

cdata->files = xreallocarray(cdata->files, cdata->nfiles + 1,
sizeof *cdata->files);
cdata->files[cdata->nfiles++] = xstrdup(path);
Expand All @@ -148,6 +162,22 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
int result;
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->item = item;

Expand Down
1 change: 1 addition & 0 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,7 @@ struct client {
struct event overlay_timer;

struct client_files files;
u_int source_file_depth;

u_int *clipboard_panes;
u_int clipboard_npanes;
Expand Down

0 comments on commit 190ddda

Please sign in to comment.