mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 18:10:08 +01:00
cloud-setup: add and use nmcs_utils_hwaddr_normalize_gbytes()
Previously we would call
nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1);
which treats the data in response as NUL terminated. That is not
entirely wrong, because the HTTP request's response is guaranteed
to have a NUL termination at the end. However, it doesn't seam to good
either.
For one, we already have the length. Use it. But also, if the response
contains any NUL bytes in the middle, then this would wrongly only
consider the first line. We should not accept "00:11:22:33:44:55\0bogus"
as valid.
While at it, reject NUL characters from nmcs_utils_hwaddr_normalize() --
except one NUL at the end.
This commit is contained in:
parent
2ba984a80a
commit
511b4ab411
4 changed files with 22 additions and 3 deletions
|
|
@ -495,8 +495,17 @@ nmcs_utils_hwaddr_normalize(const char *hwaddr, gssize len)
|
|||
if (!hwaddr)
|
||||
return NULL;
|
||||
l = strlen(hwaddr);
|
||||
} else
|
||||
} else {
|
||||
l = len;
|
||||
if (l > 0 && hwaddr[l - 1] == '\0') {
|
||||
/* we accept one '\0' at the end of the string. */
|
||||
l--;
|
||||
}
|
||||
if (memchr(hwaddr, '\0', l)) {
|
||||
/* but we don't accept other NUL characters in the middle. */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (l == 0)
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,16 @@ gboolean nmcs_utils_poll_finish(GAsyncResult *result, gpointer *probe_user_data,
|
|||
|
||||
char *nmcs_utils_hwaddr_normalize(const char *hwaddr, gssize len);
|
||||
|
||||
static inline char *
|
||||
nmcs_utils_hwaddr_normalize_gbytes(GBytes *hwaddr)
|
||||
{
|
||||
const char *str;
|
||||
gsize len;
|
||||
|
||||
str = g_bytes_get_data(hwaddr, &len);
|
||||
return nmcs_utils_hwaddr_normalize(str, len);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nmcs_utils_parse_memmem(GBytes *mem, const char *needle);
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
|||
if (error)
|
||||
goto out_done;
|
||||
|
||||
iface_data->hwaddr = nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1);
|
||||
iface_data->hwaddr = nmcs_utils_hwaddr_normalize_gbytes(response);
|
||||
|
||||
if (!iface_data->hwaddr)
|
||||
goto out_done;
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
|||
if (error)
|
||||
goto out_error;
|
||||
|
||||
hwaddr = nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1);
|
||||
hwaddr = nmcs_utils_hwaddr_normalize_gbytes(response);
|
||||
iface_data->iface_get_config = g_hash_table_lookup(get_config_data->result_dict, hwaddr);
|
||||
if (!iface_data->iface_get_config) {
|
||||
_LOGI("GCP interface[%" G_GSSIZE_FORMAT "]: did not find a matching device",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue