From 597b2ec46a3708d50ab9620d5bb4fdbd19cf8a6c Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Sat, 21 Jun 2014 12:30:41 +0200
Subject: piano: Fix segfault in GET_STATION_INFO response parser

Pandora added two new integer values to the feedback object, which
breaks the assumption that all values are arrays. Since we know the
names of the interesting keys (thumbsUp and thumbsDown) just use them
instead of iterating over all available keys.

Fixes #460.
---
 src/libpiano/response.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src/libpiano')

diff --git a/src/libpiano/response.c b/src/libpiano/response.c
index fefa610..b530f3a 100644
--- a/src/libpiano/response.c
+++ b/src/libpiano/response.c
@@ -568,7 +568,14 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
 			json_object *feedback = json_object_object_get (result,
 					"feedback");
 			if (feedback != NULL) {
-				json_object_object_foreach (feedback, key, val) {
+				static const char * const keys[] = {"thumbsUp", "thumbsDown"};
+				for (size_t i = 0; i < sizeof (keys)/sizeof (*keys); i++) {
+					json_object * const val = json_object_object_get (feedback,
+							keys[i]);
+					if (val == NULL) {
+						continue;
+					}
+					assert (json_object_is_type (val, json_type_array));
 					for (int i = 0; i < json_object_array_length (val); i++) {
 						json_object *s = json_object_array_get_idx (val, i);
 						PianoSong_t *feedbackSong;
-- 
cgit v1.2.3