Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Always close stdin when running the script to prevent any interactive script to work during install/delete/upgrade phases
Baptiste Daroussin committed 7 years ago
commit 6167cb7567264b57bc3ee96806b184d399fe6192
parent dacee2b
1 file changed +8 -3
modified libpkg/scripts.c
@@ -139,13 +139,14 @@ pkg_script_run(struct pkg * const pkg, pkg_script type)
			argmax -= 1 + sizeof(*ep);

			pkg_debug(3, "Scripts: executing\n--- BEGIN ---\n%s\nScripts: --- END ---", utstring_body(script_cmd));
+
			posix_spawn_file_actions_init(&action);
			if (utstring_len(script_cmd) > argmax) {
				if (pipe(stdin_pipe) < 0) {
					ret = EPKG_FATAL;
+
					posix_spawn_file_actions_destroy(&action);
					goto cleanup;
				}

-
				posix_spawn_file_actions_init(&action);
				posix_spawn_file_actions_adddup2(&action, stdin_pipe[0],
				    STDIN_FILENO);
				posix_spawn_file_actions_addclose(&action, stdin_pipe[1]);
@@ -156,6 +157,9 @@ pkg_script_run(struct pkg * const pkg, pkg_script type)

				use_pipe = 1;
			} else {
+
				posix_spawn_file_actions_addclose(&action,
+
				    STDIN_FILENO);
+

				argv[0] = _PATH_BSHELL;
				argv[1] = "-c";
				argv[2] = utstring_body(script_cmd);
@@ -164,14 +168,15 @@ pkg_script_run(struct pkg * const pkg, pkg_script type)
				use_pipe = 0;
			}

-
			if ((error = posix_spawn(&pid, _PATH_BSHELL,
-
			    use_pipe ? &action : NULL,
+
			if ((error = posix_spawn(&pid, _PATH_BSHELL, &action,
			    NULL, __DECONST(char **, argv),
			    environ)) != 0) {
				errno = error;
				pkg_errno("Cannot runscript %s", map[i].arg);
+
				posix_spawn_file_actions_destroy(&action);
				goto cleanup;
			}
+
			posix_spawn_file_actions_destroy(&action);

			if (use_pipe) {
				script_cmd_p = utstring_body(script_cmd);