The previous patch wasn't thread-safe for one function and also wasn't written
for the XPI version of strerror_r() and would therefore display "(null)" in
some of the errors. The attached patch fixes these bugs.
Sorry for the previous patch being crap.
diff -ru libcsoap-1.1.0.old/libcsoap/soap-ctx.c libcsoap-1.1.0.new/libcsoap/soap-ctx.c
--- libcsoap-1.1.0.old/libcsoap/soap-ctx.c 2009-06-16 10:06:16.000000000 +1000
+++ libcsoap-1.1.0.new/libcsoap/soap-ctx.c 2009-06-16 12:02:51.000000000 +1000
@@ -48,7 +48,7 @@
if (!(ctx = (SoapCtx *) malloc(sizeof(SoapCtx))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
diff -ru libcsoap-1.1.0.old/libcsoap/soap-env.c libcsoap-1.1.0.new/libcsoap/soap-env.c
--- libcsoap-1.1.0.old/libcsoap/soap-env.c 2006-07-10 02:24:19.000000000 +1000
+++ libcsoap-1.1.0.new/libcsoap/soap-env.c 2009-06-16 12:02:51.000000000 +1000
@@ -181,7 +181,7 @@
if (!(env = (SoapEnv *) malloc(sizeof(SoapEnv))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return herror_new("soap_env_from_doc", GENERAL_INVALID_PARAM, "malloc failed");
}
diff -ru libcsoap-1.1.0.old/libcsoap/soap-router.c libcsoap-1.1.0.new/libcsoap/soap-router.c
--- libcsoap-1.1.0.old/libcsoap/soap-router.c 2006-07-10 02:24:19.000000000 +1000
+++ libcsoap-1.1.0.new/libcsoap/soap-router.c 2009-06-16 12:02:51.000000000 +1000
@@ -44,7 +44,7 @@
if (!(router = (SoapRouter *) malloc(sizeof(SoapRouter))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
memset(router, 0, sizeof(SoapRouter));
diff -ru libcsoap-1.1.0.old/libcsoap/soap-server.c libcsoap-1.1.0.new/libcsoap/soap-server.c
--- libcsoap-1.1.0.old/libcsoap/soap-server.c 2006-07-10 02:24:19.000000000 +1000
+++ libcsoap-1.1.0.new/libcsoap/soap-server.c 2009-06-16 12:02:51.000000000 +1000
@@ -211,7 +211,7 @@
if (!(node = (SoapRouterNode *) malloc(sizeof(SoapRouterNode)))) {
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
diff -ru libcsoap-1.1.0.old/nanohttp/nanohttp-request.c libcsoap-1.1.0.new/nanohttp/nanohttp-request.c
--- libcsoap-1.1.0.old/nanohttp/nanohttp-request.c 2009-06-16 10:06:16.000000000 +1000
+++ libcsoap-1.1.0.new/nanohttp/nanohttp-request.c 2009-06-16 12:02:51.000000000 +1000
@@ -52,7 +52,7 @@
if (!(req = (hrequest_t *) malloc(sizeof(hrequest_t)))) {
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
@@ -175,7 +175,7 @@
{
if (!(tmppair = (hpair_t *) malloc(sizeof(hpair_t))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
diff -ru libcsoap-1.1.0.old/nanohttp/nanohttp-response.c libcsoap-1.1.0.new/nanohttp/nanohttp-response.c
--- libcsoap-1.1.0.old/nanohttp/nanohttp-response.c 2006-07-10 02:24:19.000000000 +1000
+++ libcsoap-1.1.0.new/nanohttp/nanohttp-response.c 2009-06-16 12:02:51.000000000 +1000
@@ -53,7 +53,7 @@
/* create response object */
if (!(res = (hresponse_t *) malloc(sizeof(hresponse_t)))) {
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
diff -ru libcsoap-1.1.0.old/nanohttp/nanohttp-server.c libcsoap-1.1.0.new/nanohttp/nanohttp-server.c
--- libcsoap-1.1.0.old/nanohttp/nanohttp-server.c 2006-07-10 02:24:19.000000000 +1000
+++ libcsoap-1.1.0.new/nanohttp/nanohttp-server.c 2009-06-16 12:02:51.000000000 +1000
@@ -249,7 +249,7 @@
if (!(service = (hservice_t *) malloc(sizeof(hservice_t))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return -1;
}
@@ -516,8 +516,7 @@
if (!(conn = (httpd_conn_t *) malloc(sizeof(httpd_conn_t))))
{
-
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
conn->sock = sock;
@@ -576,7 +575,7 @@
if (!(tmp = (char *) calloc(1, len)))
{
- log_error2("calloc failed (%s)", strerror(errno));
+ log_error1("calloc failed");
return -1;
}
@@ -968,7 +967,11 @@
pthread_sigmask(SIG_BLOCK, &thrsigset, NULL);
if ((err =
pthread_create(&(conn->tid), &(conn->attr), httpd_session_main, conn)))
- log_error2("pthread_create failed (%s)", strerror(err));
+ {
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ log_error2("pthread_create failed (%s)", err_buf);
+ }
#endif
return;
@@ -1158,7 +1161,7 @@
if (!(postdata = (char *) malloc(1)))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
postdata[0] = '\0';
@@ -1166,7 +1169,7 @@
}
if (!(postdata = (unsigned char *) malloc(content_length + 1)))
{
- log_error2("malloc failed (%)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
if (http_input_stream_read(req->in, postdata, (int) content_length) > 0)
diff -ru libcsoap-1.1.0.old/nanohttp/nanohttp-socket.c libcsoap-1.1.0.new/nanohttp/nanohttp-socket.c
--- libcsoap-1.1.0.old/nanohttp/nanohttp-socket.c 2009-06-16 10:06:16.000000000 +1000
+++ libcsoap-1.1.0.new/nanohttp/nanohttp-socket.c 2009-06-16 12:02:51.000000000 +1000
@@ -186,10 +186,14 @@
int h_errnop;
#endif
struct in_addr **h_addr_list;
+ char err_buf[256];
if ((dsock->sock = socket(AF_INET, SOCK_STREAM, 0)) <= 0)
+ {
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hsocket_open", HSOCKET_ERROR_CREATE,
- "Socket error (%s)", strerror(errno));
+ "Socket error (%s)", err_buf);
+ }
/* Get host data */
#ifdef HAVE_GETHOSTBYNAME_R
@@ -198,8 +202,11 @@
host = gethostbyname(hostname);
#endif
if(!host)
+ {
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hsocket_open", HSOCKET_ERROR_GET_HOSTNAME,
- "Socket error (%s)", strerror(errno));
+ "Socket error (%s)", err_buf);
+ }
h_addr_list = (struct in_addr **)host->h_addr_list;
address.sin_addr.s_addr = h_addr_list[0]->s_addr;
@@ -215,8 +222,11 @@
|| connect(dsock->sock, (struct sockaddr *) &address, sizeof(address)) != 0)
{
if(errno != EINPROGRESS)
+ {
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT,
- "Socket error (%s)", strerror(errno));
+ "Socket error (%s)", err_buf);
+ }
}
FD_ZERO(&fds);
@@ -252,13 +262,15 @@
hsocket_t sock;
struct sockaddr_in addr;
int opt = 1;
+ char err_buf[256];
/* create socket */
if ((sock.sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
- log_error2("Cannot create socket (%s)", strerror(errno));
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ log_error2("Cannot create socket (%s)", err_buf);
return herror_new("hsocket_bind", HSOCKET_ERROR_CREATE,
- "Socket error (%s)", strerror(errno));
+ "Socket error (%s)", err_buf);
}
setsockopt(sock.sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
@@ -271,9 +283,10 @@
if (bind(sock.sock, (struct sockaddr *) &addr, sizeof(struct sockaddr)) ==
-1)
{
- log_error2("Cannot bind socket (%s)", strerror(errno));
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ log_error2("Cannot bind socket (%s)", err_buf);
return herror_new("hsocket_bind", HSOCKET_ERROR_BIND, "Socket error (%s)",
- strerror(errno));
+ err_buf);
}
dsock->sock = sock.sock;
return H_OK;
@@ -294,8 +307,12 @@
if (sockfd.sock == INVALID_SOCKET)
{
if (WSAGetLastError() != WSAEWOULDBLOCK)
+ {
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT,
- "Socket error (%s)", strerror(errno));
+ "Socket error (%s)", err_buf);
+ }
}
else
{
@@ -318,10 +335,11 @@
if ((dest->sock =
accept(sock->sock, (struct sockaddr *) &(dest->addr), &len)) == -1)
{
- log_warn2("accept failed (%s)", strerror(errno));
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ log_warn2("accept failed (%s)", err_buf);
return herror_new("hsocket_accept", HSOCKET_ERROR_ACCEPT,
- "Cannot accept network connection (%s)",
- strerror(errno));
+ "Cannot accept network connection (%s)", err_buf);
}
return H_OK;
@@ -369,9 +387,11 @@
if (listen(sock->sock, 15) == -1)
{
- log_error2("listen failed (%s)", strerror(errno));
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ log_error2("listen failed (%s)", err_buf);
return herror_new("hsocket_listen", HSOCKET_ERROR_LISTEN,
- "Cannot listen on this socket (%s)", strerror(errno));
+ "Cannot listen on this socket (%s)", err_buf);
}
return H_OK;
diff -ru libcsoap-1.1.0.old/nanohttp/nanohttp-ssl.c libcsoap-1.1.0.new/nanohttp/nanohttp-ssl.c
--- libcsoap-1.1.0.old/nanohttp/nanohttp-ssl.c 2009-06-16 10:06:16.000000000 +1000
+++ libcsoap-1.1.0.new/nanohttp/nanohttp-ssl.c 2009-06-16 12:04:03.000000000 +1000
@@ -112,25 +112,27 @@
switch (SSL_get_error(ssl, ret))
{
case SSL_ERROR_NONE:
- return "None";
+ return strdup("None");
case SSL_ERROR_ZERO_RETURN:
- return "Zero return";
+ return strdup("Zero return");
case SSL_ERROR_WANT_READ:
- return "Want read";
+ return strdup("Want read");
case SSL_ERROR_WANT_WRITE:
- return "Want write";
+ return strdup("Want write");
case SSL_ERROR_WANT_X509_LOOKUP:
- return "Want x509 lookup";
+ return strdup("Want x509 lookup");
case SSL_ERROR_SYSCALL:
if (ERR_get_error() == 0 && ret == -1)
{
- return strerror(errno);
+ static char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ return strdup(err_buf);
}
- return "Syscall failed";
+ return strdup("Syscall failed");
case SSL_ERROR_SSL:
- return "SSL error";
+ return strdup("SSL error");
default:
- return "Unkown error";
+ return strdup("Unkown error");
}
}
@@ -421,10 +423,12 @@
{
herror_t err;
- log_error2("SSL connect error (%s)", _hssl_get_error(ssl, -1));
+ char *tmp = _hssl_get_error(ssl, ret);
+ log_error2("SSL connect error (%s)", tmp);
err =
herror_new("hssl_client_ssl", HSSL_ERROR_CONNECT,
- "SSL_connect failed (%s)", _hssl_get_error(ssl, ret));
+ "SSL_connect failed (%s)", tmp);
+ free(tmp);
SSL_free(ssl);
return err;
}
@@ -488,11 +492,13 @@
{
herror_t err;
- log_error2("SSL_accept failed (%s)", _hssl_get_error(ssl, ret));
+ char *tmp = _hssl_get_error(ssl, ret);
+ log_error2("SSL_accept failed (%s)", tmp);
err =
herror_new("hssl_server_ssl", HSSL_ERROR_SERVER,
- "SSL_accept failed (%s)", _hssl_get_error(ssl, ret));
+ "SSL_accept failed (%s)", tmp);
+ free(tmp);
SSL_free(ssl);
return err;
@@ -527,15 +533,23 @@
if (sock->ssl)
{
if ((count = SSL_read(sock->ssl, buf, len)) < 1)
- return herror_new("SSL_read", HSOCKET_ERROR_RECEIVE,
- "SSL_read failed (%s)", _hssl_get_error(sock->ssl,
- count));
+ {
+ char *tmp = _hssl_get_error(sock->ssl, count);
+ herror_t herr = herror_new("SSL_read", HSOCKET_ERROR_RECEIVE,
+ "SSL_read failed (%s)", tmp);
+ free(tmp);
+ return herr;
+ }
}
else
{
if ((count = hsocket_select_read(sock->sock, buf, len)) == -1)
+ {
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hssl_read", HSOCKET_ERROR_RECEIVE,
- "recv failed (%s)", strerror(errno));
+ "recv failed (%s)", err_buf);
+ }
}
*received = count;
@@ -566,15 +580,23 @@
if (sock->ssl)
{
if ((count = SSL_write(sock->ssl, buf, len)) == -1)
- return herror_new("SSL_write", HSOCKET_ERROR_SEND,
- "SSL_write failed (%s)", _hssl_get_error(sock->ssl,
- count));
+ {
+ char *tmp = _hssl_get_error(sock->ssl, count);
+ herror_t herr = herror_new("SSL_write", HSOCKET_ERROR_SEND,
+ "SSL_write failed (%s)", tmp);
+ free(tmp);
+ return herr;
+ }
}
else
{
if ((count = send(sock->sock, buf, len, 0)) == -1)
+ {
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hssl_write", HSOCKET_ERROR_SEND, "send failed (%s)",
- strerror(errno));
+ err_buf);
+ }
}
*sent = count;
@@ -589,8 +611,12 @@
int count;
if ((count = hsocket_select_read(sock->sock, buf, len)) == -1)
+ {
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hssl_read", HSOCKET_ERROR_RECEIVE, "recv failed (%s)",
- strerror(errno));
+ err_buf);
+ }
*received = count;
return H_OK;
}
@@ -615,8 +641,12 @@
return herror_new("hssl_write", HSOCKET_ERROR_SEND, "select error");
if ((count = send(sock->sock, buf, len, 0)) == -1)
+ {
+ char err_buf[256];
+ strerror_r(errno, err_buf, sizeof(err_buf));
return herror_new("hssl_write", HSOCKET_ERROR_SEND, "send failed (%s)",
- strerror(errno));
+ err_buf);
+ }
*sent = count;
return H_OK;
}
diff -ru libcsoap-1.1.0.old/nanohttp/nanohttp-stream.c libcsoap-1.1.0.new/nanohttp/nanohttp-stream.c
--- libcsoap-1.1.0.old/nanohttp/nanohttp-stream.c 2006-07-10 02:24:19.000000000 +1000
+++ libcsoap-1.1.0.new/nanohttp/nanohttp-stream.c 2009-06-16 12:02:51.000000000 +1000
@@ -88,7 +88,7 @@
/* Create object */
if (!(result = (http_input_stream_t *) malloc(sizeof(http_input_stream_t))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
return NULL;
}
@@ -136,16 +136,17 @@
http_input_stream_t *result;
FILE *fd;
+ char err_buf[256];
if (!(fd = fopen(filename, "rb"))) {
-
- log_error2("fopen failed (%s)", strerror(errno));
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ log_error2("fopen failed (%s)", err_buf);
return NULL;
}
/* Create object */
if (!(result = (http_input_stream_t *) malloc(sizeof(http_input_stream_t))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+ log_error1("malloc failed");
fclose(fd);
return NULL;
}
@@ -519,7 +520,8 @@
/* Create object */
if (!(result = (http_output_stream_t *) malloc(sizeof(http_output_stream_t))))
{
- log_error2("malloc failed (%s)", strerror(errno));
+
+ log_error1("malloc failed");
return NULL;
}