From 73c1281900a0fae0d28e523a2ab736fe9d1da6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Tue, 15 Jun 2021 11:49:23 +0200 Subject: [PATCH 1/2] Specify base 10 to the strtol() call converting the device number The USB device number given as argument to the '-d' option is parsed with a strtol() call with 0 base. This is an issue with USB device numbers that start with a 0 (and they do tend to start with a 0, e.g. from lsusb output: "Bus 001 Device 014"), because strtol() with 0 base interprets them as an octal number. Consequently, the program might not find the device, or, worse, might find and operate on the wrong device. Fix this by explicitly specifying base 10 to the strtol() call converting the device number. All other strtol() calls already explicitly specify a 10 or 16 base. --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index d7598fc..f6341a5 100644 --- a/src/main.c +++ b/src/main.c @@ -351,7 +351,7 @@ int main (int argc, char *argv[]) fprintf (stderr, "error: bad format to -d option, expected n.n\n"); return 10; } - want_dev = strtol (++p, NULL, 0); + want_dev = strtol (++p, NULL, 10); break; } case 'm': From 2ddb96a71dcb103d6c3244b67c5bc729c36ef15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Tue, 15 Jun 2021 12:03:45 +0200 Subject: [PATCH 2/2] Fix bus.dev syntax in documentation For the '-d' option the code expects the bus and device numbers in the format "bus.dev", i.e. separated by a dot, but the documentation and help text mention "bus:dev", i.e. separated by a colon. Update all documentation and help text to match the code. --- README.md | 4 ++-- src/main.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bf3e254..8ca41e8 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,12 @@ Consider yourself forewarned, and forearmed. $ ./cp210x-cfg -h Syntax: cp210x-cfg [-h ] | - [-m vid:pid] [-d bus:dev] + [-m vid:pid] [-d bus.dev] [ -l | [-V vid] [-P pid] [-F flush] [-M mode] [-N name] [-S serial]] -h This help -m vid:pid Find and use first device with vid:pid - -d bus:dev Find and use device at bus:dev + -d bus.dev Find and use device at bus.dev -l List all CP210x devices connected -V vid Program the given Vendor ID -P pid Program the given Product ID diff --git a/src/main.c b/src/main.c index f6341a5..18f203c 100644 --- a/src/main.c +++ b/src/main.c @@ -283,12 +283,12 @@ void syntax (void) fprintf (stderr, "Syntax:\n" "cp210x-cfg [-h ] |\n" -" [-m vid:pid] [-d bus:dev]\n" +" [-m vid:pid] [-d bus.dev]\n" " [ -l | [-V vid] [-P pid] [-F flush] [-M mode] [-N name] [-S serial]]\n" "\n" " -h This help\n" " -m vid:pid Find and use first device with vid:pid\n" -" -d bus:dev Find and use device at bus:dev\n" +" -d bus.dev Find and use device at bus.dev\n" " -l List all CP210x devices connected\n" " -V vid Program the given Vendor ID\n" " -P pid Program the given Product ID\n"