summary refs log tree commit diff stats
path: root/src/common
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2016-12-04 04:39:06 -0500
committerPatrick Griffis <tingping@tingping.se>2016-12-04 04:39:06 -0500
commitb6426a1e9fb157201878c43c1c82f682beb5904d (patch)
tree69058c07a93aa6569c9da61165a4d32bccaf8d76 /src/common
parentf2d93f5abe0201c4528b07985841dab383d3d844 (diff)
Fix printing invalid utf8 from /exec output
This could possibly cause a crash.

On a related note exec_data() and exec_handle_colors() could probably
use a pass cleaning up to ensure they "do the right thing".
Diffstat (limited to 'src/common')
-rw-r--r--src/common/outbound.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/common/outbound.c b/src/common/outbound.c
index 6dd42fb4..fab0c1a2 100644
--- a/src/common/outbound.c
+++ b/src/common/outbound.c
@@ -1717,6 +1717,24 @@ memrchr (const void *block, int c, size_t size)
 }
 #endif
 
+static void
+exec_print_line (session *sess, char *data, gssize len, gboolean tochannel)
+{
+	exec_handle_colors (data, len);
+	char *valid = text_fixup_invalid_utf8 (data, len, NULL);
+	if (tochannel)
+	{
+		/* must turn off auto-completion temporarily */
+		const unsigned int old = prefs.hex_completion_auto;
+		prefs.hex_completion_auto = 0;
+		handle_multiline (sess, valid, FALSE, TRUE);
+		prefs.hex_completion_auto = old;
+	}
+	else
+		PrintText (sess, valid);
+	g_free (valid);
+}
+
 static gboolean
 exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
 {
@@ -1743,17 +1761,7 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
 		kill(s->childpid, SIGKILL);
 		if (len) {
 			buf[len] = '\0';
-			exec_handle_colors(buf, len);
-			if (s->tochannel)
-			{
-				/* must turn off auto-completion temporarily */
-				unsigned int old = prefs.hex_completion_auto;
-				prefs.hex_completion_auto = 0;
-				handle_multiline (s->sess, buf, FALSE, TRUE);
-				prefs.hex_completion_auto = old;
-			}
-			else
-				PrintText (s->sess, buf);
+			exec_print_line(s->sess, buf, len, s->tochannel);
 		}
 		g_free(buf);
 		waitpid (s->childpid, NULL, 0);
@@ -1782,11 +1790,7 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
 		s->buffill = 0;
 
 	if (len) {
-		exec_handle_colors (buf, len);
-		if (s->tochannel)
-			handle_multiline (s->sess, buf, FALSE, TRUE);
-		else
-			PrintText (s->sess, buf);
+		exec_print_line(s->sess, buf, len, s->tochannel);
 	}
 
 	g_free (buf);