]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
shared: use size_t for strbuf
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 4 Sep 2024 16:17:50 +0000 (18:17 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 6 Sep 2024 16:40:22 +0000 (11:40 -0500)
The unsigned datatype could overflow on 64 bit systems with sufficiently
large index files. Switch to size_t just to be safe.

Since the API of strbuf is not exported, this has no side-effect for
libkmod users.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/101
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c
shared/strbuf.c
shared/strbuf.h

index 5fd61379e4521f8e8e2759b86ff1bc2efc3e298a..9c17c18174a89ee4a658b3c5d899e238e0b26c0c 100644 (file)
@@ -352,7 +352,8 @@ static void index_dump_node(struct index_node_f *node, struct strbuf *buf,
                                                                int fd)
 {
        struct index_value *v;
-       int ch, pushed;
+       size_t pushed;
+       int ch;
 
        pushed = strbuf_pushchars(buf, node->prefix);
 
@@ -472,7 +473,7 @@ static void index_searchwild__all(struct index_node_f *node, int j,
                                  const char *subkey,
                                  struct index_value **out)
 {
-       int pushed = 0;
+       size_t pushed = 0;
        int ch;
 
        while (node->prefix[j]) {
@@ -831,7 +832,8 @@ static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf,
                                                                int fd)
 {
        struct index_mm_value *itr, *itr_end;
-       int ch, pushed;
+       size_t pushed;
+       int ch;
 
        pushed = strbuf_pushchars(buf, node->prefix);
 
@@ -954,7 +956,7 @@ static void index_mm_searchwild_all(struct index_mm_node *node, int j,
                                          const char *subkey,
                                          struct index_value **out)
 {
-       int pushed = 0;
+       size_t pushed = 0;
        int ch;
 
        while (node->prefix[j]) {
index 0b6316668fad891164fbe6471d3a0253d10bd7e5..b032f40f67069412c7929df441e1d339eb943200 100644 (file)
@@ -77,9 +77,9 @@ bool strbuf_pushchar(struct strbuf *buf, char ch)
        return true;
 }
 
-unsigned strbuf_pushchars(struct strbuf *buf, const char *str)
+size_t strbuf_pushchars(struct strbuf *buf, const char *str)
 {
-       unsigned int len;
+       size_t len;
 
        assert(str != NULL);
        assert(buf != NULL);
@@ -101,7 +101,7 @@ void strbuf_popchar(struct strbuf *buf)
        buf->used--;
 }
 
-void strbuf_popchars(struct strbuf *buf, unsigned n)
+void strbuf_popchars(struct strbuf *buf, size_t n)
 {
        assert(buf->used >= n);
        buf->used -= n;
index 0f7ceb168ab4085c8b529553e0466101b3f0dc4d..946896fbad48ad822121459b3115516be34625b4 100644 (file)
@@ -7,8 +7,8 @@
  */
 struct strbuf {
        char *bytes;
-       unsigned size;
-       unsigned used;
+       size_t size;
+       size_t used;
 };
 
 void strbuf_init(struct strbuf *buf);
@@ -25,6 +25,6 @@ char *strbuf_steal(struct strbuf *buf);
 const char *strbuf_str(struct strbuf *buf);
 
 bool strbuf_pushchar(struct strbuf *buf, char ch);
-unsigned strbuf_pushchars(struct strbuf *buf, const char *str);
+size_t strbuf_pushchars(struct strbuf *buf, const char *str);
 void strbuf_popchar(struct strbuf *buf);
-void strbuf_popchars(struct strbuf *buf, unsigned n);
+void strbuf_popchars(struct strbuf *buf, size_t n);