[tracker/tracker-0.6] Avoid reading past the genre names array boundaries.



commit ea84785c8fe9492d6e9cdc50a53566fd36e3c33f
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 |   32 +++++++++++++++++++----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 8cf2549..d228373 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -407,6 +407,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,
@@ -497,9 +507,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 ("");
 	}
 
@@ -848,10 +858,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) {
@@ -1090,10 +1100,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) {
@@ -1311,10 +1321,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]