talons

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

commit ac7ee135c7babde03957ed7da0ee24705173df3d
parent ce233134436cf307b442b4815a1c10f68b05fb91
Author: wwp <subscript@free.fr>
Date:   Sat, 11 Sep 2021 22:22:58 +0200

Fix CID 1491207, 1491213 and 1491253: ensure string in buffer is 0-ended,
and two resource (possible) leaks.

Diffstat:
Msrc/action.c | 23+++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/action.c b/src/action.c @@ -1042,11 +1042,13 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str, int r; ret_str = g_locale_from_utf8(msg_str, strlen(msg_str), &by_read, &by_written, NULL); - if (ret_str && by_written) { + if (ret_str && by_written) r = write(chld_in, ret_str, strlen(ret_str)); - g_free(ret_str); - } else + else r = write(chld_in, msg_str, strlen(msg_str)); + if (ret_str) + g_free(ret_str); + if (!(children->action_type & (ACTION_USER_IN | ACTION_USER_HIDDEN_IN))) r = close(chld_in); @@ -1571,15 +1573,15 @@ static void catch_output(gpointer data, gint source, GIOCondition cond) if (c == 0) break; + buf[c] = 0; ret_str = g_locale_to_utf8 - (buf, c - 1, &bytes_read, &bytes_written, NULL); - if (ret_str && bytes_written > 0) { - gtk_text_buffer_insert - (textbuf, &iter, ret_str, - -1); + (buf, c, &bytes_read, &bytes_written, NULL); + if (ret_str && bytes_written > 0) + gtk_text_buffer_insert(textbuf, &iter, ret_str, -1); + else + gtk_text_buffer_insert(textbuf, &iter, buf, c); + if (ret_str) g_free(ret_str); - } else - gtk_text_buffer_insert(textbuf, &iter, buf, c - 1); } if (child_info->children->is_selection) { @@ -1595,6 +1597,7 @@ static void catch_output(gpointer data, gint source, GIOCondition cond) gsize bytes_read = 0, bytes_written = 0; gchar *ret_str; + buf[c] = 0; ret_str = g_locale_to_utf8 (buf, c, &bytes_read, &bytes_written, NULL); if (ret_str && bytes_written > 0) {