diff --git a/src/gmnlm.c b/src/gmnlm.c
index 2eb906e1312a346fe2ad479fa5f49b1d155927b8..9f76188252a30e95868b99d64d57369ac03a7e1c 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -154,8 +154,13 @@ save_bookmark(struct browser *browser)
{
char *path_fmt = get_data_pathfmt();
static char path[PATH_MAX+1];
- snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
- if (mkdirs(dirname(path), 0755) != 0) {
+ static char dname[PATH_MAX+1];
+ size_t n;
+
+ n = snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
+ assert(n < sizeof(path));
+ strncpy(dname, dirname(path), sizeof(dname));
+ if (mkdirs(dname, 0755) != 0) {
snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
free(path_fmt);
fprintf(stderr, "Error creating directory %s: %s\n",
@@ -190,8 +195,13 @@ open_bookmarks(struct browser *browser)
{
char *path_fmt = get_data_pathfmt();
static char path[PATH_MAX+1];
- snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
- if (mkdirs(dirname(path), 0755) != 0) {
+ static char dname[PATH_MAX+1];
+ size_t n;
+
+ n = snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
+ assert(n < sizeof(path));
+ strncpy(dname, dirname(path), sizeof(dname));
+ if (mkdirs(dname, 0755) != 0) {
snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
free(path_fmt);
fprintf(stderr, "Error creating directory %s: %s\n",
diff --git a/src/tofu.c b/src/tofu.c
index 863efc644a691370ee58ef0fb92291e9471adeb9..16548a1cbcebc8c4cdda4a57a4655a04e7f390a3 100644
--- a/src/tofu.c
+++ b/src/tofu.c
@@ -157,10 +157,15 @@ {.var = "XDG_DATA_HOME", .path = "/gemini/%s"},
{.var = "HOME", .path = "/.local/share/gemini/%s"}
};
char *path_fmt = getpath(paths, sizeof(paths) / sizeof(paths[0]));
- snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path),
+ char dname[PATH_MAX+1];
+ size_t n = 0;
+
+ n = snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path),
path_fmt, "known_hosts");
+ assert(n < sizeof(tofu->known_hosts_path));
- if (mkdirs(dirname(tofu->known_hosts_path), 0755) != 0) {
+ strncpy(dname, dirname(tofu->known_hosts_path), sizeof(dname));
+ if (mkdirs(dname, 0755) != 0) {
snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path),
path_fmt, "known_hosts");
fprintf(stderr, "Error creating directory %s: %s\n",
@@ -182,7 +187,7 @@ FILE *f = fopen(tofu->known_hosts_path, "r");
if (!f) {
return;
}
- size_t n = 0;
+ n = 0;
char *line = NULL;
while (getline(&line, &n, f) != -1) {
struct known_host *host = calloc(1, sizeof(struct known_host));