From e843a7caa220ad201bceddd9990918a004f30b51 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Oct 2022 08:36:21 +0200 Subject: [PATCH] cli: don't use unsafe functions in pager_fallback() The pager_fallback() runs in the forked child process. As such, it can only use functions from `man signal-safety` or that are explicitly allowed. We are mostly good, but g_printerr() is not allowed. It can deadlock. Just avoid it. It's not very to print those error messages anyway. --- src/nmcli/utils.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/nmcli/utils.c b/src/nmcli/utils.c index 07b778ff3f..503a20a43d 100644 --- a/src/nmcli/utils.c +++ b/src/nmcli/utils.c @@ -1423,20 +1423,18 @@ pager_fallback(void) { char buf[64]; int rb; - int errsv; + + /* We are still in the child process (after fork() and before exec()). + * We must only used functions listed in `man signal-safety`. */ do { rb = read(STDIN_FILENO, buf, sizeof(buf)); if (rb == -1) { - errsv = errno; - if (errsv == EINTR) + if (errno == EINTR) continue; - g_printerr(_("Error reading nmcli output: %s\n"), nm_strerror_native(errsv)); _exit(EXIT_FAILURE); } if (write(STDOUT_FILENO, buf, rb) == -1) { - errsv = errno; - g_printerr(_("Error writing nmcli output: %s\n"), nm_strerror_native(errsv)); _exit(EXIT_FAILURE); } } while (rb > 0);