From 92ae54d415472aa28debb9579a3051995ef90a58 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 5 Oct 2021 23:35:58 +0100 Subject: [PATCH] Address various review comments. --- src/common/inbound.c | 6 +++++- src/common/sts.c | 10 ++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common/inbound.c b/src/common/inbound.c index fb90880d..e0c3b4fd 100644 --- a/src/common/inbound.c +++ b/src/common/inbound.c @@ -1829,6 +1829,8 @@ inbound_cap_ls (server *serv, char *nick, char *extensions_str, stsvalue = atoi (stsvaluestr); if (stsvalue > 0) sts_update_expiry(serv->hostname, stsvalue, serv->stsprofile); + else + g_debug ("Malformed STS profile duration: %s", stsvaluestr); } } else { @@ -1840,7 +1842,7 @@ inbound_cap_ls (server *serv, char *nick, char *extensions_str, { /* We are connecting on plain text and have found a valid STS profile. */ serv->stsprofile = sts_new (); - strcpy (serv->stsprofile->host, serv->hostname); + g_strlcpy (serv->stsprofile->host, serv->hostname, sizeof (serv->stsprofile->host)); serv->stsprofile->port = stsvalue; /* Reconfigure with the new port and security settings. */ @@ -1859,6 +1861,8 @@ inbound_cap_ls (server *serv, char *nick, char *extensions_str, prefs.hex_net_reconnect_delay = stsvalue; break; } + else + g_debug ("Malformed STS profile port: %s", stsvaluestr); } } diff --git a/src/common/sts.c b/src/common/sts.c index 73ef3dfb..0d1c9bdb 100644 --- a/src/common/sts.c +++ b/src/common/sts.c @@ -67,6 +67,7 @@ sts_load (void) if (sscanf (buf, "%s %u %ld", profile->host, &profile->port, &profile->expiry) != 3) { /* Malformed profile; drop it. */ + g_debug ("Malformed STS profile: %s", buf); g_free (profile); continue; } @@ -80,10 +81,7 @@ sts_new (void) { struct sts_profile *profile; - profile = malloc (sizeof (struct sts_profile)); - profile->host[0] = 0; - profile->port = 0; - profile->expiry = 0; + profile = g_new0 (struct sts_profile, 1); return profile; } @@ -94,7 +92,7 @@ sts_parse_cap (const char* cap) char *value; GHashTable *table; - table = g_hash_table_new (g_str_hash, g_str_equal); + table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); entries = g_strsplit (cap, ",", 0); for (currentry = entries; *currentry; ++currentry) { @@ -103,7 +101,7 @@ sts_parse_cap (const char* cap) g_hash_table_insert (table, g_strndup (*currentry, value - *currentry), g_strdup (value + 1)); } - g_free (entries); + g_strfreev (entries); return table; }