summary refs log tree commit diff
path: root/conf.c
diff options
context:
space:
mode:
authorokan <okan>2014-01-29 18:34:22 +0000
committerokan <okan>2014-01-29 18:34:22 +0000
commit1f8f19b4d50f59624e84a3c932b639670e0d8b27 (patch)
treec907b036ffb1255b4e60f3eefe6b50821c08fdf7 /conf.c
parentc28467cda5323f2251ed16a407fd77b7ec9e5ba6 (diff)
downloadcwm-1f8f19b4d50f59624e84a3c932b639670e0d8b27.tar.gz
cwm-1f8f19b4d50f59624e84a3c932b639670e0d8b27.tar.xz
cwm-1f8f19b4d50f59624e84a3c932b639670e0d8b27.zip
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.
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/conf.c b/conf.c
index 9ecf1b4..8f067d0 100644
--- a/conf.c
+++ b/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_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");