Stefan Reinauer has submitted this change. ( 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 Reviewed-on: https://review.coreboot.org/c/em100/+/80249 Reviewed-by: Jakub Czapiga czapiga@google.com Reviewed-by: Stefan Reinauer stefan.reinauer@coreboot.org Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M em100.c 1 file changed, 11 insertions(+), 4 deletions(-)
Approvals: Stefan Reinauer: Looks good to me, approved build bot (Jenkins): Verified Jakub Czapiga: Looks good to me, approved
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();