diff options
| author | Damien Regad <dregad@mantisbt.org> | 2018-03-30 19:29:59 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2018-03-30 19:29:59 +0200 |
| commit | 4011379abe34845d44612dbe904f435b6cd81d9f (patch) | |
| tree | e4c2e8a086ce635ad267c202fcb9a38b01dc2649 | |
| parent | 0f82a576c73172fcab8e9f03a5dedfc6fb9a01ec (diff) | |
| parent | 1377bc3f9ae50d935da2ff83784a6ff5640cba68 (diff) | |
| download | adodb-4011379abe34845d44612dbe904f435b6cd81d9f.tar.gz adodb-4011379abe34845d44612dbe904f435b6cd81d9f.tar.bz2 adodb-4011379abe34845d44612dbe904f435b6cd81d9f.zip | |
Merge branch 'hotfix/5.20'
Conflicts:
adodb.inc.php
docs/changelog.md
| -rw-r--r-- | adodb-pear.inc.php | 2 | ||||
| -rw-r--r-- | adodb-xmlschema.inc.php | 10 | ||||
| -rw-r--r-- | adodb-xmlschema03.inc.php | 10 | ||||
| -rw-r--r-- | adodb.inc.php | 54 | ||||
| -rw-r--r-- | docs/changelog.md | 9 | ||||
| -rw-r--r-- | drivers/adodb-ads.inc.php | 29 | ||||
| -rw-r--r-- | drivers/adodb-db2.inc.php | 13 | ||||
| -rw-r--r-- | drivers/adodb-odbc.inc.php | 25 | ||||
| -rw-r--r-- | drivers/adodb-odbc_oracle.inc.php | 10 | ||||
| -rw-r--r-- | drivers/adodb-odbtp.inc.php | 5 | ||||
| -rw-r--r-- | drivers/adodb-sybase.inc.php | 3 |
11 files changed, 110 insertions, 60 deletions
diff --git a/adodb-pear.inc.php b/adodb-pear.inc.php index 888f18f7..96de6e88 100644 --- a/adodb-pear.inc.php +++ b/adodb-pear.inc.php @@ -358,7 +358,7 @@ class DB */ function assertExtension($name) { - if (!extension_loaded($name)) { + if (function_exists('dl') && !extension_loaded($name)) { $dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so'; @dl($name . $dlext); } diff --git a/adodb-xmlschema.inc.php b/adodb-xmlschema.inc.php index ca5fa567..b53d4e28 100644 --- a/adodb-xmlschema.inc.php +++ b/adodb-xmlschema.inc.php @@ -1305,8 +1305,9 @@ class adoSchema { function __construct( $db ) { // Initialize the environment $this->mgq = get_magic_quotes_runtime(); - ini_set("magic_quotes_runtime", 0); - #set_magic_quotes_runtime(0); + if ($this->mgq !== false) { + ini_set('magic_quotes_runtime', 0); + } $this->db = $db; $this->debug = $this->db->debug; @@ -2195,8 +2196,9 @@ class adoSchema { * @deprecated adoSchema now cleans up automatically. */ function Destroy() { - ini_set("magic_quotes_runtime", $this->mgq ); - #set_magic_quotes_runtime( $this->mgq ); + if ($this->mgq !== false) { + ini_set('magic_quotes_runtime', $this->mgq ); + } } } diff --git a/adodb-xmlschema03.inc.php b/adodb-xmlschema03.inc.php index d8349683..a1f7a256 100644 --- a/adodb-xmlschema03.inc.php +++ b/adodb-xmlschema03.inc.php @@ -1409,8 +1409,9 @@ class adoSchema { function __construct( $db ) { // Initialize the environment $this->mgq = get_magic_quotes_runtime(); - #set_magic_quotes_runtime(0); - ini_set("magic_quotes_runtime", 0); + if ($this->mgq !== false) { + ini_set('magic_quotes_runtime', 0 ); + } $this->db = $db; $this->debug = $this->db->debug; @@ -2377,8 +2378,9 @@ class adoSchema { * @deprecated adoSchema now cleans up automatically. */ function Destroy() { - ini_set("magic_quotes_runtime", $this->mgq ); - #set_magic_quotes_runtime( $this->mgq ); + if ($this->mgq !== false) { + ini_set('magic_quotes_runtime', $this->mgq ); + } } } diff --git a/adodb.inc.php b/adodb.inc.php index d3ceb7cb..1a32e7d8 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -3194,6 +3194,60 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return $x; } + /** + * Get the last error recorded by PHP and clear the message. + * + * By clearing the message, it becomes possible to detect whether a new error + * has occurred, even when it is the same error as before being repeated. + * + * @return array|null Array if an error has previously occurred. Null otherwise. + */ + protected function resetLastError() { + $error = error_get_last(); + + if (is_array($error)) { + $error['message'] = ''; + } + + return $error; + } + + /** + * Compare a previously stored error message with the last error recorded by PHP + * to determine whether a new error has occured. + * + * @param array|null $old Optional. Previously stored return value of error_get_last(). + * + * @return string The error message if a new error has occured + * or an empty string if no (new) errors have occured.. + */ + protected function getChangedErrorMsg($old = null) { + $new = error_get_last(); + + if (is_null($new)) { + // No error has occured yet at all. + return ''; + } + + if (is_null($old)) { + // First error recorded. + return $new['message']; + } + + $changed = false; + foreach($new as $key => $value) { + if ($new[$key] !== $old[$key]) { + $changed = true; + break; + } + } + + if ($changed === true) { + return $new['message']; + } + + return ''; + } } // end class ADOConnection diff --git a/docs/changelog.md b/docs/changelog.md index 632d760d..e230cce9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -62,14 +62,21 @@ Older changelogs: - session: add 'httponly' flag to cookie. #190 - xml: support table 'opt' attribute with mysqli. #267 -## 5.20.11 - 30-Mar-2018 +## 5.20.12 - 30-Mar-2018 - adodb: PHP 7.2 compatibility - Replace each() with foreach. #373 - Replace deprecated create_function() calls. #404 - Replace $php_errormsg with error_get_last(). #405 +- adodb: Don't call `dl()` when the function is disabled #406 +- adodb: Don't bother with magic quotes when not available #407 - adodb: fix potential SQL injection vector in SelectLimit(). #190 #311 #401 +## 5.20.11 - Withdrawn + +This release has been withdrawn as it introduced a regression on PHP 5.x. +Please use version 5.20.12 or later. + ## 5.20.10 - 08-Mar-2018 - Fix year validation in adodb_validdate() #375 diff --git a/drivers/adodb-ads.inc.php b/drivers/adodb-ads.inc.php index c678c9de..8d31b219 100644 --- a/drivers/adodb-ads.inc.php +++ b/drivers/adodb-ads.inc.php @@ -80,11 +80,10 @@ class ADODB_ads extends ADOConnection { if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') { ADOConnection::outp("For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter."); } - error_clear_last(); + $last_php_error = $this->resetLastError(); if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword); else $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword,$this->curmode); - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); return $this->_connectionID != false; @@ -93,10 +92,10 @@ class ADODB_ads extends ADOConnection { // returns true or false function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) { - if (!function_exists('ads_connect')) return null; - error_clear_last(); + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; if ($this->debug && $argDatabasename) { ADOConnection::outp("For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); } @@ -104,8 +103,7 @@ class ADODB_ads extends ADOConnection { if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword); else $this->_connectionID = ads_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); if ($this->_connectionID && $this->autoRollback) @ads_rollback($this->_connectionID); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); @@ -517,8 +515,8 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od /* returns queryID or false */ function _query($sql,$inputarr=false) { - error_clear_last(); - $this->_error = ''; + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; if ($inputarr) { if (is_array($sql)) { @@ -527,8 +525,7 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $stmtid = ads_prepare($this->_connectionID,$sql); if ($stmtid == false) { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } } @@ -579,16 +576,14 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $this->_errorMsg = ''; $this->_errorCode = 0; } else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); } } else { if ($this->_haserrorfunctions) { $this->_errorMsg = ads_errormsg(); $this->_errorCode = ads_error(); } else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); } } @@ -607,11 +602,11 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od */ function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') { + $last_php_error = $this->resetLastError(); $sql = "UPDATE $table SET $column=? WHERE $where"; $stmtid = ads_prepare($this->_connectionID,$sql); if ($stmtid == false){ - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } if (! ads_execute($stmtid,array($val),array(SQL_BINARY) )){ diff --git a/drivers/adodb-db2.inc.php b/drivers/adodb-db2.inc.php index d5b92665..a56385d2 100644 --- a/drivers/adodb-db2.inc.php +++ b/drivers/adodb-db2.inc.php @@ -108,6 +108,8 @@ class ADODB_db2 extends ADOConnection { // Replaces the odbc_binmode() call that was in Execute() ini_set('ibm_db2.binmode', $this->binmode); + $this->_errorMsg = ''; + if ($argDatabasename && empty($argDSN)) { if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_pconnect($argDatabasename,null,null); @@ -619,7 +621,7 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 /* returns queryID or false */ function _query($sql,$inputarr=false) { - error_clear_last(); + $last_php_error = $this->resetLastError(); $this->_errorMsg = ''; if ($inputarr) { @@ -629,8 +631,7 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 $stmtid = db2_prepare($this->_connectionID,$sql); if ($stmtid == false) { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } } @@ -668,16 +669,14 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2 $this->_errorMsg = ''; $this->_errorCode = 0; } else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); } } else { if ($this->_haserrorfunctions) { $this->_errorMsg = db2_stmt_errormsg(); $this->_errorCode = db2_stmt_error(); } else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); } } return $stmtid; diff --git a/drivers/adodb-odbc.inc.php b/drivers/adodb-odbc.inc.php index 52b26307..8101dae5 100644 --- a/drivers/adodb-odbc.inc.php +++ b/drivers/adodb-odbc.inc.php @@ -76,11 +76,10 @@ class ADODB_odbc extends ADOConnection { $argDSN .= 'Database='.$argDatabasename; } - error_clear_last(); + $last_php_error = $this->resetLastError(); if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode); - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); return $this->_connectionID != false; @@ -89,10 +88,10 @@ class ADODB_odbc extends ADOConnection { // returns true or false function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) { - if (!function_exists('odbc_connect')) return null; - error_clear_last(); + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; if ($this->debug && $argDatabasename) { ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); } @@ -100,8 +99,7 @@ class ADODB_odbc extends ADOConnection { if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); @@ -527,8 +525,8 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od /* returns queryID or false */ function _query($sql,$inputarr=false) { - error_clear_last(); - $this->_error = ''; + $last_php_error = $this->resetLastError(); + $this->_errorMsg = ''; if ($inputarr) { if (is_array($sql)) { @@ -537,8 +535,7 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $stmtid = odbc_prepare($this->_connectionID,$sql); if ($stmtid == false) { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } } @@ -580,16 +577,14 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/od $this->_errorMsg = ''; $this->_errorCode = 0; } else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); } } else { if ($this->_haserrorfunctions) { $this->_errorMsg = odbc_errormsg(); $this->_errorCode = odbc_error(); } else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); } } return $stmtid; diff --git a/drivers/adodb-odbc_oracle.inc.php b/drivers/adodb-odbc_oracle.inc.php index eb83c1ee..874c4ddd 100644 --- a/drivers/adodb-odbc_oracle.inc.php +++ b/drivers/adodb-odbc_oracle.inc.php @@ -76,10 +76,9 @@ class ADODB_odbc_oracle extends ADODB_odbc { // returns true or false function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) { - error_clear_last(); + $last_php_error = $this->resetLastError(); $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); @@ -88,10 +87,9 @@ class ADODB_odbc_oracle extends ADODB_odbc { // returns true or false function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) { - error_clear_last(); + $last_php_error = $this->resetLastError(); $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); diff --git a/drivers/adodb-odbtp.inc.php b/drivers/adodb-odbtp.inc.php index 6beec767..4214d0f6 100644 --- a/drivers/adodb-odbtp.inc.php +++ b/drivers/adodb-odbtp.inc.php @@ -605,7 +605,7 @@ class ADODB_odbtp extends ADOConnection{ function _query($sql,$inputarr=false) { - error_clear_last(); + $last_php_error = $this->resetLastError(); $this->_errorMsg = false; $this->_errorCode = false; @@ -615,8 +615,7 @@ class ADODB_odbtp extends ADOConnection{ } else { $stmtid = @odbtp_prepare($sql,$this->_connectionID); if ($stmtid == false) { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : ''; + $this->_errorMsg = $this->getChangedErrorMsg($last_php_error); return false; } } diff --git a/drivers/adodb-sybase.inc.php b/drivers/adodb-sybase.inc.php index 8604e24c..e53af531 100644 --- a/drivers/adodb-sybase.inc.php +++ b/drivers/adodb-sybase.inc.php @@ -114,8 +114,7 @@ class ADODB_sybase extends ADOConnection { if (function_exists('sybase_get_last_message')) $this->_errorMsg = sybase_get_last_message(); else { - $err = error_get_last(); - $this->_errorMsg = $err ? $err['message'] : 'SYBASE error messages not supported on this platform'; + $this->_errorMsg = 'SYBASE error messages not supported on this platform'; } return $this->_errorMsg; |
