Skip to content

Commit

Permalink
Run server with escaped hook_script argument
Browse files Browse the repository at this point in the history
Unlike what would be expected, adb shell just concatenates the arguments as strings same
as if they were just separated by spaces. Sending the commands in one argument
or sending as multiple arguments doesn't preduce any different outcome.
Sad but that's how adb works.

try:
adb shell 'am broadcast'
vs
adb shell am broadcast

If they both work, means there's no reasonable way to deliver the arguments as-is.
They have to be escaped.
  • Loading branch information
brunoais committed Apr 16, 2022
1 parent 2ea9cdd commit 4287759
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ sc_server_params_copy(struct sc_server_params *dst,
COPY(crop);
COPY(codec_options);
COPY(encoder_name);
COPY(hook_script);
COPY(tcpip_dst);
#undef COPY

Expand Down Expand Up @@ -233,6 +234,23 @@ execute_server(struct sc_server *server,
if (params->encoder_name) {
ADD_PARAM("encoder_name=%s", params->encoder_name);
}
if (params->hook_script) {
char* requoted_hook;
int64_t replace_result = sc_str_find_replace(params->hook_script, "'", "'\"'\"'", &requoted_hook);
switch(replace_result){
case -2:
LOG_OOM();
break;
case -1:
case 0:
ADD_PARAM("hook_script='%s'", params->hook_script);
break;
default:
ADD_PARAM("hook_script='%s'", requoted_hook);
free(requoted_hook);
}

}
if (params->power_off_on_close) {
ADD_PARAM("power_off_on_close=true");
}
Expand Down
1 change: 1 addition & 0 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct sc_server_params {
bool show_touches;
bool stay_awake;
bool force_adb_forward;
const char * hook_script;
bool power_off_on_close;
bool clipboard_autosync;
bool downsize_on_error;
Expand Down

0 comments on commit 4287759

Please sign in to comment.