Change sed_encrypt_msg() so it doesn't modify the passed message in-place
This means the calling code in commands.c no longer needs to take a copy before calling the function. Also remove code testing result of of ctcp_quote_it() and ctcp_unquote_it() - these functions never fail.
This commit is contained in:
@@ -71,7 +71,7 @@ extern char * do_notice_ctcp (char *, char *, char *);
|
||||
extern int in_ctcp (void);
|
||||
extern void send_ctcp (int, char *, int, char *, ...);
|
||||
extern int get_ctcp_val (char *);
|
||||
extern char *sed_encrypt_msg(char *, const char *);
|
||||
extern char *sed_encrypt_msg(const char *, const char *);
|
||||
extern char *sed_decrypt_msg(const char *, const char *);
|
||||
|
||||
void BX_split_CTCP (char *, char *, char *);
|
||||
|
||||
@@ -3758,7 +3758,7 @@ static int recursion = 0;
|
||||
struct target_type
|
||||
{
|
||||
char *nick_list;
|
||||
char *message;
|
||||
const char *message;
|
||||
int hook_type;
|
||||
char *command;
|
||||
char *format;
|
||||
@@ -3874,11 +3874,7 @@ struct target_type target[4] =
|
||||
continue;
|
||||
}
|
||||
if ((key = is_crypted(current_nick)))
|
||||
{
|
||||
char *breakage;
|
||||
breakage = LOCAL_COPY(text);
|
||||
line = sed_encrypt_msg(breakage, key);
|
||||
}
|
||||
line = sed_encrypt_msg(text, key);
|
||||
else
|
||||
line = m_strdup(text);
|
||||
|
||||
@@ -3895,21 +3891,18 @@ struct target_type target[4] =
|
||||
else
|
||||
dcc_raw_transmit(current_nick + 1, line, command);
|
||||
|
||||
add_last_type(&last_sent_dcc[0], MAX_LAST_MSG, NULL, NULL, current_nick+1, (char *)text);
|
||||
add_last_type(&last_sent_dcc[0], MAX_LAST_MSG, NULL, NULL, current_nick+1, text);
|
||||
from_server = old_server;
|
||||
new_free(&line);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *copy = NULL;
|
||||
if (doing_notice)
|
||||
{
|
||||
say("You cannot send a message from within ON NOTICE");
|
||||
continue;
|
||||
}
|
||||
|
||||
copy = LOCAL_COPY(text);
|
||||
|
||||
if (!(i = is_channel(current_nick)) && hook)
|
||||
addtabkey(current_nick, "msg", 0);
|
||||
|
||||
@@ -3920,8 +3913,8 @@ struct target_type target[4] =
|
||||
{
|
||||
set_display_target(current_nick, target[i].level);
|
||||
|
||||
line = sed_encrypt_msg(copy, key);
|
||||
if (hook && do_hook(target[i].hook_type, "%s %s", current_nick, copy))
|
||||
line = sed_encrypt_msg(text, key);
|
||||
if (hook && do_hook(target[i].hook_type, "%s %s", current_nick, text))
|
||||
put_it("%s", convert_output_format(target[i].format_encrypted,
|
||||
"%s %s %s %s", update_clock(GET_TIME), current_nick, get_server_nickname(from_server), text));
|
||||
|
||||
@@ -3935,7 +3928,7 @@ struct target_type target[4] =
|
||||
malloc_strcat(&target[i].nick_list, ",");
|
||||
malloc_strcat(&target[i].nick_list, current_nick);
|
||||
if (!target[i].message)
|
||||
target[i].message = (char *)text;
|
||||
target[i].message = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,29 +612,26 @@ int server;
|
||||
* Encrypts a message with my_encrypt() under the given key, and encapsulates it
|
||||
* as a CTCP SED message ready to transmit.
|
||||
*/
|
||||
char *sed_encrypt_msg(char *str, const char *key)
|
||||
char *sed_encrypt_msg(const char *str, const char *key)
|
||||
{
|
||||
static const char sed_prefix[] = { CTCP_DELIM_CHAR, 'S', 'E', 'D', ' ', 0 };
|
||||
const size_t len = strlen(str);
|
||||
char buffer[CRYPT_BUFFER_SIZE];
|
||||
char *str_encrypted = m_strdup(str);
|
||||
char *buffer = new_malloc(CRYPT_BUFFER_SIZE);
|
||||
char *ptr;
|
||||
|
||||
my_encrypt(str, len, key);
|
||||
ptr = ctcp_quote_it(str, len);
|
||||
my_encrypt(str_encrypted, len, key);
|
||||
ptr = ctcp_quote_it(str_encrypted, len);
|
||||
new_free(&str_encrypted);
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
/* The - 1 terms here are to ensure that the trailing CTCP_DELIM_CHAR
|
||||
* always gets added. */
|
||||
strlcpy(buffer, sed_prefix, sizeof buffer - 1);
|
||||
strlcat(buffer, ptr, sizeof buffer - 1);
|
||||
strlcat(buffer, CTCP_DELIM_STR, sizeof buffer);
|
||||
new_free(&ptr);
|
||||
}
|
||||
else
|
||||
strlcpy(buffer, str, sizeof buffer);
|
||||
/* The - 1 terms here are to ensure that the trailing CTCP_DELIM_CHAR
|
||||
* always gets added. */
|
||||
strlcpy(buffer, sed_prefix, CRYPT_BUFFER_SIZE - 1);
|
||||
strlcat(buffer, ptr, CRYPT_BUFFER_SIZE - 1);
|
||||
strlcat(buffer, CTCP_DELIM_STR, CRYPT_BUFFER_SIZE);
|
||||
new_free(&ptr);
|
||||
|
||||
return (m_strdup(buffer));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -658,13 +655,8 @@ char *sed_decrypt_msg(const char *str, const char *key)
|
||||
ptr = ctcp_unquote_it(str, &len);
|
||||
my_decrypt(ptr, len, key);
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
strlcpy(buffer, ptr, CRYPT_BUFFER_SIZE);
|
||||
new_free(&ptr);
|
||||
}
|
||||
else
|
||||
strlcat(buffer, str, CRYPT_BUFFER_SIZE);
|
||||
strlcpy(buffer, ptr, CRYPT_BUFFER_SIZE);
|
||||
new_free(&ptr);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user