From 91386f554ebf7b8cc03eeebcef7999732c46bf64 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 19 Jun 2015 23:41:20 -0400 Subject: [PATCH] Safely handle missing fields in the serverinfo response. This fixes GFE 2.5.4.54, albeit in a non-ideal manner. A proper fix would be to parse the error out of the response and reissue the query over HTTP if it fails with error code 401. --- src/client.c | 7 +++++-- src/xml.c | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/client.c b/src/client.c index cc5245e..ef0daa9 100644 --- a/src/client.c +++ b/src/client.c @@ -124,7 +124,10 @@ static void client_load_server_status(const char *address) { paired = pairedText != NULL && strcmp(pairedText, "1") == 0; currentGame = currentGameText == NULL ? 0 : atoi(currentGameText); - strstr(versionText, ".")[0] = 0; + char *versionSep = strstr(versionText, "."); + if (versionSep != NULL) { + *versionSep = 0; + } serverMajorVersion = atoi(versionText); free(pairedText); @@ -306,7 +309,7 @@ void client_pair(const char *address) { sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&clientpairingsecret=%s", address, unique_id, client_pairing_secret_hex); http_request(url, data); - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", address, unique_id, challenge_response_hex); + sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", address, unique_id); http_request(url, data); http_free_data(data); diff --git a/src/xml.c b/src/xml.c index 1cb960a..4dc1fb9 100644 --- a/src/xml.c +++ b/src/xml.c @@ -92,7 +92,7 @@ int xml_search(char* data, size_t len, char* node, char** result) { struct xml_query search; search.data = node; search.start = 0; - search.memory = malloc(1); + search.memory = calloc(1, 1); search.size = 0; XML_Parser parser = XML_ParserCreate("UTF-8"); XML_SetUserData(parser, &search); @@ -110,7 +110,7 @@ int xml_search(char* data, size_t len, char* node, char** result) { struct app_list* xml_applist(char* data, size_t len) { struct xml_query query; - query.memory = malloc(1); + query.memory = calloc(1, 1); query.size = 0; query.start = 0; query.data = NULL;