mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 15:33:34 +08:00
using only px4_getopt() and never the unsafe getopt()
using only <px4_getopt.h> as include, cleanup related includes added check that all the option are valid (myoptind >= argc). if there are invalid options on some script that might now lead not to run commands
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <px4_getopt.h>
|
||||
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
@@ -371,10 +372,13 @@ pca8574_main(int argc, char *argv[])
|
||||
int i2cdevice = -1;
|
||||
int pca8574adr = ADDR; // 7bit
|
||||
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
|
||||
// jump over start/off/etc and look at options first
|
||||
while ((ch = getopt(argc, argv, "a:b:")) != EOF) {
|
||||
while ((ch = px4_getopt(argc, argv, "a:b:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
pca8574adr = strtol(optarg, NULL, 0);
|
||||
@@ -390,12 +394,12 @@ pca8574_main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (optind >= argc) {
|
||||
if (myoptind >= argc) {
|
||||
pca8574_usage();
|
||||
exit(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const char *verb = argv[optind];
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
Reference in New Issue
Block a user