From 27546354ca029997500f81bb64d2df1b9cd226c6 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sun, 11 Aug 2019 20:41:57 +0200 Subject: [PATCH] increase disconnect buffer and get rid of some magic 510 values --- src/core/net-disconnect.c | 4 ++-- src/irc/core/irc-channels.c | 2 +- src/irc/core/irc-servers.c | 10 ++-------- src/irc/core/irc-servers.h | 9 +++++++++ src/irc/notifylist/notify-ison.c | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/core/net-disconnect.c b/src/core/net-disconnect.c index 889563c5..27540767 100644 --- a/src/core/net-disconnect.c +++ b/src/core/net-disconnect.c @@ -51,7 +51,7 @@ static void sig_disconnect(NET_DISCONNECT_REC *rec) char buf[512]; int count, ret; - /* check if there's any data waiting in socket. read max. 5kB so + /* check if there's any data waiting in socket. read max. 9kB so if server just keeps sending us stuff we won't get stuck */ count = 0; do { @@ -61,7 +61,7 @@ static void sig_disconnect(NET_DISCONNECT_REC *rec) net_disconnect_remove(rec); } count++; - } while (ret == sizeof(buf) && count < 10); + } while (ret == sizeof(buf) && count < 18); } static int sig_timeout_disconnect(void) diff --git a/src/irc/core/irc-channels.c b/src/irc/core/irc-channels.c index b2ee3772..27f8f4b2 100644 --- a/src/irc/core/irc-channels.c +++ b/src/irc/core/irc-channels.c @@ -142,7 +142,7 @@ static void irc_channels_join(IRC_SERVER_REC *server, const char *data, /* don't try to send too long lines make sure it's not longer than 510 so 510 - strlen("JOIN ") = 505 */ - if (cmdlen < 505) + if (cmdlen < MAX_IRC_MESSAGE_LEN - 5 /* strlen("JOIN ") */) continue; } if (outchans->len > 0) { diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 118f7242..5698b9a0 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -55,12 +55,6 @@ #define DEFAULT_CMDS_MAX_AT_ONCE 5 #define DEFAULT_MAX_QUERY_CHANS 1 /* more and more IRC networks are using stupid ircds.. */ -/* - * 63 is the maximum hostname length defined by the protocol. 10 is a common - * username limit on many networks. 1 is for the `@'. - */ -#define MAX_USERHOST_LEN (63 + 10 + 1) - void irc_servers_reconnect_init(void); void irc_servers_reconnect_deinit(void); @@ -208,7 +202,7 @@ static char **split_message(SERVER_REC *server, const char *target, /* length calculation shamelessly stolen from splitlong_safe.pl */ return split_line(SERVER(server), msg, target, - 510 - strlen(":! PRIVMSG :") - + MAX_IRC_MESSAGE_LEN - strlen(":! PRIVMSG :") - strlen(ircserver->nick) - MAX_USERHOST_LEN - strlen(target)); } @@ -498,7 +492,7 @@ char **irc_server_split_action(IRC_SERVER_REC *server, const char *target, g_return_val_if_fail(data != NULL, NULL); return split_line(SERVER(server), data, target, - 510 - strlen(":! PRIVMSG :\001ACTION \001") - + MAX_IRC_MESSAGE_LEN - strlen(":! PRIVMSG :\001ACTION \001") - strlen(server->nick) - MAX_USERHOST_LEN - strlen(target)); } diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h index df0446cb..f1697c60 100644 --- a/src/irc/core/irc-servers.h +++ b/src/irc/core/irc-servers.h @@ -5,6 +5,15 @@ #include #include +/* + * 63 is the maximum hostname length defined by the protocol. 10 is a common + * username limit on many networks. 1 is for the `@'. + */ +#define MAX_USERHOST_LEN (63 + 10 + 1) +#define MAX_IRC_MESSAGE_LEN (512 - 2) /* (2 bytes for CR+LF) */ +#define MAX_IRC_TAGS_LEN (8191 - 2) /* (2 bytes for `@' and SPACE) */ +#define MAX_IRC_USER_TAGS_LEN 4094 + #define CAP_LS_VERSION "302" #define CAP_SASL "sasl" #define CAP_MULTI_PREFIX "multi-prefix" diff --git a/src/irc/notifylist/notify-ison.c b/src/irc/notifylist/notify-ison.c index 39292896..4fb9315a 100644 --- a/src/irc/notifylist/notify-ison.c +++ b/src/irc/notifylist/notify-ison.c @@ -131,7 +131,7 @@ static void notifylist_timeout_server(IRC_SERVER_REC *server) len = strlen(nick); - if (cmd->len+len+1 > 510) + if (cmd->len+len+1 > MAX_IRC_MESSAGE_LEN) ison_send(server, cmd); g_string_append_printf(cmd, "%s ", nick);