Commit 6bee13de786cb52a98bb33a4a1cef191a240f962

Tracey Emery 2020-01-16T11:16:31

move pledge to gw functions to more tightly control promises

diff --git a/gotweb/TODO b/gotweb/TODO
index 969f659..061d498 100644
--- a/gotweb/TODO
+++ b/gotweb/TODO
@@ -11,5 +11,3 @@ TODO
 
 - Redo index header, so columns are removed when content is set to not display
   in gotweb.conf.
-
-- Move pledge to each function. Only diffing needs wpath and cpath.
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index daa235b..17c61bd 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -267,6 +267,12 @@ gw_blame(struct gw_trans *gw_trans)
 
 	char *log, *log_html;
 
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -289,6 +295,12 @@ gw_commit(struct gw_trans *gw_trans)
 	const struct got_error *error = NULL;
 	char *log, *log_html;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -311,6 +323,12 @@ gw_commitdiff(struct gw_trans *gw_trans)
 	const struct got_error *error = NULL;
 	char *log, *log_html;
 
+	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -335,6 +353,12 @@ gw_index(struct gw_trans *gw_trans)
 	char *html, *navs, *next, *prev;
 	unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_conf->got_repos_path, NULL);
 	if (error)
 		return error;
@@ -425,6 +449,12 @@ gw_log(struct gw_trans *gw_trans)
 	const struct got_error *error = NULL;
 	char *log, *log_html;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -456,6 +486,12 @@ gw_logbriefs(struct gw_trans *gw_trans)
 	const struct got_error *error = NULL;
 	char *log, *log_html;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -482,6 +518,12 @@ gw_summary(struct gw_trans *gw_trans)
 	     *cloneurl_html, *log, *log_html, *tags, *heads, *tags_html,
 	     *heads_html, *age;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -576,6 +618,12 @@ gw_tag(struct gw_trans *gw_trans)
 	const struct got_error *error = NULL;
 	char *log, *log_html;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -598,6 +646,12 @@ gw_tree(struct gw_trans *gw_trans)
 	const struct got_error *error = NULL;
 	char *log, *log_html;
 
+	if (pledge("stdio rpath proc exec sendfd unveil",
+	    NULL) == -1) {
+		error = got_error_from_errno("pledge");
+		return error;
+	}
+
 	error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
 	if (error)
 		return error;
@@ -2654,12 +2708,6 @@ main(int argc, char *argv[])
 		goto err;
 	}
 
-	if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
-	    NULL) == -1) {
-		error = got_error_from_errno("pledge");
-		goto err;
-	}
-
 	TAILQ_INIT(&gw_trans->gw_dirs);
 
 	gw_trans->page = 0;