Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
fix external merge tool: ensure the buffer is null terminated
Baptiste Daroussin committed 2 months ago
commit 002313bdcea3f0f364b46807b4e2e7b44cd071ad
parent 66175bb
1 file changed +3 -1
modified libpkg/pkg_add.c
@@ -116,7 +116,8 @@ merge_with_external_tool(const char *merge_tool, struct pkg_config_file *lcf,
	}

	char command[MAXPATHLEN];
-
	for (int i = 0; *merge_tool != '\0'; i++, merge_tool++) {
+
	int i = 0;
+
	for (; *merge_tool != '\0' && i < (int)sizeof(command) - 1; i++, merge_tool++) {
		if (*merge_tool != '%') {
			command[i] = *merge_tool;
			continue;
@@ -146,6 +147,7 @@ merge_with_external_tool(const char *merge_tool, struct pkg_config_file *lcf,
		}
		i += strlcpy(&command[i], tmp_files[tmp_files_index].path, sizeof(command) - i) - 1;
	}
+
	command[i] = '\0';

	pid_t pid = process_spawn_pipe(inout, command);
	wait_res = waitpid(pid, &status, 0);