# HG changeset patch # User jbe # Date 1435004815 -7200 # Node ID 43a077f2ab49630a7cead809901afa9d0fbe6589 # Parent 453b7d1a79445e39569e80fa4f3ed2cdd6ecdb8d Safety catch for noncompliant strerror_r() implementation on GNU/Linux systems diff -r 453b7d1a7944 -r 43a077f2ab49 moonbridge.c --- a/moonbridge.c Mon Jun 22 22:19:41 2015 +0200 +++ b/moonbridge.c Mon Jun 22 22:26:55 2015 +0200 @@ -91,6 +91,9 @@ /* Maximum length of an error string returned by strerror() */ #define MOONBR_MAXSTRERRORLEN 80 +/* Error message for noncompliant strerror_r() implementation on GNU systems */ +#define MOONBR_STRERROR_R_MSG "Error detail unavailable due to noncompliant strerror_r() implementation" + /* Status bytes exchanged between master and child processes */ #define MOONBR_STATUS_IDLE 'I' #define MOONBR_COMMAND_CONNECT 'C' @@ -670,7 +673,7 @@ /* Logs an error in child process while appending error string for global errno variable */ static void moonbr_child_log_errno(const char *message) { - char errmsg[MOONBR_MAXSTRERRORLEN]; + char errmsg[MOONBR_MAXSTRERRORLEN] = MOONBR_STRERROR_R_MSG; strerror_r(errno, errmsg, MOONBR_MAXSTRERRORLEN); /* use thread-safe call in case child created threads */ fprintf(stderr, "%s: %s\n", message, errmsg); } @@ -1978,7 +1981,7 @@ if (errcode) { freeaddrinfo(res); if (errcode == EAI_SYSTEM) { - char errmsg[MOONBR_MAXSTRERRORLEN]; + char errmsg[MOONBR_MAXSTRERRORLEN] = MOONBR_STRERROR_R_MSG; strerror_r(errno, errmsg, MOONBR_MAXSTRERRORLEN); /* use thread-safe call in case child created threads */ luaL_error(L, "Could not resolve host: %s: %s", gai_strerror(errcode), errmsg); } else { diff -r 453b7d1a7944 -r 43a077f2ab49 moonbridge_io.c --- a/moonbridge_io.c Mon Jun 22 22:19:41 2015 +0200 +++ b/moonbridge_io.c Mon Jun 22 22:26:55 2015 +0200 @@ -37,8 +37,9 @@ #define MOONBR_IO_LISTEN_BACKLOG 1024 +#define MOONBR_IO_STRERROR_R_MSG "Error detail unavailable due to noncompliant strerror_r() implementation" #define moonbr_io_errmsg() \ - char errmsg[MOONBR_IO_MAXSTRERRORLEN]; \ + char errmsg[MOONBR_IO_MAXSTRERRORLEN] = MOONBR_IO_STRERROR_R_MSG; \ strerror_r(errno, errmsg, MOONBR_IO_MAXSTRERRORLEN) #define MOONBR_IO_HANDLE_MT_REGKEY "moonbridge_io_handle" @@ -1253,7 +1254,7 @@ int i, argc; int sockin[2], sockout[2], sockerr[2]; volatile int errorcond = 0; - volatile char errmsgbuf[MOONBR_IO_MAXSTRERRORLEN]; + volatile char errmsgbuf[MOONBR_IO_MAXSTRERRORLEN] = MOONBR_IO_STRERROR_R_MSG; moonbr_io_child_t *child; argc = lua_gettop(L); argv = lua_newuserdata(L, (argc + 1) * sizeof(char *));