~sircmpwn/gmni-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH gmni] all: use posix_dirname rather than dirname

Details
Message ID
<20210316040727.23212-1-ecs@d2evs.net>
DKIM signature
pass
Download raw message
Patch: +10 -22
---
 src/gmnlm.c | 19 ++++++-------------
 src/tofu.c  | 13 ++++---------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c
index 1379959..c59e68c 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -162,18 +162,15 @@ save_bookmark(struct browser *browser)
	size_t n;

	n = snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
	free(path_fmt);
	assert(n < sizeof(path));
	strncpy(dname, dirname(path), sizeof(dname)-1);
	posix_dirname(path, 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",
				dirname(path), strerror(errno));
				dname, strerror(errno));
		return;
	}

	snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
	free(path_fmt);
	FILE *f = fopen(path, "a");
	if (!f) {
		fprintf(stderr, "Error opening %s for writing: %s\n",
@@ -203,19 +200,15 @@ open_bookmarks(struct browser *browser)
	size_t n;

	n = snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
	free(path_fmt);
	assert(n < sizeof(path));
	strncpy(dname, dirname(path), sizeof(dname)-1);
	posix_dirname(path, 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",
				dirname(path), strerror(errno));
				dname, strerror(errno));
		return;
	}

	snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
	free(path_fmt);

	struct stat buf;
	if (stat(path, &buf) == -1 && errno == ENOENT) {
		// TOCTOU, but we almost certainly don't care
diff --git a/src/tofu.c b/src/tofu.c
index 54183a7..0923aed 100644
--- a/src/tofu.c
+++ b/src/tofu.c
@@ -177,21 +177,16 @@ gemini_tofu_init(struct gemini_tofu *tofu, tofu_callback_t *cb, void *cb_data)
	n = snprintf(tofu->known_hosts_path,
		sizeof(tofu->known_hosts_path),
		path_fmt, "known_hosts");
	free(path_fmt);
	assert(n < sizeof(tofu->known_hosts_path));

	strncpy(dname, dirname(tofu->known_hosts_path), sizeof(dname)-1);
	posix_dirname(tofu->known_hosts_path, 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",
				dirname(tofu->known_hosts_path), strerror(errno));
		fprintf(stderr, "Error creating directory %s: %s\n", dname,
			strerror(errno));
		return;
	}

	snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path),
			path_fmt, "known_hosts");
	free(path_fmt);

	tofu->callback = cb;
	tofu->cb_data = cb_data;

-- 
2.30.2
Details
Message ID
<C9YSAJ2O3D1A.2E9M8049O8IXQ@taiga>
In-Reply-To
<20210316040727.23212-1-ecs@d2evs.net> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Thanks!

To git@git.sr.ht:~sircmpwn/gmni
   77b73ef..93f3052  master -> master
Reply to thread Export thread (mbox)