This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit 1099f5951685b5abb3c7937011dc0217f4d21a21 Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Jun 29 14:31:36 2020 +0200 src/x2goclient-network-ssh.c: add private wrapper function x2goclient_network_ssh_log_std_str (). Prints out an stdout or stderr string in a potentially multi-stage process if the size is bigger than INT_MAX. --- src/x2goclient-network-ssh.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index a515f85..96ec797 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <errno.h> #include <limits.h> +#include <stdbool.h> #include <glib.h> #include <glib/gi18n.h> @@ -131,6 +132,7 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetwork static gboolean x2goclient_network_ssh_kill_subprocesses (X2GoClientNetworkSSH *self); static gboolean x2goclient_network_ssh_parent_connect (X2GoClientNetwork *parent, GError **gerr); static gboolean x2goclient_network_ssh_fetch_openssh_version (X2GoClientNetworkSSH *self, GError **gerr); +static void x2goclient_network_ssh_log_std_str (const gchar * const str, const gsize str_size, const _Bool stderr); static void x2goclient_network_ssh_class_init (X2GoClientNetworkSSHClass *klass) { @@ -1021,3 +1023,54 @@ static gboolean x2goclient_network_ssh_fetch_openssh_version (X2GoClientNetworkS return (ret); } + +static void x2goclient_network_ssh_log_std_str (const gchar * const str, const gsize str_size, const _Bool stderr) { + /* + * For a size bigger than zero, the bytes object must be non-NULL, + * otherwise any value is legit according to the documentation. + */ + g_return_if_fail (((str_size) && (str)) || (!(str_size))); + + const gchar *stream = "out"; + + if (stderr) { + stream = "err"; + } + + if ((str) && (str_size)) { + gsize str_size_work = str_size; + + g_log (NULL, G_LOG_LEVEL_DEBUG, "Std%s:", stream); + + _Bool cont = FALSE; + const gchar *str_work = str; + while (str_size_work) { + int cur_len = str_size_work; + + if (INT_MAX < str_size_work) { + cur_len = INT_MAX; + str_size_work -= INT_MAX; + } + + const char *fmt = ">>>%.*s<<<"; + if (cont) { + fmt = "(continuation) >>>%.*s<<<"; + } + + g_log (NULL, G_LOG_LEVEL_DEBUG, fmt, cur_len, str_work); + + /* + * Setting this out of bounds is fine as long as we don't actually access + * out-of-bounds data. + * + * Be extra careful here. + */ + str_work += cur_len; + + cont = TRUE; + } + } + else { + g_log (NULL, G_LOG_LEVEL_DEBUG, "Std%s: no data", stream); + } +} -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git