Commit 94ed30e5 authored by Daniel Black's avatar Daniel Black Committed by Andrew Hutchings

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.
parent 2f6bb9cd
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#ifdef __WIN__ #ifdef __WIN__
#include <crtdbg.h> #include <crtdbg.h>
#include <direct.h>
#define SIGNAL_FMT "exception 0x%x" #define SIGNAL_FMT "exception 0x%x"
#else #else
#define SIGNAL_FMT "signal %d" #define SIGNAL_FMT "signal %d"
...@@ -67,27 +68,27 @@ static inline void output_core_info() ...@@ -67,27 +68,27 @@ static inline void output_core_info()
my_safe_printf_stderr("Writing a core file...\nWorking directory at %.*s\n", my_safe_printf_stderr("Writing a core file...\nWorking directory at %.*s\n",
(int) len, buff); (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"); 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_write_stderr(buff, len);
} }
my_close(fd, MYF(0)); close(fd);
} }
#ifdef __linux__ #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_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_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff);
my_close(fd, MYF(0)); close(fd);
} }
#endif #endif
#elif defined(__APPLE__) || defined(__FreeBSD__) #elif defined(__APPLE__) || defined(__FreeBSD__)
...@@ -101,11 +102,14 @@ static inline void output_core_info() ...@@ -101,11 +102,14 @@ static inline void output_core_info()
{ {
my_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff); my_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff);
} }
#else #elif defined(HAVE_GETCWD)
char buff[80]; char buff[80];
my_getwd(buff, sizeof(buff), 0);
my_safe_printf_stderr("Writing a core file at %s\n", buff); if (getcwd(buff, sizeof(buff)))
{
my_safe_printf_stderr("Writing a core file at %.*s\n", (int) sizeof(buff), buff);
fflush(stderr); fflush(stderr);
}
#endif #endif
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment