php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31038 Segmentation fault on ocilogon
Submitted: 2004-12-09 16:01 UTC Modified: 2005-04-05 17:07 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:6 (100.0%)
Same OS:6 (100.0%)
From: damien dot harper at keops dot net Assigned: tony2001 (profile)
Status: Not a bug Package: OCI8 related
PHP Version: 4.3.10RC2 OS: Red Hat 8
Private report: No CVE-ID: None
 [2004-12-09 16:01 UTC] damien dot harper at keops dot net
Description:
------------
Apache crashes (segmentation fault) as soon as it encounters 
 the ocilogon instruction.
Everything works like a charm from command line!
sqlplus connects and queries without any errors.

For information :

Apache 2.0.52 compiled and installed with :
./configure -?enable-shared=max
make
make install

PHP 4.3.10RC2 (same problem with PHP 4.3.9) compiled and installed with :
./configure --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --prefix=/usr --with-config-file-path=/etc --disable-debug --enable-pic --enable-inline-optimization --with-curl --with-dom=/usr --with-exec-dir=/usr/bin --with-gettext --with-ncurses --with-regex=system --with-xml --with-expat-dir=/usr --with-zlib --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes --enable-safe-mode --enable-sockets --enable-track-vars --enable-trans-sid --with-pear=/usr/share/pear --with-mysql=shared --with-oci8=shared --enable-bcmath --with-apxs2=/usr/local/apache2/bin/apxs

make
make install

Oracle Client 9.2.0.1 (same problem with 9.2.0.2 and 9.2.0.3)

Oracle database is 8.1.6 (same problem with our test database which is Oracle 9i)


Reproduce code:
---------------
$username = "*****";
$passwd = "*****";
$host = "10.211.162.35";
$port = "1521";
$service = "SIRENET";
$db="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port)))(CONNECT_DATA=(SERVICE_NAME=$service)))";

$conn = OCILogon($username,$passwd,$db);
if (!$conn) {
   echo "Connection failed";
   echo "Error Message: [" . OCIError($conn) . "]";
   exit;
} else {
        echo "Connected!"."\n";

        $parse=OCIParse($conn,"select che_nocheval from cheval where rownum < 10"); 
 //     OCIDefineByName($parse,"che_nocheval",$che_nocheval);
        OCIExecute($parse,OCI_DEFAULT);
        echo "\nRecuperation de donnees\n";

        $nrows = ocifetchstatement($parse, $rs, 0, 100,OCI_NUM);

                                $resultTab = "";
                                $numCol = 0;

                                for ( $iRow = 0; $iRow < $nrows; $iRow++ ) {
                                        reset($rs);
                                        while ( $column = each($rs) ) {
                                                 $data = $column['value'];
                                                 $resultTab[$iRow][$numCol] = $data[$iRow];
                                                echo $iRow.'|'.$numCol.'|'.$resultTab[$iRow][$numCol];
                                                $numCol++;
                                        }
                                        $numCol = 0;
                                }
        OCIFreeStatement($parse);
        OCILogoff($conn);
}



Actual result:
--------------
Apache segfaults

Starting program: /usr/local/apache2/bin/httpd -X
[New Thread 8192 (LWP 2417)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 8192 (LWP 2417)]
0x4078fd5d in lxhcsn () from /home/oracle/OraHome1/lib/libclntsh.so.9.0
(gdb) bt
#0  0x4078fd5d in lxhcsn () from /home/oracle/OraHome1/lib/libclntsh.so.9.0
#1  0x40274837 in kpcsnevget () from /home/oracle/OraHome1/lib/libclntsh.so.9.0
#2  0x401ecae2 in OCINlsEnvironmentVariableGet () from /home/oracle/OraHome1/lib/libclntsh.so.9.0
#3  0x4113eb53 in _oci_open_session (server=0x8224cb8, username=0x821735c "sirenet", password=0x82174ec "sirenet", 
    persistent=0, exclusive=0, charset=0x4114595d "") at /root/kic_temp/php-4.3.9/ext/oci8/oci8.c:2183
#4  0x4113f9e6 in oci_do_connect (ht=3, return_value=0x82176d4, this_ptr=0x0, return_value_used=1, persistent=0, 
    exclusive=0) at /root/kic_temp/php-4.3.9/ext/oci8/oci8.c:2715
#5  0x41142d83 in zif_ocilogon (ht=3, return_value=0x82176d4, this_ptr=0x0, return_value_used=1)
    at /root/kic_temp/php-4.3.9/ext/oci8/oci8.c:4340
#6  0x40c8e866 in execute (op_array=0x8212914) at /root/kic_temp/php-4.3.9/Zend/zend_execute.c:1640
#7  0x40c81ea3 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /root/kic_temp/php-4.3.9/Zend/zend.c:891
#8  0x40c5c563 in php_execute_script (primary_file=0xbffff6d0) at /root/kic_temp/php-4.3.9/main/main.c:1735
#9  0x40c9315a in php_handler (r=0x820a698) at /root/kic_temp/php-4.3.9/sapi/apache2handler/sapi_apache2.c:540
#10 0x0807c902 in ap_run_handler (r=0x820a698) at config.c:152
#11 0x0807ce1a in ap_invoke_handler (r=0x820a698) at config.c:363
#12 0x0806c5d3 in ap_process_request (r=0x820a698) at http_request.c:246
#13 0x080686ad in ap_process_http_connection (c=0x82064b8) at http_core.c:250
#14 0x08085ba6 in ap_run_process_connection (c=0x82064b8) at connection.c:42
#15 0x0807b47b in child_main (child_num_arg=0) at prefork.c:609
#16 0x0807b626 in make_child (s=0x80ba0c8, slot=0) at prefork.c:649
#17 0x0807b67f in startup_children (number_to_start=8) at prefork.c:721
#18 0x0807bd8d in ap_mpm_run (_pconf=0x807ae44, plog=0x80eda70, s=0x80ba0c8) at prefork.c:940
#19 0x08080d42 in main (argc=2, argv=0xbffffa24) at main.c:617
#20 0x420158d4 in __libc_start_main () from /lib/i686/libc.so.6
(gdb) 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-11 14:42 UTC] sniper@php.net
Please check that you have properly setup the Oracle environment variables as mentioned here:

http://www.php.net/manual/en/ref.oci8.php

(check the user comments about setting it up!)

 [2004-12-13 10:18 UTC] damien dot harper at keops dot net
I tried several ways to set the environnement variables up :
  1. within /etc/profile (export VARIABLE=value)
  2. within apache start script (/usr/local/apache2/bin/apachectl)
  3. within the PHP script using PHP's putenv function

All these ones are set :
  ORACLE_HOME
  ORACLE_SID
  LD_PRELOAD
  LD_LIBRARY_PATH
  NLS_LANG
  ORA_NLS33

Still crashing...
 [2004-12-14 00:02 UTC] sniper@php.net
This is pure guess, but in file ext/oci8/oci8.c try changing the number 2 on line 2180 to 0 (zero) and recompile PHP.

Patch here:

Index: oci8.c
===================================================================
RCS file: /repository/php-src/ext/oci8/oci8.c,v
retrieving revision 1.183.2.16
diff -u -r1.183.2.16 oci8.c
--- oci8.c      3 Nov 2004 13:35:56 -0000       1.183.2.16
+++ oci8.c      13 Dec 2004 23:02:12 -0000
@@ -2177,7 +2177,7 @@
 
                /* Safe, charsetid is initialized to 0 */
                CALL_OCI(OCINlsEnvironmentVariableGet(&charsetid, 
-                               2, 
+                               0, 
                                OCI_NLS_CHARSET_ID, 
                                0,
                                &rsize));

 [2004-12-14 17:33 UTC] damien dot harper at keops dot net
I've just tried... still segmfaulting !

Tried other PHP compilation options but it's still the same !
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-zlib-dir=/usr/local --enable-force-cgi-redirect --disable-cgi --with-oci8=/home/oracle/OraHome1 --enable-sigchild --with-xml
I can't get it to work !

Will a Oracle 10g client will work ?
 [2004-12-14 18:32 UTC] damien dot harper at keops dot net
Isn't that MPM related ?
 [2004-12-14 18:45 UTC] tony2001@php.net
It works fine on a number of OSes, Web-servers etc.
And I still can't see how can I reproduce your problem, as it works perfect for me.
Try it with *officially* supported Apache version (as Apache2 is officially NOT recommended), try to run the same code using CLI version.

And, please, give me your environment variables values and other additional info, so I'll be able to debug it.
 [2004-12-14 18:54 UTC] damien dot harper at keops dot net
PHP 4.3.10RC2
Oracle 9 database
Oracle 9.2.0.1 client

Everything works fine using command line : php myscript.php gives me expected results

export ORACLE_SID="ORACLE9"
export ORACLE_HOME="/home/oracle/OraHome1"
export LD_LIBRARY_PATH="/home/oracle/OraHome1/lib"
export TNS_ADMIN="/home/oracle/OraHome1/network/admin/tnsnames.ora"
export NLS_LANG="English_America.WE8ISO8859P1"

here is the script :
<?php
include "queries/fonctionsDb.php";

$username = "sirenet";
$passwd = "sirenet";
$host = "172.16.0.7";
$port = "1521";
$service = "ORACLE9";

//$db="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port)))(CONNECT_DATA=(SERVICE_NAME=$service)))";
$db="SIRENET";
$conn = connection();
if (!$conn) {
   echo "Connection failed";
   echo "Error Message: [" . OCIError($conn) . "]";
   exit;
} else {
        echo "Connected!"."\n";

        $parse=OCIParse($conn,"select nom from chevaux");
        OCIExecute($parse,OCI_DEFAULT);
        echo "\nRecuperation de donnees\n";

        $nrows = ocifetchstatement($parse, $rs, 0, 100,OCI_NUM);
                                $resultTab = "";
                                $numCol = 0;
                                for ( $iRow = 0; $iRow < $nrows; $iRow++ ) {
                                        reset($rs);
                                        while ( $column = each($rs) ) {
                                                 $data = $column['value'];
                                                 $resultTab[$iRow][$numCol] = $data[$iRow];
                                                echo $iRow.'|'.$numCol.'|'.$resultTab[$iRow][$numCol];
                                                $numCol++;
                                        }
                                        $numCol = 0;
                                }
        OCIFreeStatement($parse);
deconnection($conn);
}
?>
 [2004-12-14 18:57 UTC] damien dot harper at keops dot net
Wooops, I forgot the interesting part of the included file fonctionsDb.php :

<?php 
...
function connection(){
        global $errorCode,$test;

        $host = "172.16.0.7";
        $port = "1521";
        $service = "ORACLE9";
        $user = "sirenet";
        $pwd = "sirenet";
        $db="(DESCRIPTION=(ADDRESS_LIST=
            (ADDRESS=(PROTOCOL=TCP)
              (HOST=$host)(PORT=$port)
            )
          )
           (CONNECT_DATA=(SERVICE_NAME=$service))
     )";

        if ($test==1){
                $conn = ocilogon($user,$pwd,$db);
        } else {
                $conn = @ocilogon($user,$pwd,$db);
        }
        if ($conn==""){
                $errorCode = 2;
        }
        return $conn;
}

function deconnection($conn){
        ocilogoff($conn);
}
...
?>
 [2004-12-14 19:33 UTC] tony2001@php.net
Are you able to try latest release from 5.0.x branch?
 [2004-12-14 19:52 UTC] damien dot harper at keops dot net
I'd prefer to stick with 4.x.x branch for compatibility.
It will be used on a production server and we can't loose time to check that everything is OK with PHP 5.x now.

Nobody has any idea how to solve this trouble ?
 [2004-12-14 22:00 UTC] tony2001@php.net
Give me some time for testing.
ATM I can tell only that Apache2 is not recommended for production environment and this will not be changed in the nearest future. At least, you should use prefork if you have to stick with Apache2.
 [2004-12-15 03:59 UTC] sniper@php.net
I bet it's still the same issue as always: missing environment variable definitions for webserver. (as it works fine with CLI..)

 [2004-12-15 12:01 UTC] damien dot harper at keops dot net
Well, I found what was wrong !
I must run apache with user oracle and group oinstall (oracle has been installed with oracle user in oinstall group)

Now everything is OK, thanks for your replies ;-)
 [2005-02-17 15:12 UTC] mp at ecetra dot com
It can't be the right solution, cause apache can run under apache, httpd, whatever user and use php oci libs. have you compiled/recompiled your apache and/or php? i ask because i encounter the same problem if the oracle libs used for compilations process differ from those in runtime environment (it can be, but must not)

cheers,
-michael
 [2005-04-05 17:07 UTC] tony2001@php.net
>It can't be the right solution, cause apache can run under apache.
Right and to do that you need to set all those environment vars, that was set for oracle user.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 17:01:31 2024 UTC