]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sun, 5 Dec 2021 20:33:10 +0000 (12:33 -0800)
committeralex <[email protected]>
Sun, 5 Dec 2021 20:33:10 +0000 (12:33 -0800)
src/bencode/encode.c
test/unit/Makefile.am

index 727e6086825bc6be3fdaf76ac9454bd62b6d4bd4..536532a5df4cfee2f832f70d8df22dbe8dcd715d 100644 (file)
@@ -60,12 +60,15 @@ ssize_t bencode_string(const uint8_t *str, size_t len, uint8_t *output, size_t o
        if(NULL==output) { return -1; }
 
        i = size_int(len);
-       i += 2; // account for ':' and '\0'
-       i += len;
+       i++; // account for ':'
+       if(i+len>output_size) { return -1; }
 
-       if(i>output_size) { return -1; }
+       // snprintf requires space for '\0' otherwise will truncate
+       if(snprintf((char*)output,i+1,"%lu:",len)!=i) { return -1; }
 
-       return snprintf((char*)output,i,"%lu:%s",len,(const char*)str);
+       memcpy(&(output[i]),str,len);
+
+       return i+len;
 }
 
 
index c8e471e0b77e2565172c682813270e48bd77207a..62c5b31c0ed6e514f381cd00f867057422568c73 100644 (file)
@@ -71,7 +71,9 @@ torrent_tests_SOURCES = \
        $(top_srcdir)/src/fs/concat.c \
        $(top_srcdir)/src/hash.c \
        $(top_srcdir)/src/hashmap.c \
-       $(top_srcdir)/src/torrent.c \
+       $(top_srcdir)/src/torrent/add.c \
+       $(top_srcdir)/src/torrent/init.c \
+       $(top_srcdir)/src/torrent/free.c \
        $(top_srcdir)/src/tree.c
 
 tree_tests_SOURCES = \