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