Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Null terminate string read.
Vsevolod Stakhov committed 12 years ago
commit 576c513a4b1d3c3a2f97a2a87b75c5b5d1517d00
parent 889f6eb
1 file changed +7 -3
modified src/event.c
@@ -135,7 +135,7 @@ event_sandboxed_get_string(pkg_sandbox_cb func, char **result, int64_t *len,
{
	pid_t pid;
	int	status, ret = EPKG_OK;
-
	int pair[2];
+
	int pair[2], r;
	int64_t res_len = 0;

	if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
@@ -164,18 +164,22 @@ event_sandboxed_get_string(pkg_sandbox_cb func, char **result, int64_t *len,
		else {
			/* Fill the result buffer */
			*len = res_len;
-
			*result = malloc(res_len);
+
			*result = malloc(res_len + 1);
			if (*result == NULL) {
				warn("malloc failed");
				kill(pid, SIGTERM);
				ret = EPKG_FATAL;
			}
			else {
-
				if (read(pair[1], *result, res_len) == -1) {
+
				if ((r = read(pair[1], *result, res_len)) == -1) {
					ret = EPKG_FATAL;
					free(*result);
					kill(pid, SIGTERM);
				}
+
				else {
+
					/* Null terminate string */
+
					*result[r] = '\0';
+
				}
			}
		}
		/* Parent process */