Fix random crash on an ugly string handling in bsd backend.

Replace an horrible strlcat loop + g_snprintf by g_strjoinv + g_strlcpy.
Assert that the buffer is valid UTF8, blow otherwise.
This commit is contained in:
Landry Breuil
2014-12-18 22:57:52 +01:00
parent c1de490489
commit 58689d2683

View File

@@ -56,7 +56,7 @@ gboolean get_task_list (GArray *task_list)
Task t;
struct passwd *passwdp;
char **args, **ptr;
char buf[127];
gchar* buf;
int nproc, i;
mib[0] = CTL_KERN;
@@ -132,14 +132,11 @@ gboolean get_task_list (GArray *task_list)
break;
}
}
buf[0] = '\0';
for (ptr = args; *ptr != NULL; ptr++) {
if (ptr != args)
strlcat(buf, " ", sizeof(buf));
strlcat(buf, *ptr, sizeof(buf));
}
buf = g_strjoinv(" ", args);
g_assert(g_utf8_validate(buf, -1, NULL));
g_strlcpy(t.cmdline, buf, sizeof t.cmdline);
g_free(buf);
free(args);
g_snprintf(t.cmdline, sizeof t.cmdline, "%s", buf);
}
t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE));