libnm-util: validate connection uuid

This commit is contained in:
Dan Williams 2009-05-03 01:09:07 -04:00
parent 756bc70402
commit eee3c4ceb2

View file

@ -24,6 +24,7 @@
*/
#include <string.h>
#include <ctype.h>
#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,