summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/idle-parser.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/idle-parser.c b/src/idle-parser.c
index 159e6cc..71ca8b1 100644
--- a/src/idle-parser.c
+++ b/src/idle-parser.c
@@ -151,6 +151,7 @@ struct _IdleParserPrivate {
/* continuation line buffer */
gchar split_buf[IRC_MSG_MAXLEN + 3];
+ guint split_buf_used;
/* message handlers */
GSList *handlers[IDLE_PARSER_LAST_MESSAGE_CODE];
@@ -226,6 +227,13 @@ strnlen(const char *msg, size_t maxlen)
}
#endif
+static void clear_split_buf(IdleParser *parser) {
+ IdleParserPrivate *priv = IDLE_PARSER_GET_PRIVATE(parser);
+
+ memset(priv->split_buf, '\0', IRC_MSG_MAXLEN + 3);
+ priv->split_buf_used = 0;
+}
+
void idle_parser_receive(IdleParser *parser, const gchar *msg) {
IdleParserPrivate *priv = IDLE_PARSER_GET_PRIVATE(parser);
guint i;
@@ -245,7 +253,7 @@ void idle_parser_receive(IdleParser *parser, const gchar *msg) {
if ((lasti == 0) && (priv->split_buf[0] != '\0')) {
g_strlcpy(g_stpcpy(concat_buf, priv->split_buf), msg, i + 1);
tmp = concat_buf;
- memset(priv->split_buf, '\0', IRC_MSG_MAXLEN + 3);
+ clear_split_buf(parser);
} else {
tmp = g_strndup(msg + lasti, i - lasti);
}
@@ -264,10 +272,18 @@ void idle_parser_receive(IdleParser *parser, const gchar *msg) {
}
}
- if (!line_ends)
- g_strlcpy(priv->split_buf, msg + lasti, (IRC_MSG_MAXLEN + 3) - lasti);
- else
- memset(priv->split_buf, '\0', IRC_MSG_MAXLEN + 3);
+ if (!line_ends) {
+ len = strlen(msg + lasti);
+ if (len > (IRC_MSG_MAXLEN + 3) - priv->split_buf_used - 1) {
+ IDLE_DEBUG("Discarding content that exceeds maximum message length: \"%s\"", msg + lasti);
+ clear_split_buf(parser);
+ } else {
+ g_strlcpy(priv->split_buf + priv->split_buf_used, msg + lasti, (IRC_MSG_MAXLEN + 3) - priv->split_buf_used);
+ priv->split_buf_used += len;
+ }
+ } else {
+ clear_split_buf(parser);
+ }
}
void idle_parser_add_handler(IdleParser *parser, IdleParserMessageCode code, IdleParserMessageHandler handler, gpointer user_data) {