Linux: Fixed hil crash with no args passed

The hil module did not check for argc < 2.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-04-17 17:56:11 -07:00
parent 1126e7ed52
commit 47beddc88f
2 changed files with 15 additions and 5 deletions
+2 -2
View File
@@ -34,8 +34,8 @@
# #
#export PX4_TARGET_OS = nuttx #export PX4_TARGET_OS = nuttx
#export PX4_TARGET_OS = linux export PX4_TARGET_OS = linux
export PX4_TARGET_OS ?= qurt #export PX4_TARGET_OS ?= qurt
# #
# Some useful paths. # Some useful paths.
+13 -3
View File
@@ -796,11 +796,17 @@ fake(int argc, char *argv[])
extern "C" __EXPORT int hil_main(int argc, char *argv[]); extern "C" __EXPORT int hil_main(int argc, char *argv[]);
void
usage() {
fprintf(stderr, "HIL: unrecognized command, try:\n");
fprintf(stderr, " mode_pwm, mode_gpio_serial, mode_pwm_serial, mode_pwm_gpio, mode_port2_pwm8, mode_port2_pwm12, mode_port2_pwm16\n");
}
int int
hil_main(int argc, char *argv[]) hil_main(int argc, char *argv[])
{ {
PortMode new_mode = PORT_MODE_UNDEFINED; PortMode new_mode = PORT_MODE_UNDEFINED;
const char *verb = argv[1]; const char *verb;
int ret = PX4_OK; int ret = PX4_OK;
if (hil_start() != PX4_OK) { if (hil_start() != PX4_OK) {
@@ -808,6 +814,11 @@ hil_main(int argc, char *argv[])
return 1; return 1;
} }
if (argc < 2) {
usage();
return -EINVAL;
}
verb = argv[1];
/* /*
* Mode switches. * Mode switches.
*/ */
@@ -852,8 +863,7 @@ hil_main(int argc, char *argv[])
} }
else { else {
fprintf(stderr, "HIL: unrecognized command, try:\n"); usage();
fprintf(stderr, " mode_pwm, mode_gpio_serial, mode_pwm_serial, mode_pwm_gpio, mode_port2_pwm8, mode_port2_pwm12, mode_port2_pwm16\n");
ret = -EINVAL; ret = -EINVAL;
} }
return ret; return ret;