From e7d20a0422ab62247834c5c97be022600225d259 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Fri, 22 Nov 2002 15:47:48 +0000 Subject: [PATCH] Make magic_quotes_runtime work bidirectional for dba --- ext/dba/dba.c | 17 +++++++++++++++-- ext/dba/tests/dba008.phpt | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ext/dba/dba.c b/ext/dba/dba.c index 23679c065c..c932e8affe 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -285,6 +285,8 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) { DBA_ID_PARS; zval **val, **key; + char *v; + int len; if(ac != 3 || zend_get_parameters_ex(ac, &key, &val, &id) != SUCCESS) { WRONG_PARAM_COUNT; @@ -295,8 +297,19 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) DBA_WRITE_CHECK; - if(info->hnd->update(info, VALLEN(key), VALLEN(val), mode TSRMLS_CC) == SUCCESS) - RETURN_TRUE; + if (PG(magic_quotes_runtime)) { + len = Z_STRLEN_PP(val); + v = estrndup(Z_STRVAL_PP(val), len); + php_stripslashes(v, &len TSRMLS_CC); + if(info->hnd->update(info, VALLEN(key), v, len, mode TSRMLS_CC) == SUCCESS) { + efree(v); + RETURN_TRUE; + } + efree(v); + } else { + if(info->hnd->update(info, VALLEN(key), VALLEN(val), mode TSRMLS_CC) == SUCCESS) + RETURN_TRUE; + } RETURN_FALSE; } /* }}} */ diff --git a/ext/dba/tests/dba008.phpt b/ext/dba/tests/dba008.phpt index 340131c30b..84a47ba083 100644 --- a/ext/dba/tests/dba008.phpt +++ b/ext/dba/tests/dba008.phpt @@ -10,11 +10,15 @@ DBA magic_quotes_runtime Test require_once('test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("key1", '"', $db_file); ini_set('magic_quotes_runtime', 0); + dba_insert("key1", '"', $db_file); var_dump(dba_fetch("key1", $db_file)); ini_set('magic_quotes_runtime', 1); var_dump(dba_fetch("key1", $db_file)); + dba_replace("key1", '\"', $db_file); + var_dump(dba_fetch("key1", $db_file)); + ini_set('magic_quotes_runtime', 0); + var_dump(dba_fetch("key1", $db_file)); dba_close($db_file); } else { echo "Error creating database\n"; @@ -24,3 +28,5 @@ DBA magic_quotes_runtime Test database handler: %s string(1) """ string(2) "\"" +string(2) "\"" +string(1) """ -- 2.40.0