Skip to content

Commit

Permalink
Safely handle missing fields in the serverinfo response. This fixes G…
Browse files Browse the repository at this point in the history
…FE 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.
  • Loading branch information
cgutman committed Jun 20, 2015
1 parent fa4f1a3 commit 91386f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 91386f5

Please sign in to comment.