From eee3c4ceb2f2a27b9baf23c76e5c8cfc50e48377 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 3 May 2009 01:09:07 -0400 Subject: [PATCH] libnm-util: validate connection uuid --- libnm-util/nm-setting-connection.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c index 86cb8fb2d8..113262f52d 100644 --- a/libnm-util/nm-setting-connection.c +++ b/libnm-util/nm-setting-connection.c @@ -24,6 +24,7 @@ */ #include +#include #include "nm-setting-connection.h" /** @@ -218,6 +219,22 @@ find_setting_by_name (gconstpointer a, gconstpointer b) return strcmp (nm_setting_get_name (setting), str); } +static gboolean +validate_uuid (const char *uuid) +{ + int i; + + if (!uuid || !strlen (uuid)) + return FALSE; + + for (i = 0; i < strlen (uuid); i++) { + if (!isxdigit (uuid[i]) && (uuid[i] != '-')) + return FALSE; + } + + return TRUE; +} + static gboolean verify (NMSetting *setting, GSList *all_settings, GError **error) { @@ -243,7 +260,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY, NM_SETTING_CONNECTION_UUID); return FALSE; - } else if (!strlen (priv->uuid)) { + } else if (!validate_uuid (priv->uuid)) { g_set_error (error, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,