From 4f70920bbcf89cb1ce16217ea270faae42f1a02f Mon Sep 17 00:00:00 2001 From: Vitaly Ostrosablin Date: Sun, 6 Mar 2022 13:57:49 +0300 Subject: [PATCH 1/2] Add a special handling for fs_manifest rule Some servers return fs_manifest key-value pair, which has it's value split by newline, followed by a space. qstat breaks on such servers (at least, it can't fetch the rules and players, because it treats newline as beginning of player data, an unexpected data causes qstat to break with error). Following patch makes special handling for fs_manifest key, that doesn't treat newline as a separator, while keeping all other parsing intact. Signed-off-by: Vitaly Ostrosablin --- qstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qstat.c b/qstat.c index e6a3538..865abe7 100644 --- a/qstat.c +++ b/qstat.c @@ -6453,7 +6453,7 @@ deal_with_q2_packet(struct qserver *server, char *rawpkt, int pktlen) pkt += strlen(key) + 1; // Find the value - end = strpbrk(pkt, "\\\n"); + end = strpbrk(pkt, strcmp(key, "fs_manifest") ? "\\\n" : "\\"); if (NULL == end) { // Last value end = rawpkt + pktlen; From 498a91fe4167891d8f5d06023e4f017fe8ae6bf0 Mon Sep 17 00:00:00 2001 From: Vitaly Ostrosablin Date: Mon, 7 Mar 2022 15:35:13 +0300 Subject: [PATCH 2/2] display_json.c:json_escape: Support newline escaping within JSON strings Related to commit 4f70920, allowing multiline rule values from server cause JSON output mode to produce illegal JSON with unescaped newlines. This commit enables json_escape function to properly escape such values, translating newlines to \n. Signed-off-by: Vitaly Ostrosablin --- display_json.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/display_json.c b/display_json.c index 29c1bf4..c47dbbb 100644 --- a/display_json.c +++ b/display_json.c @@ -1008,6 +1008,11 @@ json_escape(char *string) *b++ = '"'; continue; + case '\n': + *b++ = '\\'; + *b++ = 'n'; + continue; + case '\\': *b++ = '\\'; *b++ = '\\';