|
|
90e381 |
From e679a3ce0f2cf1558da31e0bccd9e2398b89c7e9 Mon Sep 17 00:00:00 2001
|
|
|
90e381 |
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
|
|
|
90e381 |
Date: Tue, 30 Jul 2019 16:07:01 +0200
|
|
|
90e381 |
Subject: [PATCH 2/2] Prevent recursion in bug()
|
|
|
90e381 |
|
|
|
90e381 |
Resolves: rhbz#1666380
|
|
|
90e381 |
---
|
|
|
90e381 |
sysutil.c | 35 +++++++++++++++++++++++++++++++----
|
|
|
90e381 |
sysutil.h | 1 +
|
|
|
90e381 |
utility.c | 12 +++++++-----
|
|
|
90e381 |
3 files changed, 39 insertions(+), 9 deletions(-)
|
|
|
90e381 |
|
|
|
90e381 |
diff --git a/sysutil.c b/sysutil.c
|
|
|
90e381 |
index fd07d99..e2df671 100644
|
|
|
90e381 |
--- a/sysutil.c
|
|
|
90e381 |
+++ b/sysutil.c
|
|
|
90e381 |
@@ -774,21 +774,48 @@ vsf_sysutil_deactivate_linger_failok(int fd)
|
|
|
90e381 |
(void) setsockopt(fd, SOL_SOCKET, SO_LINGER, &the_linger, sizeof(the_linger));
|
|
|
90e381 |
}
|
|
|
90e381 |
|
|
|
90e381 |
-void
|
|
|
90e381 |
-vsf_sysutil_activate_noblock(int fd)
|
|
|
90e381 |
+static int
|
|
|
90e381 |
+vsf_sysutil_activate_noblock_internal(int fd, int return_err)
|
|
|
90e381 |
{
|
|
|
90e381 |
int retval;
|
|
|
90e381 |
int curr_flags = fcntl(fd, F_GETFL);
|
|
|
90e381 |
if (vsf_sysutil_retval_is_error(curr_flags))
|
|
|
90e381 |
{
|
|
|
90e381 |
- die("fcntl");
|
|
|
90e381 |
+ if (return_err)
|
|
|
90e381 |
+ {
|
|
|
90e381 |
+ return -1;
|
|
|
90e381 |
+ }
|
|
|
90e381 |
+ else
|
|
|
90e381 |
+ {
|
|
|
90e381 |
+ die("fcntl");
|
|
|
90e381 |
+ }
|
|
|
90e381 |
}
|
|
|
90e381 |
curr_flags |= O_NONBLOCK;
|
|
|
90e381 |
retval = fcntl(fd, F_SETFL, curr_flags);
|
|
|
90e381 |
if (retval != 0)
|
|
|
90e381 |
{
|
|
|
90e381 |
- die("fcntl");
|
|
|
90e381 |
+ if (return_err)
|
|
|
90e381 |
+ {
|
|
|
90e381 |
+ return -1;
|
|
|
90e381 |
+ }
|
|
|
90e381 |
+ else
|
|
|
90e381 |
+ {
|
|
|
90e381 |
+ die("fcntl");
|
|
|
90e381 |
+ }
|
|
|
90e381 |
}
|
|
|
90e381 |
+ return 0;
|
|
|
90e381 |
+}
|
|
|
90e381 |
+
|
|
|
90e381 |
+void
|
|
|
90e381 |
+vsf_sysutil_activate_noblock(int fd)
|
|
|
90e381 |
+{
|
|
|
90e381 |
+ (void) vsf_sysutil_activate_noblock_internal(fd, 0);
|
|
|
90e381 |
+}
|
|
|
90e381 |
+
|
|
|
90e381 |
+int
|
|
|
90e381 |
+vsf_sysutil_activate_noblock_no_die(int fd)
|
|
|
90e381 |
+{
|
|
|
90e381 |
+ return vsf_sysutil_activate_noblock_internal(fd, 1);
|
|
|
90e381 |
}
|
|
|
90e381 |
|
|
|
90e381 |
void
|
|
|
90e381 |
diff --git a/sysutil.h b/sysutil.h
|
|
|
90e381 |
index 2df14ed..0772423 100644
|
|
|
90e381 |
--- a/sysutil.h
|
|
|
90e381 |
+++ b/sysutil.h
|
|
|
90e381 |
@@ -281,6 +281,7 @@ void vsf_sysutil_activate_oobinline(int fd);
|
|
|
90e381 |
void vsf_sysutil_activate_linger(int fd);
|
|
|
90e381 |
void vsf_sysutil_deactivate_linger_failok(int fd);
|
|
|
90e381 |
void vsf_sysutil_activate_noblock(int fd);
|
|
|
90e381 |
+int vsf_sysutil_activate_noblock_no_die(int fd);
|
|
|
90e381 |
void vsf_sysutil_deactivate_noblock(int fd);
|
|
|
90e381 |
/* This does SHUT_RDWR */
|
|
|
90e381 |
void vsf_sysutil_shutdown_failok(int fd);
|
|
|
90e381 |
diff --git a/utility.c b/utility.c
|
|
|
90e381 |
index 75e5bdd..5619a04 100644
|
|
|
90e381 |
--- a/utility.c
|
|
|
90e381 |
+++ b/utility.c
|
|
|
90e381 |
@@ -47,11 +47,13 @@ bug(const char* p_text)
|
|
|
90e381 |
{
|
|
|
90e381 |
vsf_log_die(p_text);
|
|
|
90e381 |
}
|
|
|
90e381 |
- vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD);
|
|
|
90e381 |
- (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "500 OOPS: ", 10);
|
|
|
90e381 |
- (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text,
|
|
|
90e381 |
- vsf_sysutil_strlen(p_text));
|
|
|
90e381 |
- (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2);
|
|
|
90e381 |
+ if (vsf_sysutil_activate_noblock_no_die(VSFTP_COMMAND_FD) == 0)
|
|
|
90e381 |
+ {
|
|
|
90e381 |
+ (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "500 OOPS: ", 10);
|
|
|
90e381 |
+ (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text,
|
|
|
90e381 |
+ vsf_sysutil_strlen(p_text));
|
|
|
90e381 |
+ (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2);
|
|
|
90e381 |
+ }
|
|
|
90e381 |
if (tunable_log_die)
|
|
|
90e381 |
{
|
|
|
90e381 |
/* Workaround for https://github.com/systemd/systemd/issues/2913 */
|
|
|
90e381 |
--
|
|
|
90e381 |
2.20.1
|
|
|
90e381 |
|