summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2010-07-31 18:12:48 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2010-07-31 18:12:48 +0200
commitb01e650546075f574068d89eb58101a88a8f5ed2 (patch)
tree1150b7ea5d147315e07efa4eae9bfd8fed500d58
parent1dac515822e85646c2539d2c6261a9c55b6802ab (diff)
downloadpianobar-windows-b01e650546075f574068d89eb58101a88a8f5ed2.tar.gz
pianobar-windows-b01e650546075f574068d89eb58101a88a8f5ed2.tar.bz2
pianobar-windows-b01e650546075f574068d89eb58101a88a8f5ed2.zip
Fix genre station NULL pointer dereference
Obviously pandora changed the genre station api. Attention: Incompatible libpiano abi change.
-rw-r--r--libpiano/src/piano.c17
-rw-r--r--libpiano/src/piano.h8
-rw-r--r--libpiano/src/xml.c22
-rw-r--r--src/ui.c22
4 files changed, 45 insertions, 24 deletions
diff --git a/libpiano/src/piano.c b/libpiano/src/piano.c
index d8b40de..8682cda 100644
--- a/libpiano/src/piano.c
+++ b/libpiano/src/piano.c
@@ -150,6 +150,21 @@ void PianoDestroyPlaylist (PianoSong_t *playlist) {
}
}
+/* destroy genre linked list
+ */
+void PianoDestroyGenres (PianoGenre_t *genres) {
+ PianoGenre_t *curGenre, *lastGenre;
+
+ curGenre = genres;
+ while (curGenre != NULL) {
+ PianoFree (curGenre->name, 0);
+ PianoFree (curGenre->musicId, 0);
+ lastGenre = curGenre;
+ curGenre = curGenre->next;
+ PianoFree (lastGenre, sizeof (*lastGenre));
+ }
+}
+
/* frees the whole piano handle structure
* @param piano handle
* @return nothing
@@ -163,7 +178,7 @@ void PianoDestroy (PianoHandle_t *ph) {
/* destroy genre stations */
PianoGenreCategory_t *curGenreCat = ph->genreStations, *lastGenreCat;
while (curGenreCat != NULL) {
- PianoDestroyStations (curGenreCat->stations);
+ PianoDestroyGenres (curGenreCat->genres);
PianoFree (curGenreCat->name, 0);
lastGenreCat = curGenreCat;
curGenreCat = curGenreCat->next;
diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h
index fb97949..6b25b2d 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -87,9 +87,15 @@ typedef struct PianoArtist {
struct PianoArtist *next;
} PianoArtist_t;
+typedef struct PianoGenre {
+ char *name;
+ char *musicId;
+ struct PianoGenre *next;
+} PianoGenre_t;
+
typedef struct PianoGenreCategory {
char *name;
- PianoStation_t *stations;
+ PianoGenre_t *genres;
struct PianoGenreCategory *next;
} PianoGenreCategory_t;
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 33fe557..78f7f21 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -745,27 +745,27 @@ PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph, char *xml) {
/* get genre subnodes */
for (genreNode = ezxml_child (catNode, "genre"); genreNode;
genreNode = genreNode->next) {
- PianoStation_t *tmpStation;
+ PianoGenre_t *tmpGenre;
- if ((tmpStation = calloc (1, sizeof (*tmpStation))) == NULL) {
+ if ((tmpGenre = calloc (1, sizeof (*tmpGenre))) == NULL) {
ezxml_free (xmlDoc);
return PIANO_RET_OUT_OF_MEMORY;
}
/* get genre attributes */
- tmpStation->name = strdup (ezxml_attr (genreNode, "name"));
- tmpStation->id = strdup (ezxml_attr (genreNode, "stationId"));
+ tmpGenre->name = strdup (ezxml_attr (genreNode, "name"));
+ tmpGenre->musicId = strdup (ezxml_attr (genreNode, "musicId"));
/* append station */
- if (tmpGenreCategory->stations == NULL) {
- tmpGenreCategory->stations = tmpStation;
+ if (tmpGenreCategory->genres == NULL) {
+ tmpGenreCategory->genres = tmpGenre;
} else {
- PianoStation_t *curStation =
- tmpGenreCategory->stations;
- while (curStation->next != NULL) {
- curStation = curStation->next;
+ PianoGenre_t *curGenre =
+ tmpGenreCategory->genres;
+ while (curGenre->next != NULL) {
+ curGenre = curGenre->next;
}
- curStation->next = tmpStation;
+ curGenre->next = tmpGenre;
}
}
/* append category */
diff --git a/src/ui.c b/src/ui.c
index 0254089..4329a4e 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -445,7 +445,7 @@ void BarStationFromGenre (PianoHandle_t *ph, WaitressHandle_t *waith, FILE *curF
PianoReturn_t pRet;
WaitressReturn_t wRet;
PianoGenreCategory_t *curCat;
- PianoStation_t *curStation;
+ PianoGenre_t *curGenre;
PianoRequestDataCreateStation_t reqData;
int i;
@@ -481,26 +481,26 @@ void BarStationFromGenre (PianoHandle_t *ph, WaitressHandle_t *waith, FILE *curF
}
/* print all available stations */
- curStation = curCat->stations;
+ curGenre = curCat->genres;
i = 0;
- while (curStation != NULL) {
- BarUiMsg (MSG_LIST, "%2i) %s\n", i, curStation->name);
+ while (curGenre != NULL) {
+ BarUiMsg (MSG_LIST, "%2i) %s\n", i, curGenre->name);
i++;
- curStation = curStation->next;
+ curGenre = curGenre->next;
}
BarUiMsg (MSG_QUESTION, "Select genre: ");
if (BarReadlineInt (&i, curFd) == 0) {
return;
}
- curStation = curCat->stations;
- while (curStation != NULL && i > 0) {
- curStation = curStation->next;
+ curGenre = curCat->genres;
+ while (curGenre != NULL && i > 0) {
+ curGenre = curGenre->next;
i--;
}
/* create station */
- BarUiMsg (MSG_INFO, "Adding shared station \"%s\"... ", curStation->name);
- reqData.id = curStation->id;
- reqData.type = "sh";
+ BarUiMsg (MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name);
+ reqData.id = curGenre->musicId;
+ reqData.type = "mi";
BarUiPianoCall (ph, PIANO_REQUEST_CREATE_STATION, waith, &reqData, &pRet,
&wRet);
}