]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: store index value lengths as size_t
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 24 Sep 2024 18:55:20 +0000 (20:55 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 1 Oct 2024 14:23:31 +0000 (09:23 -0500)
The unsigned int data type might be too small on 64 bit systems and
when encountering huge and illegal index files.

Since lengths are retrieved from strbuf structs, this also keeps
the data type lengths in sync.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/152
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c
libkmod/libkmod-index.h

index 154cc43b77fce42987ad978ae73b06ef538a7436..1c730ea4d2be435db7724e84e70b42a302b78205 100644 (file)
@@ -145,7 +145,7 @@ void index_values_free(struct index_value *values)
        }
 }
 
-static int add_value(struct index_value **values, const char *value, unsigned len,
+static int add_value(struct index_value **values, const char *value, size_t len,
                     unsigned int priority)
 {
        struct index_value *v;
@@ -619,13 +619,13 @@ struct index_mm {
 
 struct index_mm_value {
        unsigned int priority;
-       unsigned int len;
+       size_t len;
        const char *value;
 };
 
 struct index_mm_value_array {
        struct index_mm_value *values;
-       unsigned int len;
+       size_t len;
 };
 
 struct index_mm_node {
@@ -657,7 +657,7 @@ static inline uint8_t read_char_mm(void **p)
        return v;
 }
 
-static inline char *read_chars_mm(void **p, unsigned *rlen)
+static inline char *read_chars_mm(void **p, size_t *rlen)
 {
        char *addr = *(char **)p;
        size_t len = *rlen = strlen(addr);
@@ -680,7 +680,7 @@ static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t o
        p = (char *)p + (offset & INDEX_NODE_MASK);
 
        if (offset & INDEX_NODE_PREFIX) {
-               unsigned len;
+               size_t len;
                prefix = read_chars_mm(&p, &len);
        } else
                prefix = _idx_empty_str;
index 5f0657eb19c62380526d51932b4317390a2af54a..b33a7bbf33c81a1d6e15b008d9fb71144fe1b9db 100644 (file)
@@ -10,7 +10,7 @@
 struct index_value {
        struct index_value *next;
        unsigned int priority;
-       unsigned int len;
+       size_t len;
        char value[0];
 };