Ensure that crypt_msg always leaves space for the trailing CTCP delimiter.

git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@393 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
Kevin Easton
2013-10-14 14:10:26 +00:00
parent 86d47f06ce
commit 69109d9045

View File

@@ -214,21 +214,21 @@ static char *do_crypt(char *str, char *key, int flag)
*/ */
char *crypt_msg(char *str, char *key) char *crypt_msg(char *str, char *key)
{ {
char thing[6] = { CTCP_DELIM_CHAR, 0 }; static const char sed_prefix[] = { CTCP_DELIM_CHAR, 'S', 'E', 'D', ' ', 0 };
char buffer[CRYPT_BUFFER_SIZE]; char buffer[CRYPT_BUFFER_SIZE];
char *ptr; char *ptr;
strlcat(thing, "SED ", sizeof thing);
*buffer = 0;
if ((ptr = do_crypt(str, key, 1))) if ((ptr = do_crypt(str, key, 1)))
{ {
strlcat(buffer, thing, sizeof buffer); /* The - 1 terms here are to ensure that the trailing CTCP_DELIM_CHAR
strlcat(buffer, ptr, sizeof buffer); * always gets added. */
strlcpy(buffer, sed_prefix, sizeof buffer - 1);
strlcat(buffer, ptr, sizeof buffer - 1);
strlcat(buffer, CTCP_DELIM_STR, sizeof buffer); strlcat(buffer, CTCP_DELIM_STR, sizeof buffer);
new_free(&ptr); new_free(&ptr);
} }
else else
strlcat(buffer, str, sizeof buffer); strlcpy(buffer, str, sizeof buffer);
return (m_strdup(buffer)); return (m_strdup(buffer));
} }