Skip to content

Commit 9c60fcd

Browse files
zhulipengguowangy
andauthored
Do security attack check only when command not found to reduce the critical path (#1212)
When explored the cycles distribution for main thread with io-threads enabled. We found this security attack check takes significant time in main thread, **~3%** cycles were used to do the commands security check in main thread. This patch try to completely avoid doing it in the hot path. We can do it only after we looked up the command and it wasn't found, just before we call commandCheckExistence. --------- Signed-off-by: Lipeng Zhu <[email protected]> Co-authored-by: Wangyang Guo <[email protected]>
1 parent 55bbbe0 commit 9c60fcd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/server.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,12 +3916,6 @@ int processCommand(client *c) {
39163916
reqresAppendRequest(c);
39173917
}
39183918

3919-
/* Handle possible security attacks. */
3920-
if (!strcasecmp(c->argv[0]->ptr, "host:") || !strcasecmp(c->argv[0]->ptr, "post")) {
3921-
securityWarningCommand(c);
3922-
return C_ERR;
3923-
}
3924-
39253919
/* If we're inside a module blocked context yielding that wants to avoid
39263920
* processing clients, postpone the command. */
39273921
if (server.busy_module_yield_flags != BUSY_MODULE_YIELD_NONE &&
@@ -3936,6 +3930,13 @@ int processCommand(client *c) {
39363930
* we do not have to repeat the same checks */
39373931
if (!client_reprocessing_command) {
39383932
struct serverCommand *cmd = c->io_parsed_cmd ? c->io_parsed_cmd : lookupCommand(c->argv, c->argc);
3933+
if (!cmd) {
3934+
/* Handle possible security attacks. */
3935+
if (!strcasecmp(c->argv[0]->ptr, "host:") || !strcasecmp(c->argv[0]->ptr, "post")) {
3936+
securityWarningCommand(c);
3937+
return C_ERR;
3938+
}
3939+
}
39393940
c->cmd = c->lastcmd = c->realcmd = cmd;
39403941
sds err;
39413942
if (!commandCheckExistence(c, &err)) {

0 commit comments

Comments
 (0)