From 6492bd12f9d7f3b669cb865dac8bcf082d3c3ec5 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 6 Oct 2014 16:23:43 -0400 Subject: [PATCH] escape newlines in contact names/status messages --- src/friendlist.c | 2 +- src/misc_tools.c | 13 ++++++++++++- src/misc_tools.h | 5 ++++- src/windows.c | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/friendlist.c b/src/friendlist.c index fb16543..0f0d047 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -553,7 +553,7 @@ static void delete_friend(Tox *m, int32_t f_num) /* activates delete friend popup */ static void del_friend_activate(ToxWindow *self, Tox *m, int32_t f_num) { - pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH - 1, 8, 8); + pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8); pendingdelete.active = true; pendingdelete.num = f_num; } diff --git a/src/misc_tools.c b/src/misc_tools.c index ab5ee49..1dae6ea 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -189,7 +189,7 @@ int qsort_strcasecmp_hlpr(const void *str1, const void *str2) - cannot start with a space - must not contain a forward slash (for logfile naming purposes) - must not contain contiguous spaces */ -int valid_nick(char *nick) +int valid_nick(const char *nick) { if (!nick[0] || nick[0] == ' ') return 0; @@ -207,6 +207,17 @@ int valid_nick(char *nick) return 1; } +/* Converts all newline chars to spaces (use for strings that should be contained to a single line) */ +void escape_newline_str(char *str, int len) +{ + int i; + + for (i = 0; i < len; ++i) { + if (str[i] == '\n' || str[i] == '\r') + str[i] = ' '; + } +} + /* gets base file name from path or original file name if no path is supplied */ void get_file_name(char *namebuf, int bufsize, const char *pathname) { diff --git a/src/misc_tools.h b/src/misc_tools.h index 38a6f79..77c0353 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -88,7 +88,10 @@ int qsort_strcasecmp_hlpr(const void *str1, const void *str2); - cannot start with a space - must not contain a forward slash (for logfile naming purposes) - must not contain contiguous spaces */ -int valid_nick(char *nick); +int valid_nick(const char *nick); + +/* Converts all newline chars to spaces (use for strings that should be contained to a single line) */ +void escape_newline_str(char *str, int len); /* gets base file name from path or original file name if no path is supplied */ void get_file_name(char *namebuf, int bufsize, const char *pathname); diff --git a/src/windows.c b/src/windows.c index e8f0b15..959b6b0 100644 --- a/src/windows.c +++ b/src/windows.c @@ -112,6 +112,7 @@ void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t { char nick[TOXIC_MAX_NAME_LENGTH + 1]; length = copy_tox_str(nick, sizeof(nick), (const char *) string, length); + escape_newline_str(nick, length); int i; @@ -127,6 +128,7 @@ void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, { char msg[TOX_MAX_STATUSMESSAGE_LENGTH + 1]; length = copy_tox_str(msg, sizeof(msg), (const char *) string, length); + escape_newline_str(msg, length); int i;