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 @@ -49,41 +49,52 @@ 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];
if (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"))
{
params.ip_address = args[i + 1];
}
if (args[i].equals ("--serial-port"))
{
params.serial_port = args[i + 1];
}
if (args[i].equals ("--ip-port"))
{
params.ip_port = Integer.parseInt (args[i + 1]);
}
if (args[i].equals ("--ip-protocol"))
{
params.ip_protocol = Integer.parseInt (args[i + 1]);
}
if (args[i].equals ("--other-info"))
{
params.other_info = args[i + 1];
}
if (args[i].equals ("--board-id"))
{
board_id = Integer.parseInt (args[i + 1]);
}
if (args[i].equals ("--timeout"))
{
params.timeout = Integer.parseInt (args[i + 1]);
}
if (args[i].equals ("--serial-number"))
{
params.serial_number = args[i + 1];
}
if (args[i].equals ("--file"))
{
params.file = args[i + 1];
if (i + 1 >= args.length)
{
throw new IllegalArgumentException ("Missing value for argument: " + arg);
}
String value = args[++i];
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 missing option values before consuming next flag

Using String value = args[++i]; without checking whether args[i + 1] is itself another CLI flag causes a new parsing regression: if a value is omitted in the middle (for example --ip-address --serial-port COM3), --serial-port is consumed as the IP value and then skipped entirely, so serial_port is never parsed. This commit adds missing-value validation, so this case should also raise an IllegalArgumentException instead of silently swallowing the next option.

Useful? React with 👍 / 👎.

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