diff options
author | Rashmica Gupta <rashmica.g@gmail.com> | 2018-05-08 10:06:56 +1000 |
---|---|---|
committer | Alistair Popple <alistair@popple.id.au> | 2018-05-08 12:46:09 +1000 |
commit | 44836e05cdb36f628044ced2bd322d84fd77b0b7 (patch) | |
tree | 4ad8f394aff9c2afcf2f1f0b3c6bb2c99b293c29 /src/htm.c | |
parent | 1e3c4192f4beffbb35a81a9c892b206e6025e80c (diff) | |
download | pdbg-44836e05cdb36f628044ced2bd322d84fd77b0b7.tar.gz pdbg-44836e05cdb36f628044ced2bd322d84fd77b0b7.zip |
htm: Avoid segfault when an option is omitted
Currently if the user omits an htm command such as 'start' or 'stop'
we segfault. This happens because we check for the wrong number of
arguments.
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
Diffstat (limited to 'src/htm.c')
-rw-r--r-- | src/htm.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -279,7 +279,14 @@ int run_htm(int optind, int argc, char *argv[]) struct pdbg_target *core_target = NULL; int i, rc = 0; - if (argc - optind < 2) { + /* + * As the index of the last argument is one less than argc, the difference + * between optind and argc will always be at least 1. Here optind is pointing + * to the 'htm' arg and we need at least 2 more following arguments, eg: + * htm <nest/core> <start/stop/etc> + * so argc-optind >= 3 to proceed. + */ + if (argc - optind < 3) { fprintf(stderr, "Expecting one of 'core' or 'nest' with a command\n"); return 0; } |