You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2015/01/01 22:34:22 UTC
svn commit: r1648948 - in /tomcat/jk/trunk: native/common/jk_ajp_common.c
native/common/jk_connect.c native/common/jk_connect.h
native/common/jk_status.c xdocs/miscellaneous/changelog.xml
Author: rjung
Date: Thu Jan 1 21:34:22 2015
New Revision: 1648948
URL: http://svn.apache.org/r1648948
Log:
BZ 56452: Fix crash in debug logging for IPv6 adresses.
Modified:
tomcat/jk/trunk/native/common/jk_ajp_common.c
tomcat/jk/trunk/native/common/jk_connect.c
tomcat/jk/trunk/native/common/jk_connect.h
tomcat/jk/trunk/native/common/jk_status.c
tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml
Modified: tomcat/jk/trunk/native/common/jk_ajp_common.c
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_ajp_common.c?rev=1648948&r1=1648947&r2=1648948&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_ajp_common.c (original)
+++ tomcat/jk/trunk/native/common/jk_ajp_common.c Thu Jan 1 21:34:22 2015
@@ -1050,7 +1050,7 @@ int ajp_connect_to_endpoint(ajp_endpoint
ae->last_errno = errno;
jk_log(l, JK_LOG_INFO,
"(%s) Failed opening socket to (%s) (errno=%d)",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)),
ae->last_errno);
JK_TRACE_EXIT(l);
return JK_FALSE;
@@ -1323,7 +1323,7 @@ int ajp_connection_tcp_get_message(ajp_e
jk_log(l, JK_LOG_INFO,
"(%s) can't receive the response header message from tomcat, "
"tomcat (%s) has forced a connection close for socket %d",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)),
ae->sd);
}
else {
@@ -1331,7 +1331,7 @@ int ajp_connection_tcp_get_message(ajp_e
jk_log(l, JK_LOG_INFO,
"(%s) can't receive the response header message from tomcat, "
"network problems or tomcat (%s) is down (errno=%d)",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)),
ae->last_errno);
}
ajp_abort_endpoint(ae, JK_FALSE, l);
@@ -1347,13 +1347,13 @@ int ajp_connection_tcp_get_message(ajp_e
if (header == AJP14_SW_HEADER) {
jk_log(l, JK_LOG_ERROR,
"(%s) received AJP14 reply on an AJP13 connection from %s",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf));
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)));
}
else {
jk_log(l, JK_LOG_ERROR,
"(%s) wrong message format 0x%04x from %s",
ae->worker->name, header, jk_dump_hinfo(&ae->worker->worker_inet_addr,
- buf));
+ buf, sizeof(buf)));
}
/* We've got a protocol error.
* We can't trust this connection any more.
@@ -1369,13 +1369,13 @@ int ajp_connection_tcp_get_message(ajp_e
if (header == AJP13_SW_HEADER) {
jk_log(l, JK_LOG_ERROR,
"(%s) received AJP13 reply on an AJP14 connection from %s",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf));
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)));
}
else {
jk_log(l, JK_LOG_ERROR,
"(%s) wrong message format 0x%04x from %s",
ae->worker->name, header, jk_dump_hinfo(&ae->worker->worker_inet_addr,
- buf));
+ buf, sizeof(buf)));
}
/* We've got a protocol error.
* We can't trust this connection any more.
@@ -1393,7 +1393,7 @@ int ajp_connection_tcp_get_message(ajp_e
jk_log(l, JK_LOG_ERROR,
"(%s) wrong message size %d %d from %s",
ae->worker->name, msglen, msg->maxlen,
- jk_dump_hinfo(&ae->worker->worker_inet_addr, buf));
+ jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)));
/* We've got a protocol error.
* We can't trust this connection any more.
*/
@@ -1418,7 +1418,7 @@ int ajp_connection_tcp_get_message(ajp_e
jk_log(l, JK_LOG_ERROR,
"(%s) can't receive the response body message from tomcat, "
"tomcat (%s) has forced a connection close for socket %d",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)),
ae->sd);
}
else {
@@ -1426,7 +1426,7 @@ int ajp_connection_tcp_get_message(ajp_e
jk_log(l, JK_LOG_ERROR,
"(%s) can't receive the response body message from tomcat, "
"network problems or tomcat (%s) is down (errno=%d)",
- ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
+ ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf, sizeof(buf)),
ae->last_errno);
}
ajp_abort_endpoint(ae, JK_FALSE, l);
Modified: tomcat/jk/trunk/native/common/jk_connect.c
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_connect.c?rev=1648948&r1=1648947&r2=1648948&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_connect.c (original)
+++ tomcat/jk/trunk/native/common/jk_connect.c Thu Jan 1 21:34:22 2015
@@ -59,6 +59,17 @@ static apr_pool_t *jk_apr_pool = NULL;
#define USE_SOCK_CLOEXEC
#endif
+#ifndef INET6_ADDRSTRLEN
+/* Maximum size of an IPv6 address in ASCII */
+#define INET6_ADDRSTRLEN 46
+#endif
+
+/* 2 IPv6 adresses of length (INET6_ADDRSTRLEN-1)
+ * each suffixed with a ":" and a port (5 digits)
+ * plus " -> " plus terminating "\0"
+ */
+#define DUMP_SINFO_BUF_SZ (2 * (INET6_ADDRSTRLEN - 1 + 1 + 5) + 4 + 1)
+
#ifndef IN6ADDRSZ
#define IN6ADDRSZ 16
#endif
@@ -573,7 +584,7 @@ jk_sock_t jk_open_socket(jk_sockaddr_t *
int timeout, int connect_timeout,
int sock_buf, jk_logger_t *l)
{
- char buf[64];
+ char buf[DUMP_SINFO_BUF_SZ];
jk_sock_t sd;
int set = 1;
int ret = 0;
@@ -753,7 +764,7 @@ jk_sock_t jk_open_socket(jk_sockaddr_t *
if (JK_IS_DEBUG_LEVEL(l))
jk_log(l, JK_LOG_DEBUG,
"trying to connect socket %d to %s", sd,
- jk_dump_hinfo(addr, buf));
+ jk_dump_hinfo(addr, buf, sizeof(buf)));
/* Need more infos for BSD 4.4 and Unix 98 defines, for now only
iSeries when Unix98 is required at compil time */
@@ -771,14 +782,14 @@ iSeries when Unix98 is required at compi
if (ret) {
jk_log(l, JK_LOG_INFO,
"connect to %s failed (errno=%d)",
- jk_dump_hinfo(addr, buf), errno);
+ jk_dump_hinfo(addr, buf, sizeof(buf)), errno);
jk_close_socket(sd, l);
sd = JK_INVALID_SOCKET;
}
else {
if (JK_IS_DEBUG_LEVEL(l))
jk_log(l, JK_LOG_DEBUG, "socket %d [%s] connected",
- sd, jk_dump_sinfo(sd, buf));
+ sd, jk_dump_sinfo(sd, buf, sizeof(buf)));
}
JK_TRACE_EXIT(l);
return sd;
@@ -855,7 +866,7 @@ int jk_close_socket(jk_sock_t sd, jk_log
int jk_shutdown_socket(jk_sock_t sd, jk_logger_t *l)
{
char dummy[512];
- char buf[64];
+ char buf[DUMP_SINFO_BUF_SZ];
char *sb = NULL;
int rc = 0;
size_t rd = 0;
@@ -873,7 +884,7 @@ int jk_shutdown_socket(jk_sock_t sd, jk_
save_errno = errno;
if (JK_IS_DEBUG_LEVEL(l)) {
- sb = jk_dump_sinfo(sd, buf);
+ sb = jk_dump_sinfo(sd, buf, sizeof(buf));
jk_log(l, JK_LOG_DEBUG, "About to shutdown socket %d [%s]",
sd, sb);
}
@@ -1124,7 +1135,7 @@ static const char *inet_ntop6(const unsi
* Keep this in mind if you think this function should have been coded
* to use pointer overlays. All the world's not a VAX.
*/
- char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+ char tmp[INET6_ADDRSTRLEN], *tp;
struct { int base, len; } best = {-1, 0}, cur = {-1, 0};
unsigned int words[IN6ADDRSZ / INT16SZ];
int i;
@@ -1224,25 +1235,25 @@ static const char *inet_ntop6(const unsi
* dump a jk_sockaddr_t in A.B.C.D:P in ASCII buffer
*
*/
-char *jk_dump_hinfo(jk_sockaddr_t *saddr, char *buf)
+char *jk_dump_hinfo(jk_sockaddr_t *saddr, char *buf, size_t size)
{
char pb[8];
if (saddr->family == JK_INET) {
- inet_ntop4(saddr->ipaddr_ptr, buf, 16);
+ inet_ntop4(saddr->ipaddr_ptr, buf, size);
}
#if JK_HAVE_IPV6
else {
- inet_ntop6(saddr->ipaddr_ptr, buf, 64);
+ inet_ntop6(saddr->ipaddr_ptr, buf, size);
}
#endif
sprintf(pb, ":%d", saddr->port);
- strcat(buf, pb);
+ strncat(buf, pb, size - strlen(buf) - 1);
return buf;
}
-char *jk_dump_sinfo(jk_sock_t sd, char *buf)
+char *jk_dump_sinfo(jk_sock_t sd, char *buf, size_t size)
{
struct sockaddr rsaddr;
struct sockaddr lsaddr;
@@ -1256,36 +1267,38 @@ char *jk_dump_sinfo(jk_sock_t sd, char *
size_t ps;
if (lsaddr.sa_family == JK_INET) {
struct sockaddr_in *sa = (struct sockaddr_in *)&lsaddr;
- inet_ntop4((unsigned char *)&sa->sin_addr, buf, 16);
+ inet_ntop4((unsigned char *)&sa->sin_addr, buf, size);
sprintf(pb, ":%d", (unsigned int)htons(sa->sin_port));
}
#if JK_HAVE_IPV6
else {
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)&lsaddr;
- inet_ntop6((unsigned char *)&sa->sin6_addr, buf, 64);
+ inet_ntop6((unsigned char *)&sa->sin6_addr, buf, size);
sprintf(pb, ":%d", (unsigned int)htons(sa->sin6_port));
}
#endif
- strcat(buf, pb);
- strcat(buf, " -> ");
+ ps = strlen(buf);
+ strncat(buf, pb, size - ps - 1);
+ ps = strlen(buf);
+ strncat(buf, " -> ", size - ps - 1);
ps = strlen(buf);
if (rsaddr.sa_family == JK_INET) {
struct sockaddr_in *sa = (struct sockaddr_in *)&rsaddr;
- inet_ntop4((unsigned char *)&sa->sin_addr, buf + ps, 16);
+ inet_ntop4((unsigned char *)&sa->sin_addr, buf + ps, size - ps);
sprintf(pb, ":%d", (unsigned int)htons(sa->sin_port));
}
#if JK_HAVE_IPV6
else {
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)&rsaddr;
- inet_ntop6((unsigned char *)&sa->sin6_addr, buf + ps, 64);
+ inet_ntop6((unsigned char *)&sa->sin6_addr, buf + ps, size - ps);
sprintf(pb, ":%d", (unsigned int)htons(sa->sin6_port));
}
#endif
- strcat(buf, pb);
+ strncat(buf, pb, size - strlen(buf) - 1);
return buf;
}
}
- sprintf(buf, "errno=%d", errno);
+ snprintf(buf, size, "errno=%d", errno);
return buf;
}
@@ -1306,7 +1319,7 @@ int jk_is_input_event(jk_sock_t sd, int
struct pollfd fds;
int rc;
int save_errno;
- char buf[64];
+ char buf[DUMP_SINFO_BUF_SZ];
JK_TRACE_ENTER(l);
@@ -1323,7 +1336,7 @@ int jk_is_input_event(jk_sock_t sd, int
if (JK_IS_DEBUG_LEVEL(l)) {
jk_log(l, JK_LOG_DEBUG,
"timeout during poll on socket %d [%s] (timeout=%d)",
- sd, jk_dump_sinfo(sd, buf), timeout);
+ sd, jk_dump_sinfo(sd, buf, sizeof(buf)), timeout);
}
/* Timeout. Set the errno to timeout */
errno = ETIMEDOUT;
@@ -1335,7 +1348,7 @@ int jk_is_input_event(jk_sock_t sd, int
if (JK_IS_DEBUG_LEVEL(l)) {
jk_log(l, JK_LOG_DEBUG,
"error during poll on socket %d [%s] (errno=%d)",
- sd, jk_dump_sinfo(sd, buf), errno);
+ sd, jk_dump_sinfo(sd, buf, sizeof(buf)), errno);
}
errno = save_errno;
JK_TRACE_EXIT(l);
@@ -1346,7 +1359,7 @@ int jk_is_input_event(jk_sock_t sd, int
if (JK_IS_DEBUG_LEVEL(l)) {
jk_log(l, JK_LOG_DEBUG,
"error event during poll on socket %d [%s] (event=%d)",
- sd, jk_dump_sinfo(sd, buf), save_errno);
+ sd, jk_dump_sinfo(sd, buf, sizeof(buf)), save_errno);
}
errno = save_errno;
JK_TRACE_EXIT(l);
@@ -1363,7 +1376,7 @@ int jk_is_input_event(jk_sock_t sd, int
struct timeval tv;
int rc;
int save_errno;
- char buf[64];
+ char buf[DUMP_SINFO_BUF_SZ];
JK_TRACE_ENTER(l);
@@ -1381,7 +1394,7 @@ int jk_is_input_event(jk_sock_t sd, int
if (JK_IS_DEBUG_LEVEL(l)) {
jk_log(l, JK_LOG_DEBUG,
"timeout during select on socket %d [%s] (timeout=%d)",
- sd, jk_dump_sinfo(sd, buf), timeout);
+ sd, jk_dump_sinfo(sd, buf, sizeof(buf)), timeout);
}
/* Timeout. Set the errno to timeout */
#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
@@ -1397,7 +1410,7 @@ int jk_is_input_event(jk_sock_t sd, int
if (JK_IS_DEBUG_LEVEL(l)) {
jk_log(l, JK_LOG_DEBUG,
"error during select on socket %d [%s] (errno=%d)",
- sd, jk_dump_sinfo(sd, buf), errno);
+ sd, jk_dump_sinfo(sd, buf, sizeof(buf)), errno);
}
errno = save_errno;
JK_TRACE_EXIT(l);
Modified: tomcat/jk/trunk/native/common/jk_connect.h
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_connect.h?rev=1648948&r1=1648947&r2=1648948&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_connect.h (original)
+++ tomcat/jk/trunk/native/common/jk_connect.h Thu Jan 1 21:34:22 2015
@@ -55,9 +55,9 @@ int jk_tcp_socket_sendfull(jk_sock_t sd,
int jk_tcp_socket_recvfull(jk_sock_t sd, unsigned char *b, int len, jk_logger_t *l);
-char *jk_dump_hinfo(jk_sockaddr_t *saddr, char *buf);
+char *jk_dump_hinfo(jk_sockaddr_t *saddr, char *buf, size_t size);
-char *jk_dump_sinfo(jk_sock_t sd, char *buf);
+char *jk_dump_sinfo(jk_sock_t sd, char *buf, size_t size);
int jk_is_input_event(jk_sock_t sd, int timeout, jk_logger_t *l);
Modified: tomcat/jk/trunk/native/common/jk_status.c
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_status.c?rev=1648948&r1=1648947&r2=1648948&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_status.c (original)
+++ tomcat/jk/trunk/native/common/jk_status.c Thu Jan 1 21:34:22 2015
@@ -1732,10 +1732,10 @@ static void display_maps(jk_ws_service_t
JK_TRACE_EXIT(l);
}
-static const char *dump_ajp_addr(ajp_worker_t *aw, char *buf)
+static const char *dump_ajp_addr(ajp_worker_t *aw, char *buf, size_t size)
{
if (aw->port > 0)
- return jk_dump_hinfo(&aw->worker_inet_addr, buf);
+ return jk_dump_hinfo(&aw->worker_inet_addr, buf, size);
else {
if (aw->addr_sequence != aw->s->addr_sequence)
return "unresolved";
@@ -1760,7 +1760,7 @@ static void display_worker_ajp_conf_deta
aw->name,
status_worker_type(type),
aw->host,
- dump_ajp_addr(aw, buf),
+ dump_ajp_addr(aw, buf, sizeof(buf)),
aw->cache_timeout,
aw->connect_timeout,
aw->prepost_timeout,
@@ -1772,7 +1772,7 @@ static void display_worker_ajp_conf_deta
jk_printf(s, l, JK_STATUS_SHOW_AJP_CONF_ROW,
status_worker_type(type),
aw->host,
- dump_ajp_addr(aw, buf),
+ dump_ajp_addr(aw, buf, sizeof(buf)),
aw->cache_timeout,
aw->connect_timeout,
aw->prepost_timeout,
@@ -1919,7 +1919,7 @@ static void display_worker_ajp_details(j
}
jk_print_xml_att_string(s, l, off+2, "host", aw->host);
jk_print_xml_att_int(s, l, off+2, "port", aw->port);
- jk_print_xml_att_string(s, l, off+2, "address", dump_ajp_addr(aw, buf));
+ jk_print_xml_att_string(s, l, off+2, "address", dump_ajp_addr(aw, buf, sizeof(buf)));
jk_print_xml_att_int(s, l, off+2, "connection_pool_timeout", aw->cache_timeout);
jk_print_xml_att_int(s, l, off+2, "ping_timeout", aw->ping_timeout);
jk_print_xml_att_int(s, l, off+2, "connect_timeout", aw->connect_timeout);
@@ -1987,7 +1987,7 @@ static void display_worker_ajp_details(j
}
jk_printf(s, l, " host=%s", aw->host);
jk_printf(s, l, " port=%d", aw->port);
- jk_printf(s, l, " address=%s", dump_ajp_addr(aw, buf));
+ jk_printf(s, l, " address=%s", dump_ajp_addr(aw, buf, sizeof(buf)));
jk_printf(s, l, " connection_pool_timeout=%d", aw->cache_timeout);
jk_printf(s, l, " ping_timeout=%d", aw->ping_timeout);
jk_printf(s, l, " connect_timeout=%d", aw->connect_timeout);
@@ -2052,7 +2052,7 @@ static void display_worker_ajp_details(j
}
jk_print_prop_att_string(s, l, w, ajp_name, "host", aw->host);
jk_print_prop_att_int(s, l, w, ajp_name, "port", aw->port);
- jk_print_prop_att_string(s, l, w, ajp_name, "address", dump_ajp_addr(aw, buf));
+ jk_print_prop_att_string(s, l, w, ajp_name, "address", dump_ajp_addr(aw, buf, sizeof(buf)));
jk_print_prop_att_int(s, l, w, ajp_name, "connection_pool_timeout", aw->cache_timeout);
jk_print_prop_att_int(s, l, w, ajp_name, "ping_timeout", aw->ping_timeout);
jk_print_prop_att_int(s, l, w, ajp_name, "connect_timeout", aw->connect_timeout);
Modified: tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml?rev=1648948&r1=1648947&r2=1648948&view=diff
==============================================================================
--- tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml Thu Jan 1 21:34:22 2015
@@ -153,6 +153,10 @@
addresses via the status worker if the client encodes
":" as "%3A". Patch contributed by Christopher Schultz. (rjung)
</fix>
+ <fix>
+ <bug>56452</bug>: Fix crash in debug logging for IPv6 adresses.
+ Patch contributed by Christopher Schultz. (rjung)
+ </fix>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org