Skip to content

Commit a0de781

Browse files
committed
cdba-server: sanitise file descriptors before device_close()
If we got to device_close(), the parent SSH might have been exited, making standard file descriptors unusable. Rebind them to /dev/null, so that any output during device_close (both from the cdba server and the helpers) doesn't cause SIGPIPE. Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent 310004b commit a0de781

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cdba-server.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ int main(int argc, char **argv)
406406

407407
done:
408408

409+
/* if we got here, stdin/out/err might be not accessible anymore */
410+
ret = open("/dev/null", O_RDWR);
411+
if (ret >= 0) {
412+
close(STDIN_FILENO);
413+
dup2(ret, STDIN_FILENO);
414+
close(STDOUT_FILENO);
415+
dup2(ret, STDOUT_FILENO);
416+
close(STDERR_FILENO);
417+
dup2(ret, STDERR_FILENO);
418+
}
419+
409420
if (selected_device)
410421
device_close(selected_device);
411422

0 commit comments

Comments
 (0)