diff options
author | Thomas Haller <thaller@redhat.com> | 2021-06-02 09:55:03 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-06-04 09:29:22 +0200 |
commit | 423e83b88037024424b2ac11e163e6bee8247678 (patch) | |
tree | 1b87dc6a2bcdb10c8fa9145bfedf26f72450afd0 | |
parent | 7e8e6836e0ec3bac1c5b3e681f87363cd46aec2d (diff) | |
download | NetworkManager-423e83b88037024424b2ac11e163e6bee8247678.tar.gz |
keyfile: reject non-normalized UUIDs in nms_keyfile_nmmeta_check_filename()
Since commit 207cf3d5d4c9 ('libnm: normalize "connection.uuid"') the
"connection.uuid" is normalized to be a valid UUID and all lower case.
That means, if we have .nmmeta files on disk with a previously valid,
but now invalid UUID, the meta file is no longer going to match.
Reject such file outright as invalid. If we really wanted to preserve
backward compatibility, then we would have to also normalize the
filename when we read it. However, that means, that suddenly we might
have any number of compatible .nmmeta files that normalize to the same
UUID, like the files
71088c75dec54119ab41be71bc10e736aaaabbbb.nmmeta
F95D40B4-578A-5E68-8597-39392249442B.nmmeta
f95d40b4-578a-5e68-8597-39392249442b.nmmeta
Having multiple places for the nmmeta file is complicated to handle.
Also, we often have the connection profile (and the normalized UUID)
first, and then check whether it has a .nmmeta file. If we would support
those unnormalized file names, we would have to visit all file names and
try to normalize it, to find those with a matching UUID.
Non-normalized UUIDs really should not be used and they already are not
working anymore for the .nmmeta file. This commit only outright rejects
them. This is a change in behavior, but the behavior change happened
earlier when we started normalizing "connection.uuid".
-rw-r--r-- | src/core/settings/plugins/keyfile/nms-keyfile-utils.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c index 2391a9fd77..44bb86829f 100644 --- a/src/core/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/core/settings/plugins/keyfile/nms-keyfile-utils.c @@ -10,6 +10,7 @@ #include <stdlib.h> #include <sys/stat.h> +#include "libnm-glib-aux/nm-uuid.h" #include "libnm-glib-aux/nm-io-utils.h" #include "libnm-core-intern/nm-keyfile-internal.h" #include "nm-utils.h" @@ -30,9 +31,9 @@ const char * nms_keyfile_nmmeta_check_filename(const char *filename, guint *out_uuid_len) { - const char *uuid; const char *s; gsize len; + char uuid[37]; s = strrchr(filename, '/'); if (s) @@ -50,17 +51,18 @@ nms_keyfile_nmmeta_check_filename(const char *filename, guint *out_uuid_len) len -= NM_STRLEN(NM_KEYFILE_PATH_SUFFIX_NMMETA); - if (!NM_IN_SET(len, 36, 40)) { + if (len != 36) { /* the remaining part of the filename has not the right length to * contain a UUID (according to nm_utils_is_uuid()). */ return NULL; } - uuid = nm_strndup_a(100, filename, len, NULL); - if (!nm_utils_is_uuid(uuid)) + memcpy(uuid, filename, 36); + uuid[36] = '\0'; + if (!nm_uuid_is_normalized(uuid)) return NULL; - NM_SET_OUT(out_uuid_len, len); + NM_SET_OUT(out_uuid_len, 36); return filename; } |