]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
shared: use proper data types in freadline_wrapped
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 20 Aug 2024 20:52:41 +0000 (22:52 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 22 Aug 2024 21:43:30 +0000 (16:43 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/81
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/util.c

index 66a76226368529d5ffb4edc5c8e89b081a3bc50e..d7db5d4f2f35b1a5849eed286d903c3a6c847131 100644 (file)
@@ -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)