summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Black <daniel@mariadb.org>2023-02-10 12:58:57 +1100
committerAndrew Hutchings <andrew@linuxjedi.co.uk>2023-03-08 13:25:30 +0000
commit94ed30e505f8a6d9dca8a2006f6dfced1bff9dec (patch)
tree2d193570803bb86a4413efcc7b84c91d4d752f00
parent2f6bb9cda57e2ddbfffc5bdad00dfb352dab1313 (diff)
downloadmariadb-git-94ed30e505f8a6d9dca8a2006f6dfced1bff9dec.tar.gz
MDEV-30613 output_core_info crashes in my_read()
and my_getwd(). The cause is my_errno define which depends on my_thread_var being a not null pointer otherwise it will be de-referenced and cause a SEGV already in the signal handler. Replace uses of these functions in the output_core_info using posix read/getcwd functions instead. The getwd fallback in my_getcwd isn't needed as its been obsolute for a very long time. Thanks Vladislav Vaintroub for diagnosis and posix recommendation.
-rw-r--r--sql/signal_handler.cc30
1 files changed, 17 insertions, 13 deletions
diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc
index 2ddda3cec9d..96c067b717e 100644
--- a/sql/signal_handler.cc
+++ b/sql/signal_handler.cc
@@ -27,6 +27,7 @@
#ifdef __WIN__
#include <crtdbg.h>
+#include <direct.h>
#define SIGNAL_FMT "exception 0x%x"
#else
#define SIGNAL_FMT "signal %d"
@@ -67,27 +68,27 @@ static inline void output_core_info()
my_safe_printf_stderr("Writing a core file...\nWorking directory at %.*s\n",
(int) len, buff);
}
- if ((fd= my_open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0)
+ if ((fd= open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0)
{
my_safe_printf_stderr("Resource Limits:\n");
- while ((len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0))) > 0)
+ while ((len= read(fd, (uchar*)buff, sizeof(buff))) > 0)
{
my_write_stderr(buff, len);
}
- my_close(fd, MYF(0));
+ close(fd);
}
#ifdef __linux__
- if ((fd= my_open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0)
+ if ((fd= open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0)
{
- len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0));
+ len= read(fd, (uchar*)buff, sizeof(buff));
my_safe_printf_stderr("Core pattern: %.*s\n", (int) len, buff);
- my_close(fd, MYF(0));
+ close(fd);
}
- if ((fd= my_open("/proc/version", O_RDONLY, MYF(0))) >= 0)
+ if ((fd= open("/proc/version", O_RDONLY)) >= 0)
{
- len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0));
+ len= read(fd, (uchar*)buff, sizeof(buff));
my_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff);
- my_close(fd, MYF(0));
+ close(fd);
}
#endif
#elif defined(__APPLE__) || defined(__FreeBSD__)
@@ -101,11 +102,14 @@ static inline void output_core_info()
{
my_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff);
}
-#else
+#elif defined(HAVE_GETCWD)
char buff[80];
- my_getwd(buff, sizeof(buff), 0);
- my_safe_printf_stderr("Writing a core file at %s\n", buff);
- fflush(stderr);
+
+ if (getcwd(buff, sizeof(buff)))
+ {
+ my_safe_printf_stderr("Writing a core file at %.*s\n", (int) sizeof(buff), buff);
+ fflush(stderr);
+ }
#endif
}