[OpenWrt-Devel] [PATCH, v2] procd sysupgrade: close input side of pipe before reading

Dustin Lundquist D.Lundquist at temperednetworks.com
Mon Oct 28 12:52:06 EDT 2019



> On Oct 27, 2019, at 6:44 AM, Rafał Miłecki <zajec5 at gmail.com> wrote:
> 
> You also need to drop close(fds[1]); that is placed inside the "if
> (!tok)" block.


When /usr/libexec/validate_firmware_image is not present on the system
procd will hang indefinitely on the read() since the input side of the
pipe is still open.

Also fix pipe file descriptor leak when fork() fails.

Signed-off-by: Dustin Lundquist <d.lundquist at temperednetworks.com>
---
system.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/system.c b/system.c
index 751a016..98d9f8c 100644
--- a/system.c
+++ b/system.c
@@ -405,6 +405,8 @@ static int validate_firmware_image_call(const char *file)

	switch (fork()) {
	case -1:
+		close(fds[0]);
+		close(fds[1]);
		return -errno;
	case 0:
		/* Set stdin & stderr to /dev/null */
@@ -425,11 +427,11 @@ static int validate_firmware_image_call(const char *file)
	}

	/* Parent process */
+	close(fds[1]);

	tok = json_tokener_new();
	if (!tok) {
		close(fds[0]);
-		close(fds[1]);
		return -ENOMEM;
	}

@@ -447,7 +449,6 @@ static int validate_firmware_image_call(const char *file)
	}

	close(fds[0]);
-	close(fds[1]);

	err = -ENOENT;
	if (jsobj) {
--
2.20.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list