@@ -3063,14 +3063,18 @@ PHP_FUNCTION(ldap_set_option)
3063
3063
case LDAP_OPT_X_KEEPALIVE_INTERVAL :
3064
3064
#endif
3065
3065
{
3066
- int val ;
3066
+ bool failed = false;
3067
+ zend_long lval = zval_try_get_long (newval , & failed );
3068
+ if (failed ) {
3069
+ zend_argument_type_error (3 , "must be of type int for the given option, %s given" , zend_zval_value_name (newval ));
3070
+ RETURN_THROWS ();
3071
+ }
3067
3072
3068
- convert_to_long (newval );
3069
- if (ZEND_LONG_EXCEEDS_INT (Z_LVAL_P (newval ))) {
3073
+ if (ZEND_LONG_EXCEEDS_INT (lval )) {
3070
3074
zend_argument_value_error (3 , "is too large" );
3071
3075
RETURN_THROWS ();
3072
3076
}
3073
- val = (int )Z_LVAL_P ( newval ) ;
3077
+ int val = (int )lval ;
3074
3078
if (ldap_set_option (ldap , option , & val )) {
3075
3079
RETURN_FALSE ;
3076
3080
}
@@ -3079,9 +3083,13 @@ PHP_FUNCTION(ldap_set_option)
3079
3083
case LDAP_OPT_NETWORK_TIMEOUT :
3080
3084
{
3081
3085
struct timeval timeout ;
3082
-
3083
- convert_to_long (newval );
3084
- timeout .tv_sec = Z_LVAL_P (newval );
3086
+ bool failed = false;
3087
+ zend_long lval = zval_try_get_long (newval , & failed );
3088
+ if (failed ) {
3089
+ zend_argument_type_error (3 , "must be of type int for the LDAP_OPT_NETWORK_TIMEOUT option, %s given" , zend_zval_value_name (newval ));
3090
+ RETURN_THROWS ();
3091
+ }
3092
+ timeout .tv_sec = lval ;
3085
3093
timeout .tv_usec = 0 ;
3086
3094
if (ldap_set_option (ldap , LDAP_OPT_NETWORK_TIMEOUT , (void * ) & timeout )) {
3087
3095
RETURN_FALSE ;
@@ -3091,9 +3099,13 @@ PHP_FUNCTION(ldap_set_option)
3091
3099
case LDAP_X_OPT_CONNECT_TIMEOUT :
3092
3100
{
3093
3101
int timeout ;
3094
-
3095
- convert_to_long (newval );
3096
- timeout = 1000 * Z_LVAL_P (newval ); /* Convert to milliseconds */
3102
+ bool failed = false;
3103
+ zend_long lval = zval_try_get_long (newval , & failed );
3104
+ if (failed ) {
3105
+ zend_argument_type_error (3 , "must be of type int for the LDAP_X_OPT_CONNECT_TIMEOUT option, %s given" , zend_zval_value_name (newval ));
3106
+ RETURN_THROWS ();
3107
+ }
3108
+ timeout = 1000 * lval ; /* Convert to milliseconds */
3097
3109
if (ldap_set_option (ldap , LDAP_X_OPT_CONNECT_TIMEOUT , & timeout )) {
3098
3110
RETURN_FALSE ;
3099
3111
}
@@ -3104,8 +3116,13 @@ PHP_FUNCTION(ldap_set_option)
3104
3116
{
3105
3117
struct timeval timeout ;
3106
3118
3107
- convert_to_long (newval );
3108
- timeout .tv_sec = Z_LVAL_P (newval );
3119
+ bool failed = false;
3120
+ zend_long lval = zval_try_get_long (newval , & failed );
3121
+ if (failed ) {
3122
+ zend_argument_type_error (3 , "must be of type int for the LDAP_OPT_TIMEOUT option, %s given" , zend_zval_value_name (newval ));
3123
+ RETURN_THROWS ();
3124
+ }
3125
+ timeout .tv_sec = lval ;
3109
3126
timeout .tv_usec = 0 ;
3110
3127
if (ldap_set_option (ldap , LDAP_OPT_TIMEOUT , (void * ) & timeout )) {
3111
3128
RETURN_FALSE ;
@@ -3141,9 +3158,8 @@ PHP_FUNCTION(ldap_set_option)
3141
3158
case LDAP_OPT_MATCHED_DN :
3142
3159
#endif
3143
3160
{
3144
- zend_string * val ;
3145
- val = zval_get_string (newval );
3146
- if (EG (exception )) {
3161
+ zend_string * val = zval_try_get_string (newval );
3162
+ if (val == NULL ) {
3147
3163
RETURN_THROWS ();
3148
3164
}
3149
3165
if (ldap_set_option (ldap , option , ZSTR_VAL (val ))) {
@@ -3161,8 +3177,7 @@ PHP_FUNCTION(ldap_set_option)
3161
3177
case LDAP_OPT_X_SASL_NOCANON :
3162
3178
#endif
3163
3179
{
3164
- void * val ;
3165
- val = zend_is_true (newval ) ? LDAP_OPT_ON : LDAP_OPT_OFF ;
3180
+ void * val = zend_is_true (newval ) ? LDAP_OPT_ON : LDAP_OPT_OFF ;
3166
3181
if (ldap_set_option (ldap , option , val )) {
3167
3182
RETURN_FALSE ;
3168
3183
}
0 commit comments