hirc

IRC client
Log | Files | Refs

commit 84866a79785970ae519164e0aac30fb5d9cef83c
parent b92c3877eed12e45722d46f566f98e178ca95d10
Author: hhvn <dev@hhvn.uk>
Date:   Wed,  8 Dec 2021 15:52:15 +0000

commands.c: strdup command before modifying

Diffstat:
Mcommands.c | 30+++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/commands.c b/commands.c @@ -672,15 +672,17 @@ command_eval(char *str) { char *cmd; char *s; - if (*str != '/' || strncmp(str, "/ /", sizeof("/ /")) == 0) { + s = strdup(str); + + if (*s != '/' || strncmp(s, "/ /", sizeof("/ /")) == 0) { /* Provide a way to escape commands * "/ /cmd" --> "/cmd" */ - if (strncmp(str, "/ /", sizeof("/ /")) == 0) - str += 3; + if (strncmp(s, "/ /", sizeof("/ /")) == 0) + s += 3; if (selected.channel && selected.server) { // TODO: message splitting - snprintf(msg, sizeof(msg), "PRIVMSG %s :%s", selected.channel->name, str); + snprintf(msg, sizeof(msg), "PRIVMSG %s :%s", selected.channel->name, s); ircprintf(selected.server, "%s\r\n", msg); hist_format(selected.channel->history, Activity_self, HIST_SHOW|HIST_LOG|HIST_SELF, msg); } else @@ -688,23 +690,25 @@ command_eval(char *str) { return; } else { - str++; - cmd = str; - str = strchr(str, ' '); - if (str && *str) { - *str = '\0'; - str++; - if (*str == '\0') - str = NULL; + s++; + cmd = s; + s = strchr(s, ' '); + if (s && *s) { + *s = '\0'; + s++; + if (*s == '\0') + s = NULL; } for (cmdp = commands; cmdp->name && cmdp->func; cmdp++) { if (strcmp(cmdp->name, cmd) == 0) { - cmdp->func(selected.server, str); + cmdp->func(selected.server, s); return; } } ui_error("no such command: '%s'", cmd); } + + free(s); }