From 8918b1457091157972efd5a5a49f1609440ed163 Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Wed, 5 Aug 2026 15:55:29 +0200 Subject: [PATCH 1/4] recipes-devtools/rs485test: increase max length of device filename When using the tool with e.g. /dev/serial/by-id/... pathnames, then the limit of 64 byte might be too less space. Increase it by using the pre-defined PATH_MAX define. Signed-off-by: Michael Heimpold --- recipes-devtools/rs485test/rs485test-0.2/rs485test.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c index 3e4356199..de66208ae 100644 --- a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c +++ b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c @@ -9,6 +9,7 @@ #include #include //for C11 compliance #include +#include #include #include #include @@ -180,11 +181,11 @@ void print_help() int main(int argc, char *argv[]) { - char dev[64]; + char dev[PATH_MAX]; int master = 0; int setrs485half = 0; int setrs485full = 0; - int hasdev = 0; + int hasdev = 0; int singleshoot = 0; struct serial_rs485 rs485ctrl = {0}; @@ -196,7 +197,10 @@ int main(int argc, char *argv[]) while ((c = getopt (argc, argv, "vsfmd:l:")) != -1) switch (c) { case 'd': - snprintf(dev, sizeof(dev), "%s",optarg); + if (snprintf(dev, sizeof(dev), "%s", optarg) >= (int)sizeof(dev)) { + printf("Device path too long: %s\n", optarg); + return -1; + } hasdev = 1; break; case 's': From 597a6d94b029cbf52ace43dd608775c73dae07d4 Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Wed, 5 Aug 2026 16:19:42 +0200 Subject: [PATCH 2/4] recipes-devtools/rs485test: validate singleshot length argument Using the unchecked value can lead to out-of-bound access. Signed-off-by: Michael Heimpold --- .../rs485test/rs485test-0.2/rs485test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c index de66208ae..33f233211 100644 --- a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c +++ b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c @@ -182,6 +182,7 @@ void print_help() int main(int argc, char *argv[]) { char dev[PATH_MAX]; + char *endp; int master = 0; int setrs485half = 0; int setrs485full = 0; @@ -216,9 +217,21 @@ int main(int argc, char *argv[]) master = 1; break; case 'l': - singleshoot = atoi(optarg); + { + long parsed; + + errno = 0; + parsed = strtol(optarg, &endp, 10); + if (errno || endp == optarg || *endp != '\0' || + parsed < 1 || parsed > MAX_SEND) { + printf("Invalid length '%s'. Use a value between 1 and %d.\n", + optarg, MAX_SEND); + return -1; + } + singleshoot = (int)parsed; master = 1; break; + } default: print_help(); } From 7b699e79d2b3d84f381a54a2fad08f0d0d5eebec Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Wed, 5 Aug 2026 16:20:25 +0200 Subject: [PATCH 3/4] recipes-devtools/rs485test: check configuration calls If - for some reason - the calls fail, then exit immediately. Signed-off-by: Michael Heimpold --- .../rs485test/rs485test-0.2/rs485test.c | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c index 33f233211..842e61019 100644 --- a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c +++ b/recipes-devtools/rs485test/rs485test-0.2/rs485test.c @@ -284,7 +284,11 @@ int main(int argc, char *argv[]) } /* Set the port speed */ - tcgetattr(fd, &ti); + if (tcgetattr(fd, &ti)) { + perror("tcgetattr"); + ret = -1; + goto restore_settings; + } ti.c_iflag = 0; ti.c_oflag = 0; ti.c_cflag = CS8 | CREAD | CLOCAL; @@ -292,9 +296,21 @@ int main(int argc, char *argv[]) ti.c_cc[VTIME] = 1; ti.c_cc[VMIN] = MAX_RECEIVE; - cfsetospeed(&ti, speed); - cfsetispeed(&ti, speed); - tcsetattr(fd, TCSANOW, &ti); + if (cfsetospeed(&ti, speed)) { + perror("cfsetospeed"); + ret = -1; + goto restore_settings; + } + if (cfsetispeed(&ti, speed)) { + perror("cfsetispeed"); + ret = -1; + goto restore_settings; + } + if (tcsetattr(fd, TCSANOW, &ti)) { + perror("tcsetattr"); + ret = -1; + goto restore_settings; + } if (master) ret = send(fd, singleshoot); @@ -302,6 +318,7 @@ int main(int argc, char *argv[]) ret = receive(fd); +restore_settings: /* restore orginial rs485 settings if available */ if (!cant_save && !already_enabled) set_rs485_ioctl(fd, &rs485ctrl_orig); From f2ceb4b94030252291de01fbe4b44e7cec37762d Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Wed, 5 Aug 2026 15:50:46 +0200 Subject: [PATCH 4/4] recipes-devtools/rs485test: bump version to 0.3 Signed-off-by: Michael Heimpold --- .../rs485test/{rs485test-0.2 => rs485test-0.3}/LICENSE | 0 .../rs485test/{rs485test-0.2 => rs485test-0.3}/rs485test.c | 0 .../{rs485test-native_0.2.bb => rs485test-native_0.3.bb} | 2 +- .../rs485test/{rs485test_0.2.bb => rs485test_0.3.bb} | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename recipes-devtools/rs485test/{rs485test-0.2 => rs485test-0.3}/LICENSE (100%) rename recipes-devtools/rs485test/{rs485test-0.2 => rs485test-0.3}/rs485test.c (100%) rename recipes-devtools/rs485test/{rs485test-native_0.2.bb => rs485test-native_0.3.bb} (95%) rename recipes-devtools/rs485test/{rs485test_0.2.bb => rs485test_0.3.bb} (100%) diff --git a/recipes-devtools/rs485test/rs485test-0.2/LICENSE b/recipes-devtools/rs485test/rs485test-0.3/LICENSE similarity index 100% rename from recipes-devtools/rs485test/rs485test-0.2/LICENSE rename to recipes-devtools/rs485test/rs485test-0.3/LICENSE diff --git a/recipes-devtools/rs485test/rs485test-0.2/rs485test.c b/recipes-devtools/rs485test/rs485test-0.3/rs485test.c similarity index 100% rename from recipes-devtools/rs485test/rs485test-0.2/rs485test.c rename to recipes-devtools/rs485test/rs485test-0.3/rs485test.c diff --git a/recipes-devtools/rs485test/rs485test-native_0.2.bb b/recipes-devtools/rs485test/rs485test-native_0.3.bb similarity index 95% rename from recipes-devtools/rs485test/rs485test-native_0.2.bb rename to recipes-devtools/rs485test/rs485test-native_0.3.bb index e50a187f0..6531fac74 100644 --- a/recipes-devtools/rs485test/rs485test-native_0.2.bb +++ b/recipes-devtools/rs485test/rs485test-native_0.3.bb @@ -4,7 +4,7 @@ LICENSE = "MIT" LIC_FILES_CHKSUM = "file://LICENSE;md5=c748d81368c9a87fff9317b09edacfee" SECTION = "devel" -require rs485test_0.2.bb +require rs485test_0.3.bb inherit deploy native diff --git a/recipes-devtools/rs485test/rs485test_0.2.bb b/recipes-devtools/rs485test/rs485test_0.3.bb similarity index 100% rename from recipes-devtools/rs485test/rs485test_0.2.bb rename to recipes-devtools/rs485test/rs485test_0.3.bb