summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHauke Mehrtens2026-04-13 08:29:14 +0000
committerHauke Mehrtens2026-06-03 23:19:20 +0000
commit7af2dd81cd537a7d8996c8ead65a0759e955d4b8 (patch)
treeab4d46e3e020dfe3de5c0d2c6b26c9a7e9d6ae1b
parentab6549a99c7cc96eb4639aabe7066b898d9c1407 (diff)
downloadrpcd-7af2dd81cd537a7d8996c8ead65a0759e955d4b8.tar.gz
main: prevent integer overflow when parsing -t timeout argument
The expression `1000 * strtol(optarg, NULL, 0)` multiplies into an int before the range check at line 91 runs. A value such as 3000000 overflows int32 and produces a small positive number that passes the subsequent validity check, resulting in a silently wrong timeout. Validate the raw seconds value (1–600) before scaling to milliseconds so the multiplication is provably within int range. Assisted-by: Claude:claude-sonnet-4-6 Link: https://github.com/openwrt/rpcd/pull/34 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--main.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main.c b/main.c
index d77a814..824ab4a 100644
--- a/main.c
+++ b/main.c
@@ -79,9 +79,11 @@ int main(int argc, char **argv)
ubus_socket = optarg;
break;
- case 't':
- rpc_exec_timeout = 1000 * strtol(optarg, NULL, 0);
+ case 't': {
+ long t = strtol(optarg, NULL, 0);
+ rpc_exec_timeout = (t > 0 && t <= 600) ? (int)(t * 1000) : -1;
break;
+ }
default:
break;