From 84eff55d4d68b3705a86ff184aab558dfd3ce804 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 20 Aug 2024 22:52:41 +0200 Subject: [PATCH] shared: use proper data types in freadline_wrapped Do not use signed data types if unsigned arithmetic is expected, i.e. use size_t if processing sizes and unsigned int for line numbers due to given API of freadline_wrapped. This fixes a possible signed integer overflow on 64 bit systems. Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/81 Signed-off-by: Lucas De Marchi --- shared/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/util.c b/shared/util.c index 66a76226..d7db5d4f 100644 --- a/shared/util.c +++ b/shared/util.c @@ -285,8 +285,8 @@ int read_str_ulong(int fd, unsigned long *value, int base) */ char *freadline_wrapped(FILE *fp, unsigned int *linenum) { - int size = 256; - int i = 0, n = 0; + size_t i = 0, size = 256; + unsigned int n = 0; _cleanup_free_ char *buf = malloc(size); if (buf == NULL) -- 2.47.3