summaryrefslogtreecommitdiff
path: root/src/libpiano/piano.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2012-01-15 20:21:50 +0100
committerLars-Dominik Braun <lars@6xq.net>2012-01-20 12:10:23 +0100
commitd44f61b583a112e23a9af405968b11514979fedf (patch)
treebbb3332087374d1c59d99bbbe0f2f3213508096c /src/libpiano/piano.c
parent9a380af719b0cdb599eaf86323bd7ca9a0526482 (diff)
downloadpianobar-d44f61b583a112e23a9af405968b11514979fedf.tar.gz
pianobar-d44f61b583a112e23a9af405968b11514979fedf.tar.bz2
pianobar-d44f61b583a112e23a9af405968b11514979fedf.zip
piano: Make sync response parser NUL-byte aware
Fixes #207
Diffstat (limited to 'src/libpiano/piano.c')
-rw-r--r--src/libpiano/piano.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/libpiano/piano.c b/src/libpiano/piano.c
index 3a5e97c..2c2a8d8 100644
--- a/src/libpiano/piano.c
+++ b/src/libpiano/piano.c
@@ -900,24 +900,23 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
/* abusing parseNarrative; has same xml structure */
ret = PianoXmlParseNarrative (req->responseData, &cryptedTimestamp);
- if (cryptedTimestamp != NULL) {
+ if (ret == PIANO_RET_OK && cryptedTimestamp != NULL) {
unsigned long timestamp = 0;
- time_t realTimestamp = time (NULL);
- char *decryptedTimestamp = NULL, *decryptedPos = NULL;
- unsigned char i = 4;
-
- if ((decryptedTimestamp = PianoDecryptString (cryptedTimestamp)) != NULL) {
- decryptedPos = decryptedTimestamp;
- /* skip four bytes garbage? at beginning */
- while (i-- > 0 && *decryptedPos++ != '\0');
- timestamp = strtoul (decryptedPos, NULL, 0);
+ const time_t realTimestamp = time (NULL);
+ char *decryptedTimestamp = NULL;
+ size_t decryptedSize;
+
+ ret = PIANO_RET_ERR;
+ if ((decryptedTimestamp = PianoDecryptString (cryptedTimestamp,
+ &decryptedSize)) != NULL && decryptedSize > 4) {
+ /* skip four bytes garbage(?) at beginning */
+ timestamp = strtoul (decryptedTimestamp+4, NULL, 0);
ph->timeOffset = realTimestamp - timestamp;
-
- free (decryptedTimestamp);
+ ret = PIANO_RET_CONTINUE_REQUEST;
}
- free (cryptedTimestamp);
+ free (decryptedTimestamp);
}
- ret = PIANO_RET_CONTINUE_REQUEST;
+ free (cryptedTimestamp);
++reqData->step;
break;
}