Commit b48e2ddb7c7f3bec51c4be31a1484677022384e8

Stefan Sperling 2019-05-22T12:31:30

set datasize limit of got-read-pack helpers to maximum

diff --git a/lib/object.c b/lib/object.c
index d781faa..f2cc6ae 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -21,6 +21,7 @@
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/syslimits.h>
+#include <sys/resource.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -228,6 +229,18 @@ request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
 	return NULL;
 }
 
+void
+set_max_datasize(void)
+{
+	struct rlimit rl;
+
+	if (getrlimit(RLIMIT_DATA, &rl) != 0)
+		return;
+
+	rl.rlim_cur = rl.rlim_max;
+	setrlimit(RLIMIT_DATA, &rl);
+}
+
 static const struct got_error *
 start_pack_privsep_child(struct got_pack *pack, struct got_packidx *packidx)
 {
@@ -257,6 +270,7 @@ start_pack_privsep_child(struct got_pack *pack, struct got_packidx *packidx)
 		err = got_error_from_errno("fork");
 		goto done;
 	} else if (pid == 0) {
+		set_max_datasize();
 		exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_PACK,
 		    pack->path_packfile);
 		/* not reached */