sixd            Sat Jun 30 03:02:10 2007 UTC

  Modified files:              
    /php-src/ext/pdo_oci        oci_driver.c oci_statement.c php_pdo_oci_int.h 
    /php-src/ext/pdo_oci/tests  pecl_bug_11345.phpt 
  Log:
  MFB: Fix Bug #11345 Seg fault after NLS environment initialization error
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/oci_driver.c?r1=1.31&r2=1.32&diff_format=u
Index: php-src/ext/pdo_oci/oci_driver.c
diff -u php-src/ext/pdo_oci/oci_driver.c:1.31 
php-src/ext/pdo_oci/oci_driver.c:1.32
--- php-src/ext/pdo_oci/oci_driver.c:1.31       Mon Jan  1 09:29:28 2007
+++ php-src/ext/pdo_oci/oci_driver.c    Sat Jun 30 03:02:10 2007
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: oci_driver.c,v 1.31 2007/01/01 09:29:28 sebastian Exp $ */
+/* $Id: oci_driver.c,v 1.32 2007/06/30 03:02:10 sixd Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -55,9 +55,10 @@
 }
 /* }}} */
 
-ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, 
sword status, const char *file, int line TSRMLS_DC) /* {{{ */
+ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, 
sword status, int isinit, const char *file, int line TSRMLS_DC) /* {{{ */
 {
        text errbuf[1024] = "<<Unknown>>";
+       char tmp_buf[2048];
        pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
        pdo_oci_error_info *einfo;
        pdo_oci_stmt *S = NULL;
@@ -83,77 +84,84 @@
        einfo->file = file;
        einfo->line = line;
        
-       switch (status) {
-               case OCI_SUCCESS:
-                       strcpy(*pdo_err, "00000");
-                       break;
-               case OCI_ERROR:
-                       OCIErrorGet(err, (ub4)1, NULL, &einfo->errcode, errbuf, 
(ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
-                       spprintf(&einfo->errmsg, 0, "%s: %s (%s:%d)", what, 
errbuf, file, line);
-                       break;
-               case OCI_SUCCESS_WITH_INFO:
-                       OCIErrorGet(err, (ub4)1, NULL, &einfo->errcode, errbuf, 
(ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
-                       spprintf(&einfo->errmsg, 0, "%s: OCI_SUCCESS_WITH_INFO: 
%s (%s:%d)", what, errbuf, file, line);
-                       break;
-               case OCI_NEED_DATA:
-                       spprintf(&einfo->errmsg, 0, "%s: OCI_NEED_DATA 
(%s:%d)", what, file, line);
-                       break;
-               case OCI_NO_DATA:
-                       spprintf(&einfo->errmsg, 0, "%s: OCI_NO_DATA (%s:%d)", 
what, file, line);
-                       break;
-               case OCI_INVALID_HANDLE:
-                       spprintf(&einfo->errmsg, 0, "%s: OCI_INVALID_HANDLE 
(%s:%d)", what, file, line);
-                       break;
-               case OCI_STILL_EXECUTING:
-                       spprintf(&einfo->errmsg, 0, "%s: OCI_STILL_EXECUTING 
(%s:%d)", what, file, line);
-                       break;
-               case OCI_CONTINUE:
-                       spprintf(&einfo->errmsg, 0, "%s: OCI_CONTINUE (%s:%d)", 
what, file, line);
-                       break;
+       if (isinit) { /* Initialization error */
+               strcpy(*pdo_err, "HY000");
+               slprintf(tmp_buf, sizeof(tmp_buf), "%s (%s:%d)", what, file, 
line);
+               einfo->errmsg = pestrdup(tmp_buf, dbh->is_persistent);
        }
-
-       if (einfo->errcode) {
-               switch (einfo->errcode) {
-                       case 1013:      /* user requested cancel of current 
operation */
-                               zend_bailout();
+       else {
+               switch (status) {
+                       case OCI_SUCCESS:
+                               strcpy(*pdo_err, "00000");
                                break;
-
-#if 0
-                       case 955:       /* ORA-00955: name is already used by 
an existing object */
-                               *pdo_err = PDO_ERR_ALREADY_EXISTS;
+                       case OCI_ERROR:
+                               OCIErrorGet(err, (ub4)1, NULL, &einfo->errcode, 
errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
+                               spprintf(&einfo->errmsg, 0, "%s: %s (%s:%d)", 
what, errbuf, file, line);
                                break;
-#endif
-
-                       case 12154:     /* ORA-12154: TNS:could not resolve 
service name */
-                               strcpy(*pdo_err, "42S02");
+                       case OCI_SUCCESS_WITH_INFO:
+                               OCIErrorGet(err, (ub4)1, NULL, &einfo->errcode, 
errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
+                               spprintf(&einfo->errmsg, 0, "%s: 
OCI_SUCCESS_WITH_INFO: %s (%s:%d)", what, errbuf, file, line);
                                break;
-                               
-                       case 22:        /* ORA-00022: invalid session id */
-                       case 1012:      /* ORA-01012: */
-                       case 3113:      /* ORA-03133: end of file on 
communication channel */
-                       case 604:
-                       case 1041:
-                               /* consider the connection closed */
-                               dbh->is_closed = 1;
-                               H->attached = 0;
-                               strcpy(*pdo_err, "01002"); /* FIXME */
+                       case OCI_NEED_DATA:
+                               spprintf(&einfo->errmsg, 0, "%s: OCI_NEED_DATA 
(%s:%d)", what, file, line);
+                               break;
+                       case OCI_NO_DATA:
+                               spprintf(&einfo->errmsg, 0, "%s: OCI_NO_DATA 
(%s:%d)", what, file, line);
+                               break;
+                       case OCI_INVALID_HANDLE:
+                               spprintf(&einfo->errmsg, 0, "%s: 
OCI_INVALID_HANDLE (%s:%d)", what, file, line);
+                               break;
+                       case OCI_STILL_EXECUTING:
+                               spprintf(&einfo->errmsg, 0, "%s: 
OCI_STILL_EXECUTING (%s:%d)", what, file, line);
+                               break;
+                       case OCI_CONTINUE:
+                               spprintf(&einfo->errmsg, 0, "%s: OCI_CONTINUE 
(%s:%d)", what, file, line);
                                break;
-
-                       default:
-                               strcpy(*pdo_err, "HY000");
                }
-       }
-
-       if (stmt) {
-               /* always propogate the error code back up to the dbh,
-                * so that we can catch the error information when execute
-                * is called via query.  See Bug #33707 */
-               if (H->einfo.errmsg) {
-                       pefree(H->einfo.errmsg, dbh->is_persistent);
+               
+               if (einfo->errcode) {
+                       switch (einfo->errcode) {
+                               case 1013:      /* user requested cancel of 
current operation */
+                                       zend_bailout();
+                                       break;
+                                       
+#if 0
+                               case 955:       /* ORA-00955: name is already 
used by an existing object */
+                                       *pdo_err = PDO_ERR_ALREADY_EXISTS;
+                                       break;
+#endif
+                                       
+                               case 12154:     /* ORA-12154: TNS:could not 
resolve service name */
+                                       strcpy(*pdo_err, "42S02");
+                                       break;
+                                       
+                               case 22:        /* ORA-00022: invalid session 
id */
+                               case 1012:      /* ORA-01012: */
+                               case 3113:      /* ORA-03133: end of file on 
communication channel */
+                               case 604:
+                               case 1041:
+                                       /* consider the connection closed */
+                                       dbh->is_closed = 1;
+                                       H->attached = 0;
+                                       strcpy(*pdo_err, "01002"); /* FIXME */
+                                       break;
+                                       
+                               default:
+                                       strcpy(*pdo_err, "HY000");
+                       }
+               }
+               
+               if (stmt) {
+                       /* always propogate the error code back up to the dbh,
+                        * so that we can catch the error information when 
execute
+                        * is called via query.  See Bug #33707 */
+                       if (H->einfo.errmsg) {
+                               pefree(H->einfo.errmsg, dbh->is_persistent);
+                       }
+                       H->einfo = *einfo;
+                       H->einfo.errmsg = einfo->errmsg ? 
pestrdup(einfo->errmsg, dbh->is_persistent) : NULL;
+                       strcpy(dbh->error_code, stmt->error_code);
                }
-               H->einfo = *einfo;
-               H->einfo.errmsg = einfo->errmsg ? pestrdup(einfo->errmsg, 
dbh->is_persistent) : NULL;
-               strcpy(dbh->error_code, stmt->error_code);
        }
 
        /* little mini hack so that we can use this code from the dbh ctor */
@@ -342,8 +350,6 @@
 
 static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int 
unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype  
TSRMLS_DC) /* {{{ */
 {
-       pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
-
        return 0;
 }
 /* }}} */
@@ -444,8 +450,14 @@
 #if HAVE_OCIENVNLSCREATE
        if (vars[0].optval) {
                H->charset = OCINlsCharSetNameToId(pdo_oci_Env, vars[0].optval);
-               if (H->charset) {
-                       OCIEnvNlsCreate(&H->env, PDO_OCI_INIT_MODE, 0, NULL, 
NULL, NULL, 0, NULL, H->charset, H->charset);
+               if (!H->charset) {
+                       oci_init_error("OCINlsCharSetNameToId: unknown 
character set name");
+                       goto cleanup;
+               } else {
+                       if (OCIEnvNlsCreate(&H->env, PDO_OCI_INIT_MODE, 0, 
NULL, NULL, NULL, 0, NULL, H->charset, H->charset) != OCI_SUCCESS) {
+                               oci_init_error("OCIEnvNlsCreate: Check the 
character set is valid and that PHP has access to Oracle libraries and NLS 
data");
+                               goto cleanup;
+                       }
                }
        }
 #endif
@@ -515,14 +527,14 @@
        /* Now fire up the session */
        H->last_err = OCISessionBegin(H->svc, H->err, H->session, 
OCI_CRED_RDBMS, OCI_DEFAULT); 
        if (H->last_err) {
-               oci_drv_error("OCISessionBegin:");
+               oci_drv_error("OCISessionBegin");
                goto cleanup;
        }
 
        /* set the server handle into service handle */
        H->last_err = OCIAttrSet(H->svc, OCI_HTYPE_SVCCTX, H->session, 0, 
OCI_ATTR_SESSION, H->err);
        if (H->last_err) {
-               oci_drv_error("OCIAttrSet: OCI_ATTR_SESSION:");
+               oci_drv_error("OCIAttrSet: OCI_ATTR_SESSION");
                goto cleanup;
        }
        
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/oci_statement.c?r1=1.22&r2=1.23&diff_format=u
Index: php-src/ext/pdo_oci/oci_statement.c
diff -u php-src/ext/pdo_oci/oci_statement.c:1.22 
php-src/ext/pdo_oci/oci_statement.c:1.23
--- php-src/ext/pdo_oci/oci_statement.c:1.22    Mon Jan  1 09:29:28 2007
+++ php-src/ext/pdo_oci/oci_statement.c Sat Jun 30 03:02:10 2007
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: oci_statement.c,v 1.22 2007/01/01 09:29:28 sebastian Exp $ */
+/* $Id: oci_statement.c,v 1.23 2007/06/30 03:02:10 sixd Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -31,19 +31,23 @@
 #include "php_pdo_oci_int.h"
 #include "Zend/zend_extensions.h"
 
-#define STMT_CALL(name, params)        \
-       S->last_err = name params; \
-       S->last_err = _oci_error(S->err, stmt->dbh, stmt, #name, S->last_err, 
__FILE__, __LINE__ TSRMLS_CC); \
-       if (S->last_err) { \
-               return 0; \
-       }
-
-#define STMT_CALL_MSG(name, msg, params)       \
-       S->last_err = name params; \
-       S->last_err = _oci_error(S->err, stmt->dbh, stmt, #name ": " #msg, 
S->last_err, __FILE__, __LINE__ TSRMLS_CC); \
-       if (S->last_err) { \
-               return 0; \
-       }
+#define STMT_CALL(name, params)                                                
                                        \
+       do {                                                                    
                                                        \
+               S->last_err = name params;                                      
                                        \
+               S->last_err = _oci_error(S->err, stmt->dbh, stmt, #name, 
S->last_err, FALSE, __FILE__, __LINE__ TSRMLS_CC); \
+               if (S->last_err) {                                              
                                                \
+                       return 0;                                               
                                                        \
+               }                                                               
                                                                \
+       } while(0)
+
+#define STMT_CALL_MSG(name, msg, params)                                       
                        \
+       do {                                                                    
                                                        \
+               S->last_err = name params;                                      
                                        \
+               S->last_err = _oci_error(S->err, stmt->dbh, stmt, #name ": " 
#msg, S->last_err, FALSE, __FILE__, __LINE__ TSRMLS_CC); \
+               if (S->last_err) {                                              
                                                \
+                       return 0;                                               
                                                        \
+               }                                                               
                                                                \
+       } while(0)
 
 
 static int oci_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/php_pdo_oci_int.h?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/pdo_oci/php_pdo_oci_int.h
diff -u php-src/ext/pdo_oci/php_pdo_oci_int.h:1.7 
php-src/ext/pdo_oci/php_pdo_oci_int.h:1.8
--- php-src/ext/pdo_oci/php_pdo_oci_int.h:1.7   Mon Jan  1 09:29:28 2007
+++ php-src/ext/pdo_oci/php_pdo_oci_int.h       Sat Jun 30 03:02:10 2007
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_oci_int.h,v 1.7 2007/01/01 09:29:28 sebastian Exp $ */
+/* $Id: php_pdo_oci_int.h,v 1.8 2007/06/30 03:02:10 sixd Exp $ */
 
 #include <oci.h>
 
@@ -83,9 +83,10 @@
 extern pdo_driver_t pdo_oci_driver;
 extern OCIEnv *pdo_oci_Env;
 
-ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, 
sword status, const char *file, int line TSRMLS_DC);
-#define oci_drv_error(w)       _oci_error(H->err, dbh, NULL, w, H->last_err, 
__FILE__, __LINE__ TSRMLS_CC)
-#define oci_stmt_error(w)      _oci_error(S->err, stmt->dbh, stmt, w, 
S->last_err, __FILE__, __LINE__ TSRMLS_CC)
+ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, 
sword status, int isinit, const char *file, int line TSRMLS_DC);
+#define oci_init_error(w)      _oci_error(H->err, dbh, NULL, w, H->last_err, 
TRUE, __FILE__, __LINE__ TSRMLS_CC)
+#define oci_drv_error(w)       _oci_error(H->err, dbh, NULL, w, H->last_err, 
FALSE, __FILE__, __LINE__ TSRMLS_CC)
+#define oci_stmt_error(w)      _oci_error(S->err, stmt->dbh, stmt, w, 
S->last_err, FALSE, __FILE__, __LINE__ TSRMLS_CC)
 
 extern struct pdo_stmt_methods oci_stmt_methods;
 
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/tests/pecl_bug_11345.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/pdo_oci/tests/pecl_bug_11345.phpt
diff -u /dev/null php-src/ext/pdo_oci/tests/pecl_bug_11345.phpt:1.2
--- /dev/null   Sat Jun 30 03:02:10 2007
+++ php-src/ext/pdo_oci/tests/pecl_bug_11345.phpt       Sat Jun 30 03:02:10 2007
@@ -0,0 +1,29 @@
+--TEST--
+PECL PDO_OCI Bug #11345 (Test invalid character set name)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not 
loaded');
+require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+// This tests only part of PECL bug 11345.  The other part - testing
+// when the National Language Support (NLS) environment can't be
+// initialized - is very difficult to test portably.
+
+try {
+    $dbh = new PDO('oci:dbname=xxx;charset=yyy', 'abc', 'def');
+} 
+catch (PDOException $e) {
+    echo 'Connection failed: ' . $e->getMessage(). "\n";
+    exit;
+}
+
+echo "Done\n";
+
+?>
+
+--EXPECTF--
+Connection failed: SQLSTATE[HY000]: OCINlsCharSetNameToId: unknown character 
set name (%s)
\ No newline at end of file

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to