Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ PHP NEWS
. Fixed odbc_field_len(), odbc_field_scale() and odbc_field_type()
returning uninitialized memory when SQLColAttribute fails.
(Ilia Alshanetsky)
. odbc_error() and odbc_errormsg() now also report SQLColAttribute
failures. (Ilia Alshanetsky)

- PCNTL:
. Fixed the declared signature of pcntl_signal(), whose $restart_syscalls
Expand Down Expand Up @@ -106,6 +108,9 @@ PHP NEWS
- SimpleXML:
. Fixed writing to a dimension of the object returned by attributes() not
creating the attribute. (Ilia Alshanetsky)
. Fixed child elements of the element returned by
SimpleXMLElement::addChild() not being accessible by property name when
namespaces are involved. (Ilia Alshanetsky)

- Streams:
. Added so_rcvbuf and so_sndbuf stream socket context options, setting the
Expand Down
34 changes: 11 additions & 23 deletions ext/odbc/php_odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ PHP_MINFO_FUNCTION(odbc)
/* }}} */

/* {{{ odbc_sql_error */
void odbc_sql_error(ODBC_SQL_ERROR_PARAMS)
void odbc_sql_error(odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, const char *func, ...)
{
SQLINTEGER error; /* Not used */
SQLSMALLINT errormsgsize; /* Not used */
Expand Down Expand Up @@ -608,7 +608,14 @@ void odbc_sql_error(ODBC_SQL_ERROR_PARAMS)
memcpy(conn_resource->lasterrormsg, ODBCG(lasterrormsg), sizeof(ODBCG(lasterrormsg)));
}
if (func) {
php_error_docref(NULL, E_WARNING, "SQL error: %s, SQL state %s in %s", ODBCG(lasterrormsg), ODBCG(laststate), func);
va_list args;
char *desc;

va_start(args, func);
vspprintf(&desc, 0, func, args);
va_end(args);
php_error_docref(NULL, E_WARNING, "SQL error: %s, SQL state %s in %s", ODBCG(lasterrormsg), ODBCG(laststate), desc);
efree(desc);
} else {
php_error_docref(NULL, E_WARNING, "SQL error: %s, SQL state %s", ODBCG(lasterrormsg), ODBCG(laststate));
}
Expand Down Expand Up @@ -785,25 +792,6 @@ void odbc_transact(INTERNAL_FUNCTION_PARAMETERS, int type)
}
/* }}} */

static void odbc_colattribute_failed(odbc_result *result, zend_long pv_num)
{
#if defined(ODBCVER) && (ODBCVER >= 0x0300)
SQLINTEGER diag_error;
SQLCHAR diag_state[6];
SQLCHAR diag_text[128];

memset(diag_state, '\0', sizeof(diag_state));
memset(diag_text, '\0', sizeof(diag_text));
if (SQL_SUCCESS == SQLGetDiagRec(SQL_HANDLE_STMT, result->stmt, 1, diag_state, &diag_error, diag_text, sizeof(diag_text), NULL)) {
diag_state[sizeof(diag_state) - 1] = '\0';
diag_text[sizeof(diag_text) - 1] = '\0';
php_error_docref(NULL, E_WARNING, "SQLColAttribute failed for field #%d: [%s] %s", (int)pv_num, diag_state, diag_text);
return;
}
#endif
php_error_docref(NULL, E_WARNING, "SQLColAttribute failed for field #%d", (int)pv_num);
}

/* {{{ odbc_column_lengths */
void odbc_column_lengths(INTERNAL_FUNCTION_PARAMETERS, int type)
{
Expand Down Expand Up @@ -836,7 +824,7 @@ void odbc_column_lengths(INTERNAL_FUNCTION_PARAMETERS, int type)

rc = SQLColAttribute(result->stmt, (SQLUSMALLINT)pv_num, (SQLUSMALLINT)(type ? SQL_COLUMN_SCALE : SQL_COLUMN_PRECISION), NULL, 0, NULL, &len);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
odbc_colattribute_failed(result, pv_num);
odbc_sql_error(result->conn_ptr, result->stmt, "SQLColAttribute column #" ZEND_LONG_FMT, pv_num);
len = 0;
}

Expand Down Expand Up @@ -2368,7 +2356,7 @@ PHP_FUNCTION(odbc_field_type)
tmp[0] = '\0';
rc = SQLColAttribute(result->stmt, (SQLUSMALLINT)pv_num, SQL_COLUMN_TYPE_NAME, tmp, sizeof(tmp) - 1, &tmplen, NULL);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
odbc_colattribute_failed(result, pv_num);
odbc_sql_error(result->conn_ptr, result->stmt, "SQLColAttribute column #" ZEND_LONG_FMT, pv_num);
RETURN_FALSE;
}

Expand Down
4 changes: 1 addition & 3 deletions ext/odbc/php_odbc_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ odbc_connection *odbc_get_conn(HashTable *list, int count);
void odbc_del_conn(HashTable *list, int ind);
void odbc_bindcols(odbc_result *result);

#define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func

void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);
void odbc_sql_error(odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, const char *func, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);

#define IS_SQL_LONG(x) (x == SQL_LONGVARBINARY || x == SQL_LONGVARCHAR || x == SQL_WLONGVARCHAR)

Expand Down
7 changes: 6 additions & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@ PHP_METHOD(SimpleXMLElement, addChild)
xmlNsPtr nsptr = NULL;
xmlChar *localname, *prefix = NULL;
bool free_localname = false;
const xmlChar *retprefix = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!",
&qname, &qname_len, &value, &value_len, &nsuri, &nsuri_len) == FAILURE) {
Expand Down Expand Up @@ -1721,7 +1722,11 @@ PHP_METHOD(SimpleXMLElement, addChild)
}
}

node_as_zval_str(sxe, newnode, return_value, SXE_ITER_NONE, localname, prefix, 0);
if ((prefix != NULL || nsuri != NULL) && newnode->ns != NULL) {
retprefix = newnode->ns->prefix;
}

node_as_zval_str(sxe, newnode, return_value, SXE_ITER_NONE, localname, retprefix, 1);

if (free_localname) {
xmlFree(localname);
Expand Down
56 changes: 56 additions & 0 deletions ext/simplexml/tests/addChild_ns_filter_returned_element.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--TEST--
SimpleXMLElement::addChild() wrong namespace filter on returned element
--EXTENSIONS--
simplexml
--FILE--
<?php
$x = new SimpleXMLElement('<r xmlns:a="http://example.com"/>');
$c = $x->addChild('a:kid', null, 'http://example.com');
$c->addChild('inner', 'v');
echo trim($x->asXML()), "\n";
echo (string) $c->inner, "\n";
var_dump(isset($c->inner));

$y = new SimpleXMLElement('<r xmlns:a="http://example.com"/>');
$d = $y->addChild('kid', null, 'http://example.com');
$d->addChild('inner', 'w');
echo trim($y->asXML()), "\n";
echo (string) $d->inner, "\n";

$z = new SimpleXMLElement('<r/>');
$e = $z->addChild('a:kid');
$e->addChild('inner', 'z');
echo trim($z->asXML()), "\n";
echo (string) $e->inner, "\n";
var_dump(isset($e->inner));

$q = new SimpleXMLElement('<p:r xmlns:p="http://example.com/p"/>');
$f = $q->addChild('kid');
$f->addAttribute('id', '7');
echo trim($q->asXML()), "\n";
echo (string) $f['id'], "\n";

$m = new SimpleXMLElement('<r xmlns:a="http://example.com"/>');
$g = $m->addChild('kid', null, 'http://example.com');
$g->addAttribute('id', '8');
echo trim($m->asXML()), "\n";
var_dump(isset($g['id']));
?>
--EXPECT--
<?xml version="1.0"?>
<r xmlns:a="http://example.com"><a:kid><a:inner>v</a:inner></a:kid></r>
v
bool(true)
<?xml version="1.0"?>
<r xmlns:a="http://example.com"><a:kid><a:inner>w</a:inner></a:kid></r>
w
<?xml version="1.0"?>
<r><kid><inner>z</inner></kid></r>
z
bool(true)
<?xml version="1.0"?>
<p:r xmlns:p="http://example.com/p"><p:kid id="7"/></p:r>
7
<?xml version="1.0"?>
<r xmlns:a="http://example.com"><a:kid id="8"/></r>
bool(false)