aboutsummaryrefslogtreecommitdiffstats
path: root/create.c
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2022-05-21 23:44:49 -0400
committerCameron Katri <me@cameronkatri.com>2022-05-21 23:44:49 -0400
commit2288b178e612386e7a75471c8861c3f6d81c300d (patch)
tree18209f47e0bc635000f7bf86b83f43a9ab0aa3ea /create.c
parentaa035f73ce081b3f07247bd15860d72355a096b2 (diff)
downloadtrustcache-2288b178e612386e7a75471c8861c3f6d81c300d.tar.gz
trustcache-2288b178e612386e7a75471c8861c3f6d81c300d.tar.zst
trustcache-2288b178e612386e7a75471c8861c3f6d81c300d.zip
Add tc remove and append -f flags
Also fix some conflicting types to hopefully prevent possible overflows.
Diffstat (limited to 'create.c')
-rw-r--r--create.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/create.c b/create.c
index a19d7f3..955c833 100644
--- a/create.c
+++ b/create.c
@@ -71,9 +71,8 @@ tccreate(int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc == 0) {
+ if (argc == 0)
return -1;
- }
for (int i = 1; i < argc; i++) {
append = cache_from_tree(argv[i], cache.version);
@@ -81,14 +80,14 @@ tccreate(int argc, char **argv)
if ((cache.hashes = realloc(cache.hashes, sizeof(trust_cache_hash0) *
(cache.num_entries + append.num_entries))) == NULL)
exit(1);
- for (int j = 0; j < append.num_entries; j++) {
+ for (uint32_t j = 0; j < append.num_entries; j++) {
memcpy(cache.hashes[cache.num_entries + j], append.hashes[j], CS_CDHASH_LEN);
}
} else if (append.version == 1) {
if ((cache.entries = realloc(cache.entries, sizeof(struct trust_cache_entry1) *
(cache.num_entries + append.num_entries))) == NULL)
exit(1);
- for (int j = 0; j < append.num_entries; j++) {
+ for (uint32_t j = 0; j < append.num_entries; j++) {
cache.entries[cache.num_entries + j].hash_type = append.entries[j].hash_type;
cache.entries[cache.num_entries + j].flags = append.entries[j].flags;
memcpy(cache.entries[cache.num_entries + j].cdhash, append.entries[j].cdhash, CS_CDHASH_LEN);
@@ -115,7 +114,7 @@ tccreate(int argc, char **argv)
cache.version = le32toh(cache.version);
cache.num_entries = le32toh(cache.num_entries);
- for (int i = 0; i < cache.num_entries; i++) {
+ for (uint32_t i = 0; i < cache.num_entries; i++) {
if (cache.version == 1)
fwrite(&cache.entries[i], sizeof(struct trust_cache_entry1), 1, f);
else if (cache.version == 0)