From 83f0720a39c911b1234aa0c1dac7ad1654b46f9c Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 16 Jul 2014 15:55:04 -0400 Subject: [PATCH] another UB fix --- src/groupchat.c | 2 +- src/misc_tools.c | 2 +- src/toxic_strings.c | 15 +++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/groupchat.c b/src/groupchat.c index 519de2f..09c5e52 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -177,7 +177,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick); selfnick[n_len] = '\0'; - bool nick_match = strcasestr(action, selfnick); + const char *nick_match = strcasestr(action, selfnick); if (nick_match) { alert_type = WINDOW_ALERT_0; diff --git a/src/misc_tools.c b/src/misc_tools.c index 48aff30..b1000a3 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -247,4 +247,4 @@ int char_find(int idx, const char *s, char ch) } return i; -} \ No newline at end of file +} diff --git a/src/toxic_strings.c b/src/toxic_strings.c index 93812f3..1f872c4 100644 --- a/src/toxic_strings.c +++ b/src/toxic_strings.c @@ -234,18 +234,23 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size) char tmp[MAX_STR_SIZE]; snprintf(tmp, sizeof(tmp), "%s", ubuf); tmp[ctx->pos] = '\0'; - char *sub = strrchr(tmp, ' '); + const char *s = strrchr(tmp, ' '); + char *sub = malloc(strlen(ubuf) + 1); int n_endchrs = 1; /* 1 = append space to end of match, 2 = append ": " */ - if (!sub++) { - sub = tmp; + if (!s) { + strcpy(sub, tmp); if (sub[0] != '/') /* make sure it's not a command */ n_endchrs = 2; + } else { + strcpy(sub, &s[1]); } - if (string_is_empty(sub)) + if (string_is_empty(sub)) { + free(sub); return -1; + } int s_len = strlen(sub); const char *match; @@ -260,6 +265,8 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size) break; } + free(sub); + if (!is_match) return -1;