c.koehne@beckhoff.com has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/80249?usp=email )
Change subject: em100: exit when using an invalid device name ......................................................................
em100: exit when using an invalid device name
If you use a stupid device name like `em100 --device bla`, we won't exit with an error right now. It just ignores the devices and uses the first device it can find. This could lead to unexpected issues when connecting more than one EM100 device to your machine. It's much better to exit if we're unable to parse the device name.
Change-Id: If0f7b8b576224a9db6ab319c2212bc245110c5c1 Signed-off-by: Corvin Köhne c.koehne@beckhoff.com --- M em100.c 1 file changed, 11 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/49/80249/1
diff --git a/em100.c b/em100.c index cfcecb9..666cef9 100644 --- a/em100.c +++ b/em100.c @@ -930,10 +930,17 @@ break; case 'x': if ((toupper(optarg[0]) == 'D' && toupper(optarg[1]) == 'P') || - (toupper(optarg[0]) == 'E' && toupper(optarg[1]) == 'M')) - sscanf(optarg + 2, "%u", &serial_number); - else - sscanf(optarg, "%d:%d", &bus, &device); + (toupper(optarg[0]) == 'E' && toupper(optarg[1]) == 'M')) { + if (sscanf(optarg + 2, "%u", &serial_number) != 1) { + printf("Invalid device name: %s\n", optarg); + return 1; + } + } else { + if (sscanf(optarg, "%d:%d", &bus, &device) != 2) { + printf("Invalid device name: %s\n", optarg); + return 1; + } + } break; case 'l': em100_list();