diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-08-26 14:10:00 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2022-08-26 14:10:00 +0000 |
commit | e0613dc66fd140a1f865126e147ead91c8dd51ef (patch) | |
tree | 70f29ad30c78b4102ba60ef52cadf15a6b674cbc /fnet | |
parent | db4fce7cab1470c85e32cf8c0db10accb47f9a5d (diff) |
Avoid out of bounds access to the argv array.
The following would crash the program before:
vespa-rpc-invoke -t 1 tcp/localhost:1234
Diffstat (limited to 'fnet')
-rw-r--r-- | fnet/src/examples/frt/rpc/rpc_invoke.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/fnet/src/examples/frt/rpc/rpc_invoke.cpp b/fnet/src/examples/frt/rpc/rpc_invoke.cpp index a6177999d70..9f3e90f469a 100644 --- a/fnet/src/examples/frt/rpc/rpc_invoke.cpp +++ b/fnet/src/examples/frt/rpc/rpc_invoke.cpp @@ -51,10 +51,14 @@ public: int main(int argc, char **argv); }; +bool timeout_specified(char **argv) { + return strcmp(argv[1], "-t") == 0; +} + int RPCClient::main(int argc, char **argv) { - if (argc < 3) { + if ((argc < 3) || (timeout_specified(argv) && argc < 5)) { fprintf(stderr, "usage: vespa-rpc-invoke [-t timeout] <connectspec> <method> [args]\n"); fprintf(stderr, " -t timeout in seconds\n"); fprintf(stderr, " Each arg must be on the form <type>:<value>\n"); @@ -79,7 +83,7 @@ RPCClient::run(int argc, char **argv) int methNameArg = 2; int startOfArgs = 3; int timeOut = 10; - if (strcmp(argv[1], "-t") == 0) { + if (timeout_specified(argv)) { timeOut = atoi(argv[2]); targetArg = 3; methNameArg = 4; |