return ret;
}
-void ERR_error_string_n(unsigned long e, char *buf, size_t len)
+void ossl_err_string_int(unsigned long e, const char *func,
+ char *buf, size_t len)
{
char lsbuf[64], rsbuf[256];
const char *ls, *rs = NULL;
- unsigned long f = 0, l, r;
+ unsigned long l, r;
if (len == 0)
return;
* directly instead.
*/
r = ERR_GET_REASON(e);
+#ifndef OPENSSL_NO_ERR
if (ERR_SYSTEM_ERROR(e)) {
if (openssl_strerror_r(r, rsbuf, sizeof(rsbuf)))
rs = rsbuf;
} else {
rs = ERR_reason_error_string(e);
}
+#endif
if (rs == NULL) {
BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
rs = rsbuf;
}
- BIO_snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls, "", rs);
+ BIO_snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls, func, rs);
if (strlen(buf) == len - 1) {
/* Didn't fit; use a minimal format. */
- BIO_snprintf(buf, len, "err:%lx:%lx:%lx:%lx", e, l, f, r);
+ BIO_snprintf(buf, len, "err:%lx:%lx:%lx:%lx", e, l, 0L, r);
}
}
+
+void ERR_error_string_n(unsigned long e, char *buf, size_t len)
+{
+ ossl_err_string_int(e, "", buf, len);
+}
+
/*
* ERR_error_string_n should be used instead for ret != NULL as
* ERR_error_string cannot know how large the buffer is
}
ERR_STATE *err_get_state_int(void);
+void ossl_err_string_int(unsigned long e, const char *func,
+ char *buf, size_t len);
int line, flags;
while ((l = ERR_get_error_all(&file, &line, &func, &data, &flags)) != 0) {
- char buf[ERR_PRINT_BUF_SIZE], *hex;
- const char *lib, *reason = NULL;
- char rsbuf[256];
- unsigned long r = ERR_GET_REASON(l);
-
- lib = ERR_lib_error_string(l);
-
- /*
- * ERR_reason_error_string() can't safely return system error strings,
- * since it would call openssl_strerror_r(), which needs a buffer for
- * thread safety. So for system errors, we call openssl_strerror_r()
- * directly instead.
- */
- if (ERR_SYSTEM_ERROR(l)) {
- if (openssl_strerror_r(r, rsbuf, sizeof(rsbuf)))
- reason = rsbuf;
- } else {
- reason = ERR_reason_error_string(l);
- }
+ char buf[ERR_PRINT_BUF_SIZE] = "";
+ char *hex = NULL;
+ int offset;
- if (func == NULL)
- func = "unknown function";
- if (reason == NULL) {
- BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
- reason = rsbuf;
- }
if ((flags & ERR_TXT_STRING) == 0)
data = "";
+
hex = openssl_buf2hexstr_sep((const unsigned char *)&tid, sizeof(tid),
'\0');
- BIO_snprintf(buf, sizeof(buf), "%s:error::%s:%s:%s:%s:%d:%s\n",
- hex == NULL ? "<null>" : hex, lib, func, reason, file,
- line, data);
+ BIO_snprintf(buf, sizeof(buf), "%s:", hex == NULL ? "<null>" : hex);
+ offset = strlen(buf);
+ ossl_err_string_int(l, func, buf + offset, sizeof(buf) - offset);
+ offset += strlen(buf + offset);
+ BIO_snprintf(buf + offset, sizeof(buf) - offset, ":%s:%d:%s\n",
+ file, line, data);
OPENSSL_free(hex);
if (cb(buf, strlen(buf), u) <= 0)
break; /* abort outputting the error report */