File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,7 @@ client *createClient(connection *conn) {
167167 c -> nread = 0 ;
168168 c -> read_flags = 0 ;
169169 c -> write_flags = 0 ;
170+ c -> io_checked = 0 ;
170171 c -> cmd = c -> lastcmd = c -> realcmd = c -> io_parsed_cmd = NULL ;
171172 c -> cur_script = NULL ;
172173 c -> multibulklen = 0 ;
@@ -4832,6 +4833,13 @@ void ioThreadReadQueryFromClient(void *data) {
48324833 goto done ;
48334834 }
48344835
4836+ /* Handle possible security attacks. */
4837+ if (!strcasecmp (c -> argv [0 ]-> ptr , "host:" ) || !strcasecmp (c -> argv [0 ]-> ptr , "post" )) {
4838+ c -> io_checked = IO_CHECKED_NOT_SECURITY ;
4839+ } else {
4840+ c -> io_checked = IO_CHECKED_SECURITY ;
4841+ }
4842+
48354843 /* Lookup command offload */
48364844 c -> io_parsed_cmd = lookupCommand (c -> argv , c -> argc );
48374845 if (c -> io_parsed_cmd && commandCheckArity (c -> io_parsed_cmd , c -> argc , NULL ) == 0 ) {
Original file line number Diff line number Diff line change @@ -3829,7 +3829,8 @@ int processCommand(client *c) {
38293829 }
38303830
38313831 /* Handle possible security attacks. */
3832- if (!strcasecmp (c -> argv [0 ]-> ptr , "host:" ) || !strcasecmp (c -> argv [0 ]-> ptr , "post" )) {
3832+ if (c -> io_checked == IO_CHECKED_NOT_SECURITY ||
3833+ (!c -> io_checked && (!strcasecmp (c -> argv [0 ]-> ptr , "host:" ) || !strcasecmp (c -> argv [0 ]-> ptr , "post" )))) {
38333834 securityWarningCommand (c );
38343835 return C_ERR ;
38353836 }
Original file line number Diff line number Diff line change @@ -1148,6 +1148,12 @@ typedef enum {
11481148 CLIENT_COMPLETED_IO = 2 /* IO-thread sets this state after completing IO operation. */
11491149} clientIOState ;
11501150
1151+ typedef enum {
1152+ IO_NOT_CHECKED = 0 , /* Initial state: io thread doesn't check anything yet. */
1153+ IO_CHECKED_SECURITY = 1 , /* IO checked, there is no possible security attacks. */
1154+ IO_CHECKED_NOT_SECURITY = 2 /* IO checked, there is possible security attacks. */
1155+ } ioCheckedState ;
1156+
11511157typedef struct ClientFlags {
11521158 uint64_t primary : 1 ; /* This client is a primary */
11531159 uint64_t replica : 1 ; /* This client is a replica */
@@ -1251,6 +1257,9 @@ typedef struct client {
12511257 size_t argv_len_sum ; /* Sum of lengths of objects in argv list. */
12521258 volatile uint8_t io_read_state ; /* Indicate the IO read state of the client */
12531259 volatile uint8_t io_write_state ; /* Indicate the IO write state of the client */
1260+ uint8_t io_checked ; /* Indicate if the logic is already covered in io-thread,
1261+ * then reduce the logic in main thread.
1262+ * For example, the possible security attacks check of command. */
12541263 uint8_t cur_tid ; /* ID of IO thread currently performing IO for this client */
12551264 int nread ; /* Number of bytes of the last read. */
12561265 int nwritten ; /* Number of bytes of the last write. */
You can’t perform that action at this time.
0 commit comments