[glib] GApplications: Tighten up application-id validity checks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GApplications: Tighten up application-id validity checks
- Date: Fri, 25 Feb 2011 16:15:31 +0000 (UTC)
commit e3cff93408163009dbc2dd3b6d90cd620385fc28
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 25 11:13:55 2011 -0500
GApplications: Tighten up application-id validity checks
Also add tests for these conditions.
https://bugzilla.gnome.org/show_bug.cgi?id=643197
gio/gapplication.c | 32 ++++++++++++++++++++++++--------
1 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 263b71a..44f1cdb 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -647,9 +647,9 @@ get_platform_data (GApplication *application)
* For convenience, the restrictions on application identifiers are
* reproduced here:
* <itemizedlist>
- * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-" and must not begin with a digit.</listitem>
- * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least two elements).</listitem>
- * <listitem>Application identifiers must not begin with a '.' (period) character.</listitem>
+ * <listitem>Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-." and must not begin with a digit.</listitem>
+ * <listitem>Application identifiers must contain at least one '.' (period) character (and thus at least three elements).</listitem>
+ * <listitem>Application identifiers must not begin or end with a '.' (period) character.</listitem>
* <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem>
* <listitem>Application identifiers must not exceed 255 characters.</listitem>
* </itemizedlist>
@@ -657,28 +657,44 @@ get_platform_data (GApplication *application)
gboolean
g_application_id_is_valid (const gchar *application_id)
{
+ gsize len;
gboolean allow_dot;
+ gboolean has_dot;
- if (strlen (application_id) > 255)
+ len = strlen (application_id);
+
+ if (len > 255)
+ return FALSE;
+
+ if (!g_ascii_isalpha (application_id[0]))
return FALSE;
- if (!g_ascii_isalpha (*application_id))
+ if (application_id[len-1] == '.')
return FALSE;
application_id++;
- allow_dot = FALSE;
+ allow_dot = TRUE;
+ has_dot = FALSE;
for (; *application_id; application_id++)
{
if (g_ascii_isalnum (*application_id) ||
(*application_id == '-') ||
(*application_id == '_'))
- allow_dot = TRUE;
+ {
+ allow_dot = TRUE;
+ }
else if (allow_dot && *application_id == '.')
- allow_dot = FALSE;
+ {
+ has_dot = TRUE;
+ allow_dot = FALSE;
+ }
else
return FALSE;
}
+ if (!has_dot)
+ return FALSE;
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]