Skip to content

Commit d00f7d7

Browse files
committed
don't permit too long usernames
fixes #7
1 parent ed6ac2f commit d00f7d7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

xmpp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,15 @@ void xmpp_connect()
541541
connection_state = OFFLINE;
542542
return;
543543
}
544-
char *jid = malloc(3071); // see rfc3920bis
545-
strcpy(jid, g_hash_table_lookup(config, "username"));
544+
545+
// see rfc3920
546+
#define MAX_JID_COMPONENT_LEN 1023
547+
#define MAX_JID_LEN (MAX_JID_COMPONENT_LEN * 3 + 2)
548+
char jid[MAX_JID_LEN + 1];
549+
strncpy(jid, g_hash_table_lookup(config, "username"), MAX_JID_COMPONENT_LEN);
546550
strcat(jid, "@");
547551
strcat(jid, lm_connection_get_server(connection));
548552
lm_connection_set_jid(connection, jid); // loudmouth doesn't set it itself somewhy
549-
free(jid);
550553

551554
lm_connection_set_keep_alive_rate(connection, 240);
552555

0 commit comments

Comments
 (0)