*) Support SM2 signing and verification schemes with X509 certificate.
[Paul Yang]
+ *) The macro SYSerr() was changed to take a function name, not
+ a numeric value; the SYS_F_xxx defines were removed.
+ [Rich Salz]
+
*) Use SHA256 as the default digest for TS query in the ts app.
[Tomas Mraz]
#ifndef OPENSSL_NO_POSIX_IO
BIO_get_fp(in, &dbfp);
if (fstat(fileno(dbfp), &dbst) == -1) {
- SYSerr(SYS_F_FSTAT, errno);
- ERR_add_error_data(3, "fstat('", dbfile, "')");
+ SYSerr("fstat", errno);
+ ERR_add_error_data(1, dbfile);
ERR_print_errors(bio_err);
goto err;
}
flags)) != 0) {
# ifdef EAI_SYSTEM
if (ret == EAI_SYSTEM) {
- SYSerr(SYS_F_GETNAMEINFO, get_last_socket_error());
+ SYSerr("getnameinfo", get_last_socket_error());
BIOerr(BIO_F_ADDR_STRINGS, ERR_R_SYS_LIB);
} else
# endif
switch ((gai_ret = getaddrinfo(host, service, &hints, res))) {
# ifdef EAI_SYSTEM
case EAI_SYSTEM:
- SYSerr(SYS_F_GETADDRINFO, get_last_socket_error());
+ SYSerr("getaddrinfo", get_last_socket_error());
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB);
break;
# endif
*/
# if defined(OPENSSL_SYS_VXWORKS)
/* h_errno doesn't exist on VxWorks */
- SYSerr(SYS_F_GETHOSTBYNAME, 1000 );
+ SYSerr("gethostbyname", 1000 );
# else
- SYSerr(SYS_F_GETHOSTBYNAME, 1000 + h_errno);
+ SYSerr("gethostbyname", 1000 + h_errno);
# endif
#else
- SYSerr(SYS_F_GETHOSTBYNAME, WSAGetLastError());
+ SYSerr("gethostbyname", get_last_socket_error());
#endif
ret = 0;
goto err;
se = getservbyname(service, proto);
if (se == NULL) {
-#ifndef OPENSSL_SYS_WINDOWS
- SYSerr(SYS_F_GETSERVBYNAME, errno);
-#else
- SYSerr(SYS_F_GETSERVBYNAME, WSAGetLastError());
-#endif
+ SYSerr("getservbyname", get_last_socket_error());
goto err;
}
} else {
static struct WSAData wsa_state;
if (!wsa_init_done) {
- int err;
-
wsa_init_done = 1;
memset(&wsa_state, 0, sizeof(wsa_state));
/*
* probed at run-time with DSO_global_lookup.
*/
if (WSAStartup(0x0202, &wsa_state) != 0) {
- err = WSAGetLastError();
- SYSerr(SYS_F_WSASTARTUP, err);
+ SYSerr("wsastartup", get_last_socket_error());
BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
return -1;
}
i = ioctlsocket(fd, type, ARG);
# endif /* __DJGPP__ */
if (i < 0)
- SYSerr(SYS_F_IOCTLSOCKET, get_last_socket_error());
+ SYSerr("ioctlsocket", get_last_socket_error());
return i;
}
ret = -2;
goto end;
}
- SYSerr(SYS_F_ACCEPT, get_last_socket_error());
+ SYSerr("accept", get_last_socket_error());
BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR);
goto end;
}
l = fcntl(s, F_GETFL, 0);
if (l == -1) {
- SYSerr(SYS_F_FCNTL, get_last_sys_error());
+ SYSerr("fcntl", get_last_sys_error());
ret = -1;
} else {
# if defined(O_NONBLOCK)
ret = fcntl(s, F_SETFL, l);
if (ret < 0) {
- SYSerr(SYS_F_FCNTL, get_last_sys_error());
+ SYSerr("fcntl", get_last_sys_error());
}
}
# else
ret = getsockname(sock, BIO_ADDR_sockaddr_noconst(info->addr),
&addr_len);
if (ret == -1) {
- SYSerr(SYS_F_GETSOCKNAME, get_last_socket_error());
+ SYSerr("getsockname", get_last_socket_error());
BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_GETSOCKNAME_ERROR);
return 0;
}
sock = socket(domain, socktype, protocol);
if (sock == -1) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ SYSerr("socket", get_last_socket_error());
BIOerr(BIO_F_BIO_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
return INVALID_SOCKET;
}
if (options & BIO_SOCK_KEEPALIVE) {
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_KEEPALIVE);
return 0;
}
if (options & BIO_SOCK_NODELAY) {
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_NODELAY);
return 0;
}
if (connect(sock, BIO_ADDR_sockaddr(addr),
BIO_ADDR_sockaddr_size(addr)) == -1) {
if (!BIO_sock_should_retry(-1)) {
- SYSerr(SYS_F_CONNECT, get_last_socket_error());
+ SYSerr("connect", get_last_socket_error());
BIOerr(BIO_F_BIO_CONNECT, BIO_R_CONNECT_ERROR);
}
return 0;
if (options & BIO_SOCK_REUSEADDR) {
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_BIND, BIO_R_UNABLE_TO_REUSEADDR);
return 0;
}
# endif
if (bind(sock, BIO_ADDR_sockaddr(addr), BIO_ADDR_sockaddr_size(addr)) != 0) {
- SYSerr(SYS_F_BIND, get_last_socket_error());
+ SYSerr("bind", get_last_socket_error());
BIOerr(BIO_F_BIO_BIND, BIO_R_UNABLE_TO_BIND_SOCKET);
return 0;
}
if (getsockopt(sock, SOL_SOCKET, SO_TYPE,
(void *)&socktype, &socktype_len) != 0
|| socktype_len != sizeof(socktype)) {
- SYSerr(SYS_F_GETSOCKOPT, get_last_socket_error());
+ SYSerr("getsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_GETTING_SOCKTYPE);
return 0;
}
if (options & BIO_SOCK_KEEPALIVE) {
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_KEEPALIVE);
return 0;
}
if (options & BIO_SOCK_NODELAY) {
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_NODELAY);
return 0;
}
on = options & BIO_SOCK_V6_ONLY ? 1 : 0;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
(const void *)&on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
+ SYSerr("setsockopt", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_LISTEN_V6_ONLY);
return 0;
}
return 0;
if (socktype != SOCK_DGRAM && listen(sock, MAX_LISTEN) == -1) {
- SYSerr(SYS_F_LISTEN, get_last_socket_error());
+ SYSerr("listen", get_last_socket_error());
BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_LISTEN_SOCKET);
return 0;
}
BIO_ADDR_sockaddr_noconst(addr), &len);
if (accepted_sock == -1) {
if (!BIO_sock_should_retry(accepted_sock)) {
- SYSerr(SYS_F_ACCEPT, get_last_socket_error());
+ SYSerr("accept", get_last_socket_error());
BIOerr(BIO_F_BIO_ACCEPT_EX, BIO_R_ACCEPT_ERROR);
}
return INVALID_SOCKET;
BIO_ADDRINFO_socktype(c->addr_iter),
BIO_ADDRINFO_protocol(c->addr_iter), 0);
if (ret == (int)INVALID_SOCKET) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ SYSerr("socket", get_last_socket_error());
ERR_add_error_data(4,
"hostname=", c->param_addr,
" service=", c->param_serv);
BIO_ADDRINFO_socktype(c->addr_iter),
BIO_ADDRINFO_protocol(c->addr_iter), 0);
if (ret == (int)INVALID_SOCKET) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ SYSerr("socket", get_last_socket_error());
ERR_add_error_data(4,
"hostname=", c->param_hostname,
" service=", c->param_service);
ERR_clear_error();
break;
} else {
- SYSerr(SYS_F_CONNECT, get_last_socket_error());
+ SYSerr("connect", get_last_socket_error());
ERR_add_error_data(4,
"hostname=", c->param_hostname,
" service=", c->param_service);
i = BIO_sock_error(b->num);
if (i) {
BIO_clear_retry_flags(b);
- SYSerr(SYS_F_CONNECT, i);
+ SYSerr("connect", i);
ERR_add_error_data(4,
"hostname=", c->param_hostname,
" service=", c->param_service);
fp_flags |= BIO_FP_TEXT;
if (file == NULL) {
- SYSerr(SYS_F_FOPEN, get_last_sys_error());
+ SYSerr("fopen", get_last_sys_error());
ERR_add_error_data(5, "fopen('", filename, "','", mode, "')");
if (errno == ENOENT
# ifdef ENXIO
if (ret == 0
&& (b->flags & BIO_FLAGS_UPLINK_INTERNAL
? UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr))) {
- SYSerr(SYS_F_FREAD, get_last_sys_error());
+ SYSerr("fread", get_last_sys_error());
BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
ret = -1;
}
# endif
fp = openssl_fopen(ptr, p);
if (fp == NULL) {
- SYSerr(SYS_F_FOPEN, get_last_sys_error());
+ SYSerr("fopen", get_last_sys_error());
ERR_add_error_data(5, "fopen('", ptr, "','", p, "')");
BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB);
ret = 0;
st = b->flags & BIO_FLAGS_UPLINK_INTERNAL
? UP_fflush(b->ptr) : fflush((FILE *)b->ptr);
if (st == EOF) {
- SYSerr(SYS_F_FFLUSH, get_last_sys_error());
+ SYSerr("fflush", get_last_sys_error());
ERR_add_error_data(1, "fflush()");
BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB);
ret = 0;
BIO *next;
if (stat(include, &st) < 0) {
- SYSerr(SYS_F_STAT, errno);
+ SYSerr("stat", errno);
ERR_add_error_data(1, include);
/* missing include file is not fatal error */
return NULL;
/********************************************************/
+void ERR_put_func_error(int lib, const char *func, int reason,
+ const char *file, int line)
+{
+ ERR_put_error(lib, 0, reason, file, line);
+ ERR_add_error_data(2, "calling function ", func);
+}
+
void ERR_put_error(int lib, int func, int reason, const char *file, int line)
{
ERR_STATE *es;
}
if (stat(path_data[i].path, &st) < 0) {
- SYSerr(SYS_F_STAT, errno);
+ SYSerr("stat", errno);
ERR_add_error_data(1, path_data[i].path);
} else {
path = path_data[i].path;
=head1 NAME
-ERR_put_error, ERR_add_error_data, ERR_add_error_vdata - record an error
+ERR_put_error, ERR_put_func_error,
+ERR_add_error_data, ERR_add_error_vdata - record an error
=head1 SYNOPSIS
#include <openssl/err.h>
void ERR_put_error(int lib, int func, int reason, const char *file, int line);
+ void ERR_put_func_error(int lib, const char *func, int reason,
+ const char *file, int line);
void ERR_add_error_data(int num, ...);
void ERR_add_error_vdata(int num, va_list arg);
B<func> of library B<lib>, in line number B<line> of B<file>.
This function is usually called by a macro.
+ERR_put_func_err() is similar except that the B<func> is a string naming
+a function external to OpenSSL, usually provided by the platform on which
+OpenSSL and the application is running.
+
ERR_add_error_data() associates the concatenation of its B<num> string
arguments with the error code added last.
ERR_add_error_vdata() is similar except the argument is a B<va_list>.
static int clean_devcrypto_session(struct session_op *sess) {
if (ioctl(cfd, CIOCFSESSION, &sess->ses) < 0) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
memset(sess, 0, sizeof(struct session_op));
cipher_ctx->mode = cipher_d->flags & EVP_CIPH_MODE;
cipher_ctx->blocksize = cipher_d->blocksize;
if (ioctl(cfd, CIOCGSESSION, &cipher_ctx->sess) < 0) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
#endif
if (ioctl(cfd, CIOCCRYPT, &cryp) < 0) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
memset(&digest_ctx->sess, 0, sizeof(digest_ctx->sess));
digest_ctx->sess.mac = digest_d->devcryptoid;
if (ioctl(cfd, CIOCGSESSION, &digest_ctx->sess) < 0) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
return 1;
return 1;
}
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT)) {
memcpy(md, digest_ctx->digest_res, EVP_MD_CTX_size(ctx));
} else if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
return 1;
if (!digest_init(to)) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
cphash.src_ses = digest_from->sess.ses;
cphash.dst_ses = digest_to->sess.ses;
if (ioctl(cfd, CIOCCPHASH, &cphash) < 0) {
- SYSerr(SYS_F_IOCTL, errno);
+ SYSerr("ioctl", errno);
return 0;
}
return 1;
#endif
# ifndef OPENSSL_NO_ERR
-# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
+# define ERR_PUT_error(l,f,r,fn,ln) ERR_put_error(l,f,r,fn,ln)
+# define ERR_PUT_func_error(l,f,r,fn,ln) ERR_put_func_error(l,f,r,fn,ln)
# else
-# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
+# define ERR_PUT_error(l,f,r,fn,ln) ERR_put_error(l,f,r,NULL,0)
+# define ERR_PUT_func_error(l,f,r,fn,ln) ERR_put_func_error(l,f,r,NULL,0)
# endif
# include <errno.h>
# define ERR_LIB_USER 128
-# define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,0,(r),OPENSSL_FILE,OPENSSL_LINE)
+# define SYSerr(f,r) ERR_PUT_func_error(ERR_LIB_SYS,(f),(r),OPENSSL_FILE,OPENSSL_LINE)
# define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,0,(r),OPENSSL_FILE,OPENSSL_LINE)
# define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,0,(r),OPENSSL_FILE,OPENSSL_LINE)
# define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,0,(r),OPENSSL_FILE,OPENSSL_LINE)
# define ERR_GET_REASON(l) (int)( (l) & 0xFFFL)
# define ERR_FATAL_ERROR(l) (int)( (l) & ERR_R_FATAL)
-/* OS functions */
-# define SYS_F_FOPEN 1
-# define SYS_F_CONNECT 2
-# define SYS_F_GETSERVBYNAME 3
-# define SYS_F_SOCKET 4
-# define SYS_F_IOCTLSOCKET 5
-# define SYS_F_BIND 6
-# define SYS_F_LISTEN 7
-# define SYS_F_ACCEPT 8
-# define SYS_F_WSASTARTUP 9/* Winsock stuff */
-# define SYS_F_OPENDIR 10
-# define SYS_F_FREAD 11
-# define SYS_F_GETADDRINFO 12
-# define SYS_F_GETNAMEINFO 13
-# define SYS_F_SETSOCKOPT 14
-# define SYS_F_GETSOCKOPT 15
-# define SYS_F_GETSOCKNAME 16
-# define SYS_F_GETHOSTBYNAME 17
-# define SYS_F_FFLUSH 18
-# define SYS_F_OPEN 19
-# define SYS_F_CLOSE 20
-# define SYS_F_IOCTL 21
-# define SYS_F_STAT 22
-# define SYS_F_FCNTL 23
-# define SYS_F_FSTAT 24
-# define SYS_F_SENDFILE 25
-
/* reasons */
# define ERR_R_SYS_LIB ERR_LIB_SYS/* 2 */
# define ERR_R_BN_LIB ERR_LIB_BN/* 3 */
DEFINE_LHASH_OF(ERR_STRING_DATA);
void ERR_put_error(int lib, int func, int reason, const char *file, int line);
+void ERR_put_func_error(int lib, const char *func, int reason,
+ const char *file, int line);
void ERR_set_error_data(char *data, int flags);
unsigned long ERR_get_error(void);
}
if (errno) {
- SYSerr(SYS_F_OPENDIR, get_last_sys_error());
+ SYSerr("readdir", get_last_sys_error());
ERR_add_error_data(3, "OPENSSL_DIR_read(&ctx, '", dir, "')");
SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
goto err;
else
#endif
#ifdef OPENSSL_NO_KTLS
- SYSerr(SYS_F_SENDFILE, get_last_sys_error());
+ SYSerr("sendfile", get_last_sys_error());
#else
SSLerr(SSL_F_SSL_SENDFILE, SSL_R_UNINITIALIZED);
#endif
return TEST_str_eq(data, "hello world");
}
+/* Test that setting a platform error sets the right values. */
+static int platform_error(void)
+{
+ const char *file = __FILE__, *f, *data;
+ const int line = __LINE__;
+ int l;
+ unsigned long e;
+
+ ERR_put_func_error(ERR_LIB_SYS, "exit", ERR_R_INTERNAL_ERROR, file, line);
+ if (!TEST_ulong_ne(e = ERR_get_error_line_data(&f, &l, &data, NULL), 0)
+ || !TEST_int_eq(ERR_GET_REASON(e), ERR_R_INTERNAL_ERROR)
+ || !TEST_int_eq(l, line)
+ || !TEST_str_eq(f, file)
+ || !TEST_str_eq(data, "calling function exit"))
+ return 0;
+ return 1;
+}
+
int setup_tests(void)
{
ADD_TEST(preserves_system_error);
ADD_TEST(vdata_appends);
+ ADD_TEST(platform_error);
return 1;
}
EVP_KEYMGMT_free 4796 3_0_0 EXIST::FUNCTION:
EVP_KEYMGMT_provider 4797 3_0_0 EXIST::FUNCTION:
X509_PUBKEY_dup 4798 3_0_0 EXIST::FUNCTION:
+ERR_put_func_error 4799 3_0_0 EXIST::FUNCTION: