Commit e24a72f8 authored by Milan Broz's avatar Milan Broz

Fix crash if non-GNU strerror_r is used.

The strerror_r call exists in POSIX and GNU variant,
if POSIX variant is used (like in musl libc replacement)
we cannot rely on char* pointer.

Fixes issue#237.
parent 2c70c057
......@@ -62,6 +62,7 @@ AC_TYPE_OFF_T
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO
AC_PROG_GCC_TRADITIONAL
AC_FUNC_STRERROR_R
dnl ==========================================================================
......
......@@ -163,7 +163,7 @@ int yesDialog(const char *msg, void *usrptr __attribute__((unused)))
void show_status(int errcode)
{
char error[256], *error_;
char error[256];
if(!opt_verbose)
return;
......@@ -175,12 +175,16 @@ void show_status(int errcode)
crypt_get_error(error, sizeof(error));
if (!error[0]) {
error_ = strerror_r(-errcode, error, sizeof(error));
if (error_ != error) {
if (*error) {
#ifdef STRERROR_R_CHAR_P /* GNU-specific strerror_r */
char *error_ = strerror_r(-errcode, error, sizeof(error));
if (error_ != error)
strncpy(error, error_, sizeof(error));
error[sizeof(error) - 1] = '\0';
}
#else /* POSIX strerror_r variant */
if (strerror_r(-errcode, error, sizeof(error)))
*error = '\0';
#endif
error[sizeof(error) - 1] = '\0';
}
log_err(_("Command failed with code %i"), -errcode);
......
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