dag

Djmoch's Auto Generator
git clone git://git.danielmoch.com/dag.git
Log | Files | Refs | README | LICENSE

commit a6a94c246b19a4197ce13e42bda86d64a049b7fe
parent a8bf54222273137d8e2dda2245495cd12f5849e8
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat, 13 Nov 2021 10:58:05 -0500

pledge and unveil

Diffstat:
Mdag.c | 9+++++++--
Mdagindex.c | 9++++++++-
Mdb.c | 10+++++-----
3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/dag.c b/dag.c @@ -1,4 +1,6 @@ /* See LICENSE file for copyright and license details */ +#include <err.h> +#include <errno.h> #include <libgen.h> #include <stdio.h> #include <stdlib.h> @@ -72,6 +74,11 @@ main(int argc, char **argv) fprintf(stderr, "%s: expected no arguments\n", argv0); usage(ERR_ARGS); } +#ifdef __OpenBSD__ + if (pledge("stdio cpath rpath wpath proc exec", NULL)) { + err(errno, "pledge failed"); + } +#endif if ((df = fopen(path, "r")) == NULL) { fprintf(stderr, "%s: error opening %s\n", argv0, path); exit(ERR_FILE); @@ -85,8 +92,6 @@ main(int argc, char **argv) debug_dagfile(dagfile); } - /* TODO - pledge and unveil */ - retval = process_dagfile(dagfile); free_dagfile(dagfile); diff --git a/dagindex.c b/dagindex.c @@ -224,7 +224,14 @@ main(int argc, char **argv) usage(ERR_ARGS); } - /* TODO: pledge and unveil */ +#ifdef __OpenBSD__ + if (unveil("index.db", "rwc")) { + err(errno, "unveil failed"); + } + if (pledge("stdio rpath wpath cpath", "")) { + err(errno, "pledge failed"); + } +#endif if (verbose >= 2) { fputs("DEBUG: received options:\n", stderr); diff --git a/db.c b/db.c @@ -21,7 +21,7 @@ static int entrycmp(struct db_entry *e1, struct db_entry *e2); struct db_index * db_index_open(const char *db_path) { - char *dir, path[strlen(db_path + 1)]; + char path[strlen(db_path + 1)]; struct stat sb; struct db_index *index; struct db_entry *cur_entry = NULL, *next_entry = NULL; @@ -32,7 +32,6 @@ db_index_open(const char *db_path) } strcpy(path, db_path); - dir = dirname(path); index->db_path = db_path; index->entries = NULL; @@ -42,9 +41,6 @@ db_index_open(const char *db_path) return index; } - if (stat(dir, &sb)) { - err(errno, "failed to stat parent directory %s", dir); - } if (stat(db_path, &sb)) { warnx("creating new db file: %s", db_path); index->db_path = db_path; @@ -52,6 +48,10 @@ db_index_open(const char *db_path) goto exit; } + if (sb.st_mode | S_IFDIR) { + errx("%s is a directory", db_path); + } + if ((cur_entry = getentry(fp)) == NULL) { warnx("empty db file: %s", db_path); goto exit;