From bb5ce4b2d3b825c03d29226e3f05f9ab266d4517 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 27 Nov 2005 20:15:41 +0000 Subject: [PATCH] Don't read beyond len. (#322520, Christian Persch) 2005-11-27 Matthias Clasen * glib/gunicollate.c (g_utf8_collate_key_for_filename): Don't read beyond len. (#322520, Christian Persch) --- ChangeLog | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ ChangeLog.pre-2-12 | 5 +++++ glib/gunicollate.c | 10 +++++----- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e41ea2da..e8f9a2fad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-11-27 Matthias Clasen + + * glib/gunicollate.c (g_utf8_collate_key_for_filename): + Don't read beyond len. (#322520, Christian Persch) + Wed Nov 23 17:34:01 2005 Tim Janik * glib/gdataset.c: access datalist flags via atomic pointer access diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4e41ea2da..e8f9a2fad 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2005-11-27 Matthias Clasen + + * glib/gunicollate.c (g_utf8_collate_key_for_filename): + Don't read beyond len. (#322520, Christian Persch) + Wed Nov 23 17:34:01 2005 Tim Janik * glib/gdataset.c: access datalist flags via atomic pointer access diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 4e41ea2da..e8f9a2fad 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +2005-11-27 Matthias Clasen + + * glib/gunicollate.c (g_utf8_collate_key_for_filename): + Don't read beyond len. (#322520, Christian Persch) + Wed Nov 23 17:34:01 2005 Tim Janik * glib/gdataset.c: access datalist flags via atomic pointer access diff --git a/glib/gunicollate.c b/glib/gunicollate.c index b00be88c6..b702a639d 100644 --- a/glib/gunicollate.c +++ b/glib/gunicollate.c @@ -298,6 +298,7 @@ g_utf8_collate_key_for_filename (const gchar *str, GString *append; const gchar *p; const gchar *prev; + const gchar *end; gchar *collate_key; gint digits; gint leading_zeros; @@ -354,8 +355,10 @@ g_utf8_collate_key_for_filename (const gchar *str, result = g_string_sized_new (len * 2); append = g_string_sized_new (0); + end = str + len; + /* No need to use utf8 functions, since we're only looking for ascii chars */ - for (prev = p = str; *p != '\0'; p++) + for (prev = p = str; p < end; p++) { switch (*p) { @@ -406,10 +409,8 @@ g_utf8_collate_key_for_filename (const gchar *str, digits = 1; } - do + while (++p < end) { - p++; - if (*p == '0' && !digits) ++leading_zeros; else if (g_ascii_isdigit(*p)) @@ -427,7 +428,6 @@ g_utf8_collate_key_for_filename (const gchar *str, break; } } - while (*p != '\0'); while (digits > 1) {