[tracker] Avoid reading past the genre names array boundaries.
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Avoid reading past the genre names array boundaries.
- Date: Fri, 24 Apr 2009 08:26:28 -0400 (EDT)
commit 428df1e49ed269c852c0ec6b4f52b2b9226f73de
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Apr 21 14:22:09 2009 +0200
Avoid reading past the genre names array boundaries.
---
src/tracker-extract/tracker-extract-mp3.c | 30 +++++++++++++++++++---------
1 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 69dbdbd..7f2fc6d 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -420,6 +420,16 @@ get_genre_number (const char *str, guint *genre)
return FALSE;
}
+static const gchar *
+get_genre_name (guint number)
+{
+ if (number > G_N_ELEMENTS (genre_names)) {
+ return NULL;
+ }
+
+ return genre_names[number];
+}
+
static void
un_unsync (const unsigned char *source,
size_t size,
@@ -510,9 +520,9 @@ get_id3 (const gchar *data,
pos += 30;
- if ((guint) pos[0] < G_N_ELEMENTS (genre_names)) {
- id3->genre = g_strdup (genre_names[(unsigned) pos[0]]);
- } else {
+ id3->genre = g_strdup (get_genre_name ((guint) pos[0]));
+
+ if (!id3->genre) {
id3->genre = g_strdup ("");
}
@@ -866,10 +876,10 @@ get_id3v24_tags (const gchar *data,
if (get_genre_number (word, &genre)) {
g_free (word);
- word = g_strdup (genre_names[genre]);
+ word = g_strdup (get_genre_name (genre));
}
- if (strcasecmp (word, "unknown") == 0) {
+ if (!word || strcasecmp (word, "unknown") == 0) {
break;
}
} else if (strcmp (tmap[i].text, "TLEN") == 0) {
@@ -1117,10 +1127,10 @@ get_id3v23_tags (const gchar *data,
if (get_genre_number (word, &genre)) {
g_free (word);
- word = g_strdup (genre_names[genre]);
+ word = g_strdup (get_genre_name (genre));
}
-
- if (strcasecmp (word, "unknown") == 0) {
+
+ if (!word || strcasecmp (word, "unknown") == 0) {
break;
}
} else if (strcmp (tmap[i].text, "TLEN") == 0) {
@@ -1347,10 +1357,10 @@ get_id3v20_tags (const gchar *data,
gint genre;
if (get_genre_number (word, &genre)) {
g_free (word);
- word = g_strdup (genre_names[genre]);
+ word = g_strdup (get_genre_name (genre));
}
- if (strcasecmp (word, "unknown")==0) {
+ if (!word || strcasecmp (word, "unknown") == 0) {
g_free (word);
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]