summaryrefslogtreecommitdiffstats
path: root/cmd-list.c
diff options
context:
space:
mode:
authornicm <nicm>2014-04-11 19:35:54 +0000
committernicm <nicm>2014-04-11 19:35:54 +0000
commitb8bda67f304b7c70dee891b7ca660036793c2a4b (patch)
treedded327c5a855dddbbdddf68220868207dca3b10 /cmd-list.c
parent73c5a487c1b0f10bbc36479f425fb9cea512be7b (diff)
Don't blindly increase offsets by the return value of snprintf, if there
wasn't enough space this will go off the end. Instead clamp to the available space. Fixes crash reported by Julien Rebetez.
Diffstat (limited to 'cmd-list.c')
-rw-r--r--cmd-list.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/cmd-list.c b/cmd-list.c
index 82ae7480..6dc4493a 100644
--- a/cmd-list.c
+++ b/cmd-list.c
@@ -103,7 +103,7 @@ size_t
cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
{
struct cmd *cmd;
- size_t off;
+ size_t off, used;
off = 0;
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
@@ -112,8 +112,12 @@ cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
off += cmd_print(cmd, buf + off, len - off);
if (off >= len)
break;
- if (TAILQ_NEXT(cmd, qentry) != NULL)
- off += xsnprintf(buf + off, len - off, " ; ");
+ if (TAILQ_NEXT(cmd, qentry) != NULL) {
+ used = xsnprintf(buf + off, len - off, " ; ");
+ if (used > len - off)
+ used = len - off;
+ off += used;
+ }
}
return (off);
}