All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libselinux: avcstat: reject out-of-range interval values
@ 2026-10-08  7:27 Evgeniy Gorbanyov
  2026-10-08 14:58 ` Stephen Smalley
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeniy Gorbanyov @ 2026-10-08  7:27 UTC (permalink / raw)
  To: selinux; +Cc: Evgeniy Gorbanyov

strtoul() returns unsigned long, but avcstat stored the result in a
signed int and passed it to sleep(). A value above INT_MAX becomes
negative, and sleep() then treats it as a large unsigned duration.
Compare the full strtoul() result with INT_MAX before narrowing it.

Signed-off-by: Evgeniy Gorbanyov <esgor@altlinux.org>
---
 libselinux/utils/avcstat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
index 640a7a05..0c534f51 100644
--- a/libselinux/utils/avcstat.c
+++ b/libselinux/utils/avcstat.c
@@ -13,6 +13,7 @@
 #include <libgen.h>
 #include <stdarg.h>
 #include <errno.h>
+#include <limits.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -122,9 +123,9 @@ int main(int argc, char **argv)
 
 	if (optind < argc) {
 		char *arg = argv[optind];
-		unsigned int n = strtoul(arg, NULL, 10);
+		unsigned long n = strtoul(arg, NULL, 10);
 
-		if (errno == ERANGE) {
+		if (errno == ERANGE || n > INT_MAX) {
 			usage();
 			die("invalid interval \'%s\'", arg);
 		}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-09 12:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08  7:27 [PATCH] libselinux: avcstat: reject out-of-range interval values Evgeniy Gorbanyov
2026-10-08 14:58 ` Stephen Smalley
2026-10-09  5:57   ` [PATCH v2] " Evgeniy Gorbanyov
2026-10-09 12:29     ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.