summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Goldstein <cardoe@php.net>2007-03-22 21:50:34 +0000
committerDouglas Goldstein <cardoe@php.net>2007-03-22 21:50:34 +0000
commit4b39efa0ee347ec61ca6a50d6f34fcf988ff1db2 (patch)
treefcd30d3dddd68ca16be97759855e764588d10a40
parentd95939d566fcacc991543fbcc0ebefd5d69efbf5 (diff)
downloadphp-git-4b39efa0ee347ec61ca6a50d6f34fcf988ff1db2.tar.gz
Replaced all instances of ldap_get_values() with ldap_get_values_len(), which returns back the length of the data so on non-NULL terminated data we don't crash in a strlen(). Removed the PHP function ldap_get_values() since it's the same thing as ldap_get_values_len() now and made it alias ldap_get_values_len(). This should fix some random PHP<->LDAP crashes
-rw-r--r--ext/ldap/ldap.c63
1 files changed, 12 insertions, 51 deletions
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 781a5d7205..de2b9e8a7a 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -18,6 +18,7 @@
| Gerrit Thomson <334647@swin.edu.au> |
| Jani Taskinen <sniper@iki.fi> |
| Stig Venaas <venaas@uninett.no> |
+ | Doug Goldstein <cardoe@cardoe.com> |
| PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
@@ -117,7 +118,7 @@ zend_function_entry ldap_functions[] = {
PHP_FE(ldap_first_attribute, third_arg_force_ref)
PHP_FE(ldap_next_attribute, third_arg_force_ref)
PHP_FE(ldap_get_attributes, NULL)
- PHP_FE(ldap_get_values, NULL)
+ PHP_FALIAS(ldap_get_values, ldap_get_values_len, NULL)
PHP_FE(ldap_get_values_len, NULL)
PHP_FE(ldap_get_dn, NULL)
PHP_FE(ldap_explode_dn, NULL)
@@ -1036,7 +1037,7 @@ PHP_FUNCTION(ldap_get_entries)
BerElement *ber;
char *attribute;
size_t attr_len;
- char **ldap_value;
+ struct berval **ldap_value;
char *dn;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &link, &result) == FAILURE) {
@@ -1067,16 +1068,16 @@ PHP_FUNCTION(ldap_get_entries)
attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber);
while (attribute != NULL) {
- ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute);
- num_values = ldap_count_values(ldap_value);
+ ldap_value = ldap_get_values_len(ldap, ldap_result_entry, attribute);
+ num_values = ldap_count_values_len(ldap_value);
MAKE_STD_ZVAL(tmp2);
array_init(tmp2);
add_assoc_long(tmp2, "count", num_values);
for (i = 0; i < num_values; i++) {
- add_index_string(tmp2, i, ldap_value[i], 1);
+ add_index_stringl(tmp2, i, ldap_value[i]->bv_val, ldap_value[i]->bv_len, 1);
}
- ldap_value_free(ldap_value);
+ ldap_value_free_len(ldap_value);
attr_len = strlen(attribute);
zend_hash_update(Z_ARRVAL_P(tmp1), php_strtolower(attribute, attr_len), attr_len+1, (void *) &tmp2, sizeof(zval *), NULL);
@@ -1183,7 +1184,7 @@ PHP_FUNCTION(ldap_get_attributes)
ldap_linkdata *ld;
ldap_resultentry *resultentry;
char *attribute;
- char **ldap_value;
+ struct berval **ldap_value;
int i, num_values, num_attrib;
BerElement *ber;
@@ -1199,16 +1200,16 @@ PHP_FUNCTION(ldap_get_attributes)
attribute = ldap_first_attribute(ld->link, resultentry->data, &ber);
while (attribute != NULL) {
- ldap_value = ldap_get_values(ld->link, resultentry->data, attribute);
- num_values = ldap_count_values(ldap_value);
+ ldap_value = ldap_get_values_len(ld->link, resultentry->data, attribute);
+ num_values = ldap_count_values_len(ldap_value);
MAKE_STD_ZVAL(tmp);
array_init(tmp);
add_assoc_long(tmp, "count", num_values);
for (i = 0; i < num_values; i++) {
- add_index_string(tmp, i, ldap_value[i], 1);
+ add_index_stringl(tmp, i, ldap_value[i]->bv_val, ldap_value[i]->bv_len, 1);
}
- ldap_value_free(ldap_value);
+ ldap_value_free_len(ldap_value);
zend_hash_update(Z_ARRVAL_P(return_value), attribute, strlen(attribute)+1, (void *) &tmp, sizeof(zval *), NULL);
add_index_string(return_value, num_attrib, attribute, 1);
@@ -1229,46 +1230,6 @@ PHP_FUNCTION(ldap_get_attributes)
}
/* }}} */
-/* {{{ proto array ldap_get_values(resource link, resource result_entry, string attribute)
- Get all values from a result entry */
-PHP_FUNCTION(ldap_get_values)
-{
- zval **link, **result_entry, **attr;
- ldap_linkdata *ld;
- ldap_resultentry *resultentry;
- char *attribute;
- char **ldap_value;
- int i, num_values;
-
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &link, &result_entry, &attr) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, link, -1, "ldap link", le_link);
- ZEND_FETCH_RESOURCE(resultentry, ldap_resultentry *, result_entry, -1, "ldap result entry", le_result_entry);
-
- convert_to_string_ex(attr);
- attribute = Z_STRVAL_PP(attr);
-
- if ((ldap_value = ldap_get_values(ld->link, resultentry->data, attribute)) == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot get the value(s) of attribute %s", ldap_err2string(_get_lderrno(ld->link)));
- RETURN_FALSE;
- }
-
- num_values = ldap_count_values(ldap_value);
-
- array_init(return_value);
-
- for (i = 0; i<num_values; i++) {
- add_next_index_string(return_value, ldap_value[i], 1);
- }
-
- add_assoc_long(return_value, "count", num_values);
- ldap_value_free(ldap_value);
-
-}
-/* }}} */
-
/* {{{ proto array ldap_get_values_len(resource link, resource result_entry, string attribute)
Get all values with lengths from a result entry */
PHP_FUNCTION(ldap_get_values_len)