[Pdbg] [PATCH] htm: Avoid segfault when an option is omitted
Rashmica Gupta
rashmica.g at gmail.com
Tue May 8 10:06:56 AEST 2018
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 at gmail.com>
---
src/htm.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/htm.c b/src/htm.c
index 566687e..084a3ba 100644
--- a/src/htm.c
+++ b/src/htm.c
@@ -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;
}
--
2.14.3
More information about the Pdbg
mailing list