mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-19 00:40:35 +01:00
dhcp: cleanup build_signal_parameters() in nm-dhcp-helper
Also, silently ignore all environment variables with a name that is not valid UTF-8. We would hit an assertion trying to put that in a GVariant (or sending it via D-Bus).
This commit is contained in:
parent
d9740d108d
commit
ed32651ab8
1 changed files with 28 additions and 15 deletions
|
|
@ -46,33 +46,46 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char * ignore[] = {"PATH", "SHLVL", "_", "PWD", "dhc_dbus", NULL};
|
||||
|
||||
static GVariant *
|
||||
build_signal_parameters (void)
|
||||
{
|
||||
char **item;
|
||||
const char *const*environ_iter;
|
||||
GVariantBuilder builder;
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
|
||||
|
||||
/* List environment and format for dbus dict */
|
||||
for (item = environ; *item; item++) {
|
||||
char *name, *val, **p;
|
||||
for (environ_iter = (const char *const*) environ; *environ_iter; environ_iter++) {
|
||||
static const char *const ignore_with_prefix_list[] = {
|
||||
"PATH",
|
||||
"SHLVL",
|
||||
"_",
|
||||
"PWD",
|
||||
"dhc_dbus",
|
||||
NULL
|
||||
};
|
||||
const char *item = *environ_iter;
|
||||
gs_free char *name = NULL;
|
||||
const char *val;
|
||||
const char *const*p;
|
||||
|
||||
/* Split on the = */
|
||||
name = g_strdup (*item);
|
||||
val = strchr (name, '=');
|
||||
if (!val || val == name)
|
||||
goto next;
|
||||
*val++ = '\0';
|
||||
val = strchr (item, '=');
|
||||
if ( !val
|
||||
|| item == val)
|
||||
continue;
|
||||
|
||||
/* Ignore non-DCHP-related environment variables */
|
||||
for (p = (char **) ignore; *p; p++) {
|
||||
name = g_strndup (item, val - item);
|
||||
val += 1;
|
||||
|
||||
/* Ignore non-DHCP-related environment variables */
|
||||
for (p = ignore_with_prefix_list; *p; p++) {
|
||||
if (strncmp (name, *p, strlen (*p)) == 0)
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (!g_utf8_validate (name, -1, NULL))
|
||||
continue;
|
||||
|
||||
/* Value passed as a byte array rather than a string, because there are
|
||||
* no character encoding guarantees with DHCP, and D-Bus requires
|
||||
* strings to be UTF-8.
|
||||
|
|
@ -85,8 +98,8 @@ build_signal_parameters (void)
|
|||
g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
val, strlen (val), 1));
|
||||
|
||||
next:
|
||||
g_free (name);
|
||||
next:
|
||||
;
|
||||
}
|
||||
|
||||
return g_variant_ref_sink (g_variant_new ("(a{sv})", &builder));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue