1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00

tools: fix an integer overflow bug in parse_period()

If p * m exceeds ULLONG_MAX, the result wraps modulo 2^64. The wrapped
value may be less than LLONG_MAX, passing the guard and returning
a completely wrong period value. Check the overflow before the
multiplication.

Fixes: 8ffb648928 ("tools: line name focussed rework")
Reported-by: 4fqr <4fqr@proton.me>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260407-treewide-fixes-v1-8-66c9744a56a3@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
This commit is contained in:
Bartosz Golaszewski
2026-04-07 14:49:59 +02:00
parent 39f6239848
commit 6702eed1a5

View File

@@ -151,9 +151,9 @@ long long parse_period(const char *option)
m = 1000;
}
p *= m;
if (*end != '\0' || p > LLONG_MAX)
if (m != 0 && p > ULLONG_MAX / m)
return -1;
p *= m;
return p;
}