qrexec: use #define for protocol-specified strings

And optimize strlen() calls.
Those defines are in qrexec.h (as the rest of qrexec protocol).
This commit is contained in:
Marek Marczykowski-Górecki 2015-11-08 22:06:54 +01:00
parent b6d4f5afbf
commit 823954c7f6
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -84,7 +84,7 @@ void no_colon_in_cmd()
*/ */
void do_exec(const char *cmd) void do_exec(const char *cmd)
{ {
char buf[strlen(QUBES_RPC_MULTIPLEXER_PATH) + strlen(cmd) - strlen(RPC_REQUEST_COMMAND) + 1]; char buf[strlen(QUBES_RPC_MULTIPLEXER_PATH) + strlen(cmd) - RPC_REQUEST_COMMAND_LEN + 1];
char *realcmd = index(cmd, ':'); char *realcmd = index(cmd, ':');
if (!realcmd) if (!realcmd)
no_colon_in_cmd(); no_colon_in_cmd();
@ -92,12 +92,12 @@ void do_exec(const char *cmd)
*realcmd = 0; *realcmd = 0;
realcmd++; realcmd++;
/* ignore "nogui:" prefix in linux agent */ /* ignore "nogui:" prefix in linux agent */
if (strncmp(realcmd, "nogui:", strlen("nogui:")) == 0) if (strncmp(realcmd, NOGUI_CMD_PREFIX, NOGUI_CMD_PREFIX_LEN) == 0)
realcmd += strlen("nogui:"); realcmd += NOGUI_CMD_PREFIX_LEN;
/* replace magic RPC cmd with RPC multiplexer path */ /* replace magic RPC cmd with RPC multiplexer path */
if (strncmp(realcmd, RPC_REQUEST_COMMAND " ", strlen(RPC_REQUEST_COMMAND)+1)==0) { if (strncmp(realcmd, RPC_REQUEST_COMMAND " ", RPC_REQUEST_COMMAND_LEN+1)==0) {
strcpy(buf, QUBES_RPC_MULTIPLEXER_PATH); strcpy(buf, QUBES_RPC_MULTIPLEXER_PATH);
strcpy(buf + strlen(QUBES_RPC_MULTIPLEXER_PATH), realcmd + strlen(RPC_REQUEST_COMMAND)); strcpy(buf + strlen(QUBES_RPC_MULTIPLEXER_PATH), realcmd + RPC_REQUEST_COMMAND_LEN);
realcmd = buf; realcmd = buf;
} }
signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, SIG_DFL);