aboutsummaryrefslogtreecommitdiff
path: root/src/Cache/Cache.c
diff options
context:
space:
mode:
authorfrosty <frostinator33@airmail.cc>2026-10-27 20:31:28 -0400
committerfrosty <frostinator33@airmail.cc>2026-10-27 20:33:50 -0400
commit250898c638f07ace6bc7167faede93113c8fd0db (patch)
tree310addbedcaaf76da98df22434a4f4711c8ba963 /src/Cache/Cache.c
parentbd3da2232540ea4c78e7ac35e2c90c38c8a3c410 (diff)
refactor: replace potentially unsafe string functions with snprintf
Diffstat (limited to 'src/Cache/Cache.c')
-rw-r--r--src/Cache/Cache.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/Cache/Cache.c b/src/Cache/Cache.c
index 22f2553..bf71974 100644
--- a/src/Cache/Cache.c
+++ b/src/Cache/Cache.c
@@ -36,7 +36,7 @@ static void md5_hash(const char *str, char *output) {
EVP_DigestFinal_ex(ctx, hash, &hash_len);
EVP_MD_CTX_free(ctx);
for (unsigned int i = 0; i < hash_len; i++) {
- sprintf(output + (i * 2), "%02x", hash[i]);
+ snprintf(output + (i * 2), 3, "%02x", hash[i]);
}
}
@@ -50,11 +50,9 @@ static time_t get_file_mtime(const char *filepath) {
int cache_init(const char *dir) {
if (!dir || strlen(dir) == 0) {
- strncpy(cache_dir, DEFAULT_CACHE_DIR, sizeof(cache_dir) - 1);
- cache_dir[sizeof(cache_dir) - 1] = '\0';
+ snprintf(cache_dir, sizeof(cache_dir), "%s", DEFAULT_CACHE_DIR);
} else {
- strncpy(cache_dir, dir, sizeof(cache_dir) - 1);
- cache_dir[sizeof(cache_dir) - 1] = '\0';
+ snprintf(cache_dir, sizeof(cache_dir), "%s", dir);
}
struct stat st;