Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,60 @@ private static int parse_args (String[] args, BrainFlowInputParams params)
int board_id = -1;
for (int i = 0; i < args.length; i++)
{
if (args[i].equals ("--ip-address"))
String arg = args[i];
boolean requires_value = arg.equals ("--ip-address") || arg.equals ("--serial-port")
|| arg.equals ("--ip-port") || arg.equals ("--ip-protocol")
|| arg.equals ("--other-info") || arg.equals ("--board-id")
|| arg.equals ("--timeout") || arg.equals ("--serial-number")
|| arg.equals ("--file");
if (requires_value && i + 1 >= args.length)
{
throw new IllegalArgumentException ("Missing value for argument: " + arg);
Comment on lines +39 to +41
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject option tokens used as missing argument values

The new guard only checks that i + 1 exists, so a missing value in the middle of the CLI can still consume the next flag as data (for example, --ip-address --board-id 1 sets ip_address to --board-id and then skips parsing --board-id because of the later i++). This silently misconfigures inputs instead of reporting a missing value, which is a regression from the intended validation behavior. Consider treating a known flag token in args[i + 1] as an absent value and throwing IllegalArgumentException in that case as well.

Useful? React with 👍 / 👎.

}
if (arg.equals ("--ip-address"))
{
params.ip_address = args[i + 1];
i++;
}
if (args[i].equals ("--serial-port"))
if (arg.equals ("--serial-port"))
{
params.serial_port = args[i + 1];
i++;
}
if (args[i].equals ("--ip-port"))
if (arg.equals ("--ip-port"))
{
params.ip_port = Integer.parseInt (args[i + 1]);
i++;
}
if (args[i].equals ("--ip-protocol"))
if (arg.equals ("--ip-protocol"))
{
params.ip_protocol = Integer.parseInt (args[i + 1]);
i++;
}
if (args[i].equals ("--other-info"))
if (arg.equals ("--other-info"))
{
params.other_info = args[i + 1];
i++;
}
if (args[i].equals ("--board-id"))
if (arg.equals ("--board-id"))
{
board_id = Integer.parseInt (args[i + 1]);
i++;
}
if (args[i].equals ("--timeout"))
if (arg.equals ("--timeout"))
{
params.timeout = Integer.parseInt (args[i + 1]);
i++;
}
if (args[i].equals ("--serial-number"))
if (arg.equals ("--serial-number"))
{
params.serial_number = args[i + 1];
i++;
}
if (args[i].equals ("--file"))
if (arg.equals ("--file"))
{
params.file = args[i + 1];
i++;
}
}
return board_id;
Expand Down
Loading