diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index bbb8cd8f16..2bd4d47712 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -de00572e0a22b67defb05759a4d5aac6bf0e107bfd6834a1edc20ffb0379528d /usr/local/bin/tox-bootstrapd +746158481ebd16d70aadc0bf4d2dc6da6a2f3ac4eb12d219b49fc6fd7e60d149 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/network.c b/toxcore/network.c index 17aa6b3af1..3532a94ca6 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -1746,18 +1746,36 @@ char *net_new_strerror(int error) error, 0, (char *)&str, 0, nullptr); return str; #else - char *str = (char *)malloc(256); + char tmp[256]; + + errno = 0; + #ifdef _GNU_SOURCE - str = strerror_r(error, str, 256); + const char *retstr = strerror_r(error, tmp, sizeof(tmp)); + + if (errno != 0) { + snprintf(tmp, sizeof(tmp), "error %d (strerror_r failed with errno %d)", error, errno); + } + #else - const int fmt_error = strerror_r(error, str, 256); + const int fmt_error = strerror_r(error, tmp, sizeof(tmp)); if (fmt_error != 0) { - snprintf(str, 256, "error %d (strerror failed with error %d)", error, fmt_error); + snprintf(tmp, sizeof(tmp), "error %d (strerror_r failed with error %d, errno %d)", error, fmt_error, errno); } + const char *retstr = tmp; #endif + const size_t retstr_len = strlen(retstr); + char *str = (char *)malloc(retstr_len + 1); + + if (str == nullptr) { + return nullptr; + } + + memcpy(str, retstr, retstr_len + 1); + return str; #endif }