Skip to content

Commit fb7d5bd

Browse files
committed
The fix for #35332 caused #35671 (and thus PECL #6504).
Partially back out that fix and introduce an extra optional step for drivers to canonicalize the "name" that is used for registering parameters.
1 parent 2030a7a commit fb7d5bd

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,14 @@ static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_s
323323
}
324324
return 0;
325325
}
326-
327-
/* tell the driver we just created a parameter */
326+
327+
/* ask the driver to perform any normalization it needs on the
328+
* parameter name. Note that it is illegal for the driver to take
329+
* a reference to param, as it resides in transient storage only
330+
* at this time. */
328331
if (stmt->methods->param_hook) {
329-
if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_ALLOC TSRMLS_CC)) {
332+
if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE
333+
TSRMLS_CC)) {
330334
if (param->name) {
331335
efree(param->name);
332336
param->name = NULL;
@@ -335,16 +339,36 @@ static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_s
335339
}
336340
}
337341

342+
/* delete any other parameter registered with this number.
343+
* If the parameter is named, it will be removed and correctly
344+
* disposed of by the hash_update call that follows */
338345
if (param->paramno >= 0) {
339346
zend_hash_index_del(hash, param->paramno);
340347
}
341-
348+
349+
/* allocate storage for the parameter, keyed by its "canonical" name */
342350
if (param->name) {
343-
zend_hash_update(hash, param->name, param->namelen, param, sizeof(*param), (void**)&pparam);
351+
zend_hash_update(hash, param->name, param->namelen, param,
352+
sizeof(*param), (void**)&pparam);
344353
} else {
345-
zend_hash_index_update(hash, param->paramno, param, sizeof(*param), (void**)&pparam);
354+
zend_hash_index_update(hash, param->paramno, param, sizeof(*param),
355+
(void**)&pparam);
346356
}
347357

358+
/* tell the driver we just created a parameter */
359+
if (stmt->methods->param_hook) {
360+
if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC
361+
TSRMLS_CC)) {
362+
/* undo storage allocation; the hash will free the parameter
363+
* name if required */
364+
if (pparam->name) {
365+
zend_hash_del(hash, pparam->name, pparam->namelen);
366+
} else {
367+
zend_hash_index_del(hash, pparam->paramno);
368+
}
369+
return 0;
370+
}
371+
}
348372
return 1;
349373
}
350374
/* }}} */

ext/pdo/php_pdo_driver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
4444
# define FALSE 0
4545
#endif
4646

47-
#define PDO_DRIVER_API 20051128
47+
#define PDO_DRIVER_API 20060327
4848

4949
enum pdo_param_type {
5050
PDO_PARAM_NULL,
@@ -338,7 +338,8 @@ enum pdo_param_event {
338338
PDO_PARAM_EVT_EXEC_PRE,
339339
PDO_PARAM_EVT_EXEC_POST,
340340
PDO_PARAM_EVT_FETCH_PRE,
341-
PDO_PARAM_EVT_FETCH_POST
341+
PDO_PARAM_EVT_FETCH_POST,
342+
PDO_PARAM_EVT_NORMALIZE
342343
};
343344

344345
typedef int (*pdo_stmt_param_hook_func)(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type TSRMLS_DC);

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
221221
}
222222
break;
223223

224-
case PDO_PARAM_EVT_ALLOC:
224+
case PDO_PARAM_EVT_NORMALIZE:
225225
/* decode name from $1, $2 into 0, 1 etc. */
226226
if (param->name) {
227227
if (param->name[0] == '$') {
@@ -240,6 +240,10 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
240240
}
241241
break;
242242

243+
case PDO_PARAM_EVT_ALLOC:
244+
/* work is handled by EVT_NORMALIZE */
245+
return 1;
246+
243247
case PDO_PARAM_EVT_EXEC_PRE:
244248
if (!S->param_values) {
245249
S->param_values = ecalloc(

0 commit comments

Comments
 (0)