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.
This commit is contained in:
Milan Broz
2015-01-10 20:33:42 +01:00
parent 2c70c057d6
commit e24a72f84c
2 changed files with 11 additions and 6 deletions

View File

@@ -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);