From 2fa821028d2457a4e9d62381edb635769b8bf704 Mon Sep 17 00:00:00 2001 From: Shobhit Adlakha Date: Fri, 27 May 2022 10:15:34 -0400 Subject: Fix/Adjust PTS content length for newline string (#3913) * Add check for newline string and adjust content length for added escape character * Apply same fix to sample_policy_manager for extern proprietary * Address review comments --- src/appMain/sample_policy_manager.py | 7 ++++++- .../src/commands/mobile/on_system_request_notification.cc | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/appMain/sample_policy_manager.py b/src/appMain/sample_policy_manager.py index 75a04685ed..2b3f835c57 100644 --- a/src/appMain/sample_policy_manager.py +++ b/src/appMain/sample_policy_manager.py @@ -25,12 +25,17 @@ parser.add_argument("--encryption", action="store_true", def http_header(data): +# The Content-Length to be sent in the HTTP Request header should be +# adjusted for additional escape characters added for newline strings +# The mobile proxy will remove the escape characters after receiving this request. + content_length = len(data) - data.count('\\') + header = {} header["HTTPRequest"] = {} header["HTTPRequest"]["headers"] = { "ConnectTimeout": 60, "ContentType": "application/json", - "Content-Length": len(data), + "Content-Length": content_length, "DoInput": True, "DoOutput": True, "InstanceFollowRedirects": False, diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc index af0a5a6539..0537043cd4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc @@ -225,8 +225,13 @@ size_t OnSystemRequestNotification::ParsePTString( size_t result_length = length; result.reserve(length * 2); for (size_t i = 0; i < length; ++i) { - if (pt_string[i] == '\"' || pt_string[i] == '\\') { + if (pt_string[i] == '\"') { result += '\\'; + } else if (pt_string[i] == '\\') { + result += '\\'; + --result_length; // contentLength is adjusted for the additional escape + // character added before special characters (like the + // newline string) } else if (pt_string[i] == '\n') { --result_length; // contentLength is adjusted when this character is // not copied to result. -- cgit v1.2.1