Bug 33308

Summary: mod_jk 1.2.8 segfaults when ForwardDirectories is enabled
Product: Tomcat Connectors Reporter: Christopher G. Stach II <cstach-asf>
Component: CommonAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Christopher G. Stach II 2005-01-31 08:06:56 UTC
Apache version apache-1.3.27-9.ent.src.rpm (RedHat ES 2.1)
Tomcat version 5.5.4
Sun JDK 1.5.0_01
mod_jk 1.2.8 (local AJP 1.3 through loadbalancer)

The webapps are local to apache, so the dirs are all readable.  mod_dir works 
properly.  When ForwardDirectories is not specified, it dumps index.html.  When 
ForwardDirectories is enabled, the httpd worker segfaults.  Specifying the 
index.jsp works properly.  Specifying index.html works, too.  Only after a 
successful search does it come to this.

Tomcat log:

DEBUG TP-Processor3 org.apache.jk.common.ChannelSocket - read() [B@7c7894 8192 
0 4 = -1
DEBUG TP-Processor3 org.apache.jk.common.ChannelSocket - server has been 
restarted or reset this connection

jk log:

[Mon Jan 31 02:01:50 2005] [12751:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (671): enter
[Mon Jan 31 02:01:50 2005] [12751:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (700): Attempting to map URI '/WEBAPP' 
from 3 maps
[Mon Jan 31 02:01:50 2005] [12751:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (559): enter
[Mon Jan 31 02:01:50 2005] [12751:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (656): exit
[Mon Jan 31 02:01:50 2005] [12751:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (718): Attempting to map context 
URI '/*.jsp'
[Mon Jan 31 02:01:50 2005] [12751:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (845): exit
[Mon Jan 31 02:01:50 2005] [12751:0] [debug] jk_translate::mod_jk.c (1955): 
mod_jk::jk_translate, check alias_dir: /com/webapps
[Mon Jan 31 02:01:50 2005] [12751:0] [debug] jk_translate::mod_jk.c (2011): 
mod_jk::jk_translate, AutoAlias OK for file: /com/webapps/WEBAPP
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (671): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (700): Attempting to map URI '/WEBAPP/' 
from 3 maps
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (559): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (656): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (718): Attempting to map context 
URI '/*.jsp'
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (845): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (1955): 
mod_jk::jk_translate, check alias_dir: /com/webapps
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (1980): 
mod_jk::jk_translate, AutoAlias child_dir: 
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (2011): 
mod_jk::jk_translate, AutoAlias OK for file: /com/webapps/WEBAPP/
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (671): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (700): Attempting to map 
URI '/WEBAPP/index.jsp' from 3 maps
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (559): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (656): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (718): Attempting to map context 
URI '/*.jsp'
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (808): Found a suffix match lb1 -> *.jsp
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (821): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (671): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (700): Attempting to map 
URI '/WEBAPP/index.php' from 3 maps
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (559): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (656): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (718): Attempting to map context 
URI '/*.jsp'
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (845): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (1955): 
mod_jk::jk_translate, check alias_dir: /com/webapps
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (1980): 
mod_jk::jk_translate, AutoAlias child_dir: index.php
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (2011): 
mod_jk::jk_translate, AutoAlias OK for file: /com/webapps/WEBAPP/index.php
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (671): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (700): Attempting to map 
URI '/WEBAPP/index.html' from 3 maps
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (559): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (656): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (718): Attempting to map context 
URI '/*.jsp'
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (845): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (1955): 
mod_jk::jk_translate, check alias_dir: /com/webapps
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (1980): 
mod_jk::jk_translate, AutoAlias child_dir: index.html
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] jk_translate::mod_jk.c (2011): 
mod_jk::jk_translate, AutoAlias OK for file: /com/webapps/WEBAPP/index.html
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (671): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (700): Attempting to map 
URI '/WEBAPP/index.html' from 3 maps
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (559): enter
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
is_nomap_match::jk_uri_worker_map.c (656): exit
[Mon Jan 31 02:01:50 2005] [12749:0] [debug] 
map_uri_to_worker::jk_uri_worker_map.c (718): Attempting to map context 
URI '/*.jsp'
[Mon Jan 31 02:01:50 2005] [12749:0] [trace] 
map_uri_to_worker::jk_uri_worker_map.c (845): exit

I'm a little too tired to track this down right now, but in case anyone else 
wants the stack trace to check it out:

[root@rx ~]# gdb /usr/sbin/httpd 12718
GNU gdb Red Hat Linux (5.3.90-0.20030710.41.2.1rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(no debugging symbols found)...Using host libthread_db 
library "/lib/libthread_db.so.1".

Attaching to program: /usr/sbin/httpd, process 12718
Reading symbols from /lib/i686/libpthread.so.0...done.
[Thread debugging using libthread_db enabled]
[New Thread 8192 (LWP 12718)]
Loaded symbols for /lib/i686/libpthread.so.0
Reading symbols from /lib/i686/libm.so.6...done.
Loaded symbols for /lib/i686/libm.so.6
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /lib/libdb-3.3.so...done.
Loaded symbols for /lib/libdb-3.3.so
Reading symbols from /usr/lib/libmm.so.11...done.
Loaded symbols for /usr/lib/libmm.so.11
Reading symbols from /usr/lib/libexpat.so.0...done.
Loaded symbols for /usr/lib/libexpat.so.0
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/i686/libc.so.6...done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libnss_files.so.2...done.
Loaded symbols for /lib/libnss_files.so.2
Reading symbols from /etc/httpd/modules/mod_vhost_alias.so...done.
Loaded symbols for /etc/httpd/modules/mod_vhost_alias.so
Reading symbols from /etc/httpd/modules/mod_env.so...done.
Loaded symbols for /etc/httpd/modules/mod_env.so
Reading symbols from /etc/httpd/modules/mod_log_config.so...done.
Loaded symbols for /etc/httpd/modules/mod_log_config.so
Reading symbols from /etc/httpd/modules/mod_log_agent.so...done.
Loaded symbols for /etc/httpd/modules/mod_log_agent.so
Reading symbols from /etc/httpd/modules/mod_log_referer.so...done.
Loaded symbols for /etc/httpd/modules/mod_log_referer.so
Reading symbols from /etc/httpd/modules/mod_mime.so...done.
Loaded symbols for /etc/httpd/modules/mod_mime.so
Reading symbols from /etc/httpd/modules/mod_negotiation.so...done.
Loaded symbols for /etc/httpd/modules/mod_negotiation.so
Reading symbols from /etc/httpd/modules/mod_status.so...done.
Loaded symbols for /etc/httpd/modules/mod_status.so
Reading symbols from /etc/httpd/modules/mod_info.so...done.
Loaded symbols for /etc/httpd/modules/mod_info.so
Reading symbols from /etc/httpd/modules/mod_include.so...done.
Loaded symbols for /etc/httpd/modules/mod_include.so
Reading symbols from /etc/httpd/modules/mod_autoindex.so...done.
Loaded symbols for /etc/httpd/modules/mod_autoindex.so
Reading symbols from /etc/httpd/modules/mod_dir.so...done.
Loaded symbols for /etc/httpd/modules/mod_dir.so
Reading symbols from /etc/httpd/modules/mod_cgi.so...done.
Loaded symbols for /etc/httpd/modules/mod_cgi.so
Reading symbols from /etc/httpd/modules/mod_asis.so...done.
Loaded symbols for /etc/httpd/modules/mod_asis.so
Reading symbols from /etc/httpd/modules/mod_imap.so...done.
Loaded symbols for /etc/httpd/modules/mod_imap.so
Reading symbols from /etc/httpd/modules/mod_actions.so...done.
Loaded symbols for /etc/httpd/modules/mod_actions.so
Reading symbols from /etc/httpd/modules/mod_userdir.so...done.
Loaded symbols for /etc/httpd/modules/mod_userdir.so
Reading symbols from /etc/httpd/modules/mod_alias.so...done.
Loaded symbols for /etc/httpd/modules/mod_alias.so
Reading symbols from /etc/httpd/modules/mod_rewrite.so...done.
Loaded symbols for /etc/httpd/modules/mod_rewrite.so
Reading symbols from /etc/httpd/modules/mod_access.so...done.
Loaded symbols for /etc/httpd/modules/mod_access.so
Reading symbols from /etc/httpd/modules/mod_auth.so...done.
Loaded symbols for /etc/httpd/modules/mod_auth.so
Reading symbols from /etc/httpd/modules/mod_auth_anon.so...done.
Loaded symbols for /etc/httpd/modules/mod_auth_anon.so
Reading symbols from /etc/httpd/modules/mod_auth_db.so...done.
Loaded symbols for /etc/httpd/modules/mod_auth_db.so
Reading symbols from /etc/httpd/modules/mod_expires.so...done.
Loaded symbols for /etc/httpd/modules/mod_expires.so
Reading symbols from /etc/httpd/modules/mod_headers.so...done.
Loaded symbols for /etc/httpd/modules/mod_headers.so
Reading symbols from /etc/httpd/modules/mod_setenvif.so...done.
Loaded symbols for /etc/httpd/modules/mod_setenvif.so
Reading symbols from /etc/httpd/modules/libperl.so...done.
Loaded symbols for /etc/httpd/modules/libperl.so
Reading symbols from /lib/libnsl.so.1...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libutil.so.1...done.
Loaded symbols for /lib/libutil.so.1
Reading symbols from /etc/httpd/modules/libphp4.so...done.
Loaded symbols for /etc/httpd/modules/libphp4.so
Reading symbols from /lib/libpam.so.0...done.
Loaded symbols for /lib/libpam.so.0
---Type <return> to continue, or q <return> to quit---
Reading symbols from /usr/lib/libltdl.so.3...done.
Loaded symbols for /usr/lib/libltdl.so.3
Reading symbols from /usr/lib/libpspell-modules.so.1...done.
Loaded symbols for /usr/lib/libpspell-modules.so.1
Reading symbols from /usr/lib/libstdc++-libc6.2-2.so.3...done.
Loaded symbols for /usr/lib/libstdc++-libc6.2-2.so.3
Reading symbols from /usr/lib/libz.so.1...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /lib/libcrypto.so.2...done.
Loaded symbols for /lib/libcrypto.so.2
Reading symbols from /lib/libssl.so.2...done.
Loaded symbols for /lib/libssl.so.2
Reading symbols from /lib/libresolv.so.2...done.
Loaded symbols for /lib/libresolv.so.2
Reading symbols from /usr/lib/libpspell.so.4...done.
Loaded symbols for /usr/lib/libpspell.so.4
Reading symbols from /usr/lib/libgmp.so.3...done.
Loaded symbols for /usr/lib/libgmp.so.3
Reading symbols from /usr/lib/libgd.so.1.8...done.
Loaded symbols for /usr/lib/libgd.so.1.8
Reading symbols from /usr/lib/libxml2.so.2...done.
Loaded symbols for /usr/lib/libxml2.so.2
Reading symbols from /usr/lib/libgdbm.so.2...done.
Loaded symbols for /usr/lib/libgdbm.so.2
Reading symbols from /usr/lib/libcurl.so.1...done.
Loaded symbols for /usr/lib/libcurl.so.1
Reading symbols from /usr/lib/libbz2.so.1...done.
Loaded symbols for /usr/lib/libbz2.so.1
Reading symbols from /usr/lib/libttf.so.2...done.
Loaded symbols for /usr/lib/libttf.so.2
Reading symbols from /usr/lib/libfreetype.so.6...done.
Loaded symbols for /usr/lib/libfreetype.so.6
Reading symbols from /usr/lib/libpng.so.2...done.
Loaded symbols for /usr/lib/libpng.so.2
Reading symbols from /usr/lib/libjpeg.so.62...done.
Loaded symbols for /usr/lib/libjpeg.so.62
Reading symbols from /etc/httpd/modules/libdav.so...done.
Loaded symbols for /etc/httpd/modules/libdav.so
Reading symbols from /etc/httpd/modules/libssl.so...done.
Loaded symbols for /etc/httpd/modules/libssl.so
Reading symbols from /etc/httpd/modules/mod_python.so...done.
Loaded symbols for /etc/httpd/modules/mod_python.so
Reading symbols from /etc/httpd/modules/mod_jk.so...done.
Loaded symbols for /etc/httpd/modules/mod_jk.so
Reading symbols from /usr/lib/php4/imap.so...done.
Loaded symbols for /usr/lib/php4/imap.so
Reading symbols from /usr/kerberos/lib/libgssapi_krb5.so.2...done.
Loaded symbols for /usr/kerberos/lib/libgssapi_krb5.so.2
Reading symbols from /usr/kerberos/lib/libkrb5.so.3...done.
Loaded symbols for /usr/kerberos/lib/libkrb5.so.3
Reading symbols from /usr/kerberos/lib/libk5crypto.so.3...done.
Loaded symbols for /usr/kerberos/lib/libk5crypto.so.3
Reading symbols from /usr/kerberos/lib/libcom_err.so.3...done.
Loaded symbols for /usr/kerberos/lib/libcom_err.so.3
Reading symbols from /usr/lib/php4/ldap.so...done.
Loaded symbols for /usr/lib/php4/ldap.so
Reading symbols from /usr/lib/libldap.so.2...done.
Loaded symbols for /usr/lib/libldap.so.2
Reading symbols from /usr/lib/liblber.so.2...done.
Loaded symbols for /usr/lib/liblber.so.2
Reading symbols from /usr/lib/libsasl.so.7...done.
Loaded symbols for /usr/lib/libsasl.so.7
Reading symbols from /usr/lib/php4/mysql.so...done.
Loaded symbols for /usr/lib/php4/mysql.so
Reading symbols from /usr/lib/mysql/libmysqlclient.so.10...done.
Loaded symbols for /usr/lib/mysql/libmysqlclient.so.10
Reading symbols from /usr/lib/php4/pgsql.so...done.
Loaded symbols for /usr/lib/php4/pgsql.so
Reading symbols from /usr/lib/libpq.so.2...done.
Loaded symbols for /usr/lib/libpq.so.2
Reading symbols from /lib/libnss_nisplus.so.2...done.
Loaded symbols for /lib/libnss_nisplus.so.2
0x40249ed2 in semop (semid=2064384, sops=0x8087870, nsops=1)
    at ../sysdeps/unix/sysv/linux/semop.c:36
36      ../sysdeps/unix/sysv/linux/semop.c: No such file or directory.
        in ../sysdeps/unix/sysv/linux/semop.c
(gdb) cont
Continuing.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 8192 (LWP 12718)]
0x40a2a3d6 in jk_translate (r=0x8127d68) at mod_jk.c:1936
1936    mod_jk.c: No such file or directory.
        in mod_jk.c
(gdb) where
#0  0x40a2a3d6 in jk_translate (r=0x8127d68) at mod_jk.c:1936
#1  0x08054762 in run_method ()
#2  0x080547c4 in ap_translate_name ()
#3  0x08067b13 in process_request_internal ()
#4  0x403c7d43 in handle_dir () from /etc/httpd/modules/mod_dir.so
#5  0x08054bad in ap_invoke_handler ()
#6  0x08067edc in process_request_internal ()
#7  0x08067f53 in ap_process_request ()
#8  0x08060067 in child_main ()
#9  0x080602a9 in make_child ()
#10 0x080605fb in perform_idle_server_maintenance ()
#11 0x08060b9c in standalone_main ()
#12 0x080612a3 in main ()
(gdb) list
1936                    r->prev && !strcmp(r->prev->handler, JK_HANDLER) &&
1937                    r->uri[strlen(r->uri) - 1] == '/') {
1938
1939                    /* Nothing here to do but assign the first worker since 
we
1940                     * already tried mapping and it didn't work out */
1941                    worker = worker_env.first_worker;
1942
1943                    jk_log(l, JK_LOG_DEBUG, "Manual configuration for %s %
s\n",
1944                           r->uri, worker_env.first_worker);
1945                }
Comment 1 Christopher G. Stach II 2005-02-09 23:29:55 UTC
I don't know why the handler isn't being set, but this patch remedies the 
segfault for now.

--- jakarta-tomcat-connectors-1.2.8-src.orig/jk/native/apache-1.3/mod_jk.c     
Fri Dec 24 05:18:10 2004
+++ jakarta-tomcat-connectors-1.2.8-src/jk/native/apache-1.3/mod_jk.c   Mon Jan 
31 16:41:58 2005
@@ -1933,7 +1933,8 @@
              * jk_fixups) and the request is for a directory:
              * --> forward to Tomcat, via default worker */
             if (!worker && (conf->options & JK_OPT_FWDDIRS) &&
-                r->prev && !strcmp(r->prev->handler, JK_HANDLER) &&
+                r->prev && r->prev->handler &&
+                !strcmp(r->prev->handler, JK_HANDLER) &&
                 r->uri[strlen(r->uri) - 1] == '/') {
 
                 /* Nothing here to do but assign the first worker since we
Comment 2 Mladen Turk 2005-02-10 08:19:34 UTC
Hi,
This has already been fixed in the CVS. Take a look at:
http://cvs.apache.org/viewcvs.cgi/jakarta-tomcat-connectors/jk/native/apache-
1.3/mod_jk.c?r1=1.61&r2=1.62&diff_format=h