mirror of
https://github.com/joyieldInc/predixy.git
synced 2026-02-05 01:42:24 +08:00
Handle long commands safely in parser
This commit is contained in:
parent
a47a3c8cc0
commit
d4b10d5065
@ -470,6 +470,8 @@ void RequestParser::parseCmd()
|
|||||||
if (mArgLen >= Const::MaxCmdLen) {
|
if (mArgLen >= Const::MaxCmdLen) {
|
||||||
mStatus = CmdError;
|
mStatus = CmdError;
|
||||||
mType = Command::None;
|
mType = Command::None;
|
||||||
|
// Keep mCommand non-null for downstream state handling.
|
||||||
|
mCommand = &Command::get(Command::None);
|
||||||
logNotice("unknown request cmd too long:%s...", mCmd);
|
logNotice("unknown request cmd too long:%s...", mCmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
34
test/request_parser_long_command.py
Normal file
34
test/request_parser_long_command.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Send an overlong command name to ensure parser doesn't crash.
|
||||||
|
#
|
||||||
|
|
||||||
|
import socket
|
||||||
|
from test_util import parse_args, make_client, exit_with_result
|
||||||
|
|
||||||
|
|
||||||
|
def run_test(host, port):
|
||||||
|
long_cmd = b"a" * 32
|
||||||
|
payload = b"*2\r\n$32\r\n" + long_cmd + b"\r\n$1\r\nx\r\n"
|
||||||
|
try:
|
||||||
|
sock = socket.create_connection((host, port), timeout=1.0)
|
||||||
|
sock.sendall(payload)
|
||||||
|
sock.close()
|
||||||
|
except Exception as exc:
|
||||||
|
print("WARN: long command send failed:", exc)
|
||||||
|
|
||||||
|
try:
|
||||||
|
c = make_client(host, port)
|
||||||
|
if c.ping() is not True:
|
||||||
|
print("FAIL: ping after long command")
|
||||||
|
return False
|
||||||
|
except Exception as exc:
|
||||||
|
print("FAIL: ping after long command:", exc)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
args = parse_args("Request parser long command test")
|
||||||
|
success = run_test(args.host, args.port)
|
||||||
|
exit_with_result(success, "request parser long command", "request parser long command")
|
||||||
@ -143,6 +143,7 @@ TESTS=(
|
|||||||
"test/request_parser_boundary.py"
|
"test/request_parser_boundary.py"
|
||||||
"test/request_parser_error_log.py"
|
"test/request_parser_error_log.py"
|
||||||
"test/response_parser_error_log.py"
|
"test/response_parser_error_log.py"
|
||||||
|
"test/request_parser_long_command.py"
|
||||||
"test/pubsub_long_name.py"
|
"test/pubsub_long_name.py"
|
||||||
"test/pubsub_large_message.py"
|
"test/pubsub_large_message.py"
|
||||||
"test/transaction_forbid.py"
|
"test/transaction_forbid.py"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user