From d44f61b583a112e23a9af405968b11514979fedf Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 15 Jan 2012 20:21:50 +0100 Subject: piano: Make sync response parser NUL-byte aware Fixes #207 --- src/libpiano/piano.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/libpiano/piano.c') 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; } -- cgit v1.2.3