talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 7efc008db2cb63dc7d4ac0f0c7f9046742ceae49
parent f4f722b814ad7ff6f3fa6cb5e83b330275784d97
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Mon,  7 Jan 2019 17:38:01 +0100

Fix a few small memory leaks in scan_mailto_url()

Diffstat:
Msrc/common/utils.c | 20++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/common/utils.c b/src/common/utils.c @@ -1411,7 +1411,8 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, "../", NULL }; gint num_attach = 0; - gchar **my_att = NULL; + + cm_return_val_if_fail(mailto != NULL, -1); Xstrdup_a(tmp_mailto, mailto, return -1); @@ -1427,9 +1428,6 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, if (to && !*to) *to = decode_uri_gdup(tmp_mailto); - my_att = g_malloc(sizeof(char *)); - my_att[0] = NULL; - while (p) { gchar *field, *value; @@ -1456,6 +1454,7 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, } else { gchar *tmp = decode_uri_gdup(value); gchar *new_from = g_strdup_printf("%s, %s", *from, tmp); + g_free(tmp); g_free(*from); *from = new_from; } @@ -1465,6 +1464,7 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, } else { gchar *tmp = decode_uri_gdup(value); gchar *new_cc = g_strdup_printf("%s, %s", *cc, tmp); + g_free(tmp); g_free(*cc); *cc = new_cc; } @@ -1474,6 +1474,7 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, } else { gchar *tmp = decode_uri_gdup(value); gchar *new_bcc = g_strdup_printf("%s, %s", *bcc, tmp); + g_free(tmp); g_free(*bcc); *bcc = new_bcc; } @@ -1491,11 +1492,16 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, } else if (attach && !g_ascii_strcasecmp(field, "attach")) { int i = 0; gchar *tmp = decode_uri_gdup(value); + gchar **my_att = g_malloc(sizeof(char *)); + + my_att[0] = NULL; + for (; forbidden_uris[i]; i++) { if (strstr(tmp, forbidden_uris[i])) { g_print("Refusing to attach '%s', potential private data leak\n", tmp); g_free(tmp); + g_free(my_att); break; } } @@ -1505,6 +1511,10 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, my_att = g_realloc(my_att, (sizeof(char *))*(num_attach+1)); my_att[num_attach-1] = tmp; my_att[num_attach] = NULL; + *attach = my_att; + g_free(tmp); + } else { + g_free(my_att); } } else if (inreplyto && !*inreplyto && !g_ascii_strcasecmp(field, "in-reply-to")) { @@ -1512,8 +1522,6 @@ gint scan_mailto_url(const gchar *mailto, gchar **from, gchar **to, gchar **cc, } } - if (attach) - *attach = my_att; return 0; }