mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Check command name/path for truncation and provide user feedback during
config parse (and use conf_cmd_add to populate defaults); based on a discussion with Tiago Cunha. While this looks ugly, there are likely some other changes here to come.
This commit is contained in:
parent
c28467cda5
commit
1f8f19b4d5
2
calmwm.h
2
calmwm.h
@ -522,7 +522,7 @@ int conf_bind_mouse(struct conf *, const char *,
|
|||||||
const char *);
|
const char *);
|
||||||
void conf_clear(struct conf *);
|
void conf_clear(struct conf *);
|
||||||
void conf_client(struct client_ctx *);
|
void conf_client(struct client_ctx *);
|
||||||
void conf_cmd_add(struct conf *, const char *,
|
int conf_cmd_add(struct conf *, const char *,
|
||||||
const char *);
|
const char *);
|
||||||
void conf_cursor(struct conf *);
|
void conf_cursor(struct conf *);
|
||||||
void conf_grab_kbd(Window);
|
void conf_grab_kbd(Window);
|
||||||
|
36
conf.c
36
conf.c
@ -35,21 +35,32 @@ static const char *conf_bind_getmask(const char *, unsigned int *);
|
|||||||
static void conf_unbind_kbd(struct conf *, struct keybinding *);
|
static void conf_unbind_kbd(struct conf *, struct keybinding *);
|
||||||
static void conf_unbind_mouse(struct conf *, struct mousebinding *);
|
static void conf_unbind_mouse(struct conf *, struct mousebinding *);
|
||||||
|
|
||||||
/* Add an command menu entry to the end of the menu */
|
int
|
||||||
void
|
|
||||||
conf_cmd_add(struct conf *c, const char *name, const char *path)
|
conf_cmd_add(struct conf *c, const char *name, const char *path)
|
||||||
{
|
{
|
||||||
|
struct cmd *cmd;
|
||||||
|
|
||||||
/* "term" and "lock" have special meanings. */
|
/* "term" and "lock" have special meanings. */
|
||||||
if (strcmp(name, "term") == 0)
|
if (strcmp(name, "term") == 0) {
|
||||||
(void)strlcpy(c->termpath, path, sizeof(c->termpath));
|
if (strlcpy(c->termpath, path, sizeof(c->termpath)) >=
|
||||||
else if (strcmp(name, "lock") == 0)
|
sizeof(c->termpath))
|
||||||
(void)strlcpy(c->lockpath, path, sizeof(c->lockpath));
|
return (0);
|
||||||
else {
|
} else if (strcmp(name, "lock") == 0) {
|
||||||
struct cmd *cmd = xmalloc(sizeof(*cmd));
|
if (strlcpy(c->lockpath, path, sizeof(c->lockpath)) >=
|
||||||
(void)strlcpy(cmd->name, name, sizeof(cmd->name));
|
sizeof(c->lockpath))
|
||||||
(void)strlcpy(cmd->path, path, sizeof(cmd->path));
|
return (0);
|
||||||
|
} else {
|
||||||
|
cmd = xmalloc(sizeof(*cmd));
|
||||||
|
|
||||||
|
if (strlcpy(cmd->name, name, sizeof(cmd->name)) >=
|
||||||
|
sizeof(cmd->name))
|
||||||
|
return (0);
|
||||||
|
if (strlcpy(cmd->path, path, sizeof(cmd->path)) >=
|
||||||
|
sizeof(cmd->path))
|
||||||
|
return (0);
|
||||||
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
|
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
|
||||||
}
|
}
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -249,9 +260,8 @@ conf_init(struct conf *c)
|
|||||||
for (i = 0; i < nitems(color_binds); i++)
|
for (i = 0; i < nitems(color_binds); i++)
|
||||||
c->color[i] = xstrdup(color_binds[i]);
|
c->color[i] = xstrdup(color_binds[i]);
|
||||||
|
|
||||||
/* Default term/lock */
|
conf_cmd_add(c, "lock", "xlock");
|
||||||
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
conf_cmd_add(c, "term", "xterm");
|
||||||
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
|
||||||
|
|
||||||
(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
|
(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
|
||||||
homedir, ".ssh/known_hosts");
|
homedir, ".ssh/known_hosts");
|
||||||
|
7
parse.y
7
parse.y
@ -137,7 +137,12 @@ main : FONTNAME STRING {
|
|||||||
conf->snapdist = $2;
|
conf->snapdist = $2;
|
||||||
}
|
}
|
||||||
| COMMAND STRING string {
|
| COMMAND STRING string {
|
||||||
conf_cmd_add(conf, $2, $3);
|
if (!conf_cmd_add(conf, $2, $3)) {
|
||||||
|
yyerror("command name/path too long");
|
||||||
|
free($2);
|
||||||
|
free($3);
|
||||||
|
YYERROR;
|
||||||
|
}
|
||||||
free($2);
|
free($2);
|
||||||
free($3);
|
free($3);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user