From 38feb4c12499d644688f9208f36665176b1a2402 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Dec 2023 10:43:01 +0100 Subject: [PATCH 1/2] libnm: deprecate nm_utils_escape_ssid() nm_utils_escape_ssid() uses a static buffer, which makes it non thread-safe. We shouldn't have such API in libnm. We could improve that by using a thread-local storage, but that brings overhead, for a function that really isn't useful. It's not useful, because the escaping is very naive. You are better served with: - nm_utils_ssid_to_utf8(): gives UTF-8, but looses information. - nm_utils_bin2hexstr(): does not loose information, but makes the name unreadable. Maybe the best way to escape the SSID (which can be binary, but usually is UTF-8), are the utf8safe functions. That is because it makes the blob UFT-8, while not loosing/hiding any bytes (the escaping can be reversed). This API is currently not exposed to the users, if there were a need, then this could be done as a 3rd way for printing SSIDs. However, nm_utils_escape_ssid() is bad either way. Deprecate. --- src/libnm-core-impl/nm-utils.c | 5 +++++ src/libnm-core-public/nm-utils.h | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 4f24eba861..88df329148 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -655,8 +655,13 @@ nm_utils_is_empty_ssid(const guint8 *ssid, gsize len) * representation of that character. Intended for debugging only, should not * be used for display of SSIDs. * + * Warning: this function uses a static buffer. It is not thread-safe. Don't + * use this function. + * * Returns: pointer to the escaped SSID, which uses an internal static buffer * and will be overwritten by subsequent calls to this function + * + * Deprecated: 1.46: use nm_utils_ssid_to_utf8() or nm_utils_bin2hexstr(). **/ const char * nm_utils_escape_ssid(const guint8 *ssid, gsize len) diff --git a/src/libnm-core-public/nm-utils.h b/src/libnm-core-public/nm-utils.h index ca399c4c3e..35ef580db7 100644 --- a/src/libnm-core-public/nm-utils.h +++ b/src/libnm-core-public/nm-utils.h @@ -24,14 +24,17 @@ G_BEGIN_DECLS typedef struct _NMVariantAttributeSpec NMVariantAttributeSpec; /* SSID helpers */ -gboolean nm_utils_is_empty_ssid(const guint8 *ssid, gsize len); +gboolean nm_utils_is_empty_ssid(const guint8 *ssid, gsize len); + +NM_DEPRECATED_IN_1_46 const char *nm_utils_escape_ssid(const guint8 *ssid, gsize len); -gboolean nm_utils_same_ssid(const guint8 *ssid1, - gsize len1, - const guint8 *ssid2, - gsize len2, - gboolean ignore_trailing_null); -char *nm_utils_ssid_to_utf8(const guint8 *ssid, gsize len); + +gboolean nm_utils_same_ssid(const guint8 *ssid1, + gsize len1, + const guint8 *ssid2, + gsize len2, + gboolean ignore_trailing_null); +char *nm_utils_ssid_to_utf8(const guint8 *ssid, gsize len); /** * NMUtilsSecurityType: From 0a64237932a2576d33d8230ba519d3f1be87ec34 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Dec 2023 10:48:19 +0100 Subject: [PATCH 2/2] all: adjust nm_utils_is_empty_ssid() to return TRUE for zero length SSID A SSID of zero length, really looks "empty". Let nm_utils_is_empty_ssid() indicate so too. This affects some places, that try to guess what a hidden SSID looks like. In general, it seems that treating a length of zero as empty, is suitable also then. --- src/libnm-glib-aux/nm-shared-utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 6cbfea2c8a..f8620279b3 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -5970,6 +5970,9 @@ nm_utils_exp10(gint16 ex) gboolean _nm_utils_is_empty_ssid_arr(const guint8 *ssid, gsize len) { + if (len == 0) + return TRUE; + /* Single white space is for Linksys APs */ if (len == 1 && ssid[0] == ' ') return TRUE;