aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--calmwm.h4
-rw-r--r--conf.c38
-rw-r--r--parse.y9
3 files changed, 33 insertions, 18 deletions
diff --git a/calmwm.h b/calmwm.h
index 729c048..930fc12 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: calmwm.h,v 1.248 2014/01/28 20:22:21 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.249 2014/01/29 18:34:22 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -522,7 +522,7 @@ int conf_bind_mouse(struct conf *, const char *,
const char *);
void conf_clear(struct conf *);
void conf_client(struct client_ctx *);
-void conf_cmd_add(struct conf *, const char *,
+int conf_cmd_add(struct conf *, const char *,
const char *);
void conf_cursor(struct conf *);
void conf_grab_kbd(Window);
diff --git a/conf.c b/conf.c
index a2ac6b8..396ef1d 100644
--- a/conf.c
+++ b/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.163 2014/01/28 20:22:21 okan Exp $
+ * $OpenBSD: conf.c,v 1.164 2014/01/29 18:34:22 okan Exp $
*/
#include <sys/param.h>
@@ -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_mouse(struct conf *, struct mousebinding *);
-/* Add an command menu entry to the end of the menu */
-void
+int
conf_cmd_add(struct conf *c, const char *name, const char *path)
{
+ struct cmd *cmd;
+
/* "term" and "lock" have special meanings. */
- if (strcmp(name, "term") == 0)
- (void)strlcpy(c->termpath, path, sizeof(c->termpath));
- else if (strcmp(name, "lock") == 0)
- (void)strlcpy(c->lockpath, path, sizeof(c->lockpath));
- else {
- struct cmd *cmd = xmalloc(sizeof(*cmd));
- (void)strlcpy(cmd->name, name, sizeof(cmd->name));
- (void)strlcpy(cmd->path, path, sizeof(cmd->path));
+ if (strcmp(name, "term") == 0) {
+ if (strlcpy(c->termpath, path, sizeof(c->termpath)) >=
+ sizeof(c->termpath))
+ return (0);
+ } else if (strcmp(name, "lock") == 0) {
+ if (strlcpy(c->lockpath, path, sizeof(c->lockpath)) >=
+ sizeof(c->lockpath))
+ 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);
}
+ return (1);
}
void
@@ -249,9 +260,8 @@ conf_init(struct conf *c)
for (i = 0; i < nitems(color_binds); i++)
c->color[i] = xstrdup(color_binds[i]);
- /* Default term/lock */
- (void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
- (void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
+ conf_cmd_add(c, "lock", "xlock");
+ conf_cmd_add(c, "term", "xterm");
(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
homedir, ".ssh/known_hosts");
diff --git a/parse.y b/parse.y
index f218a13..f42fd56 100644
--- a/parse.y
+++ b/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.55 2014/01/28 20:22:21 okan Exp $ */
+/* $OpenBSD: parse.y,v 1.56 2014/01/29 18:34:22 okan Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -137,7 +137,12 @@ main : FONTNAME STRING {
conf->snapdist = $2;
}
| 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($3);
}