]> granicus.if.org Git - php/commitdiff
further datatype and range check fixes for ibase
authorAnatol Belski <ab@php.net>
Mon, 11 Jan 2016 08:46:53 +0000 (09:46 +0100)
committerAnatol Belski <ab@php.net>
Mon, 11 Jan 2016 08:46:53 +0000 (09:46 +0100)
ext/interbase/ibase_blobs.c
ext/interbase/ibase_events.c
ext/interbase/ibase_query.c
ext/interbase/ibase_service.c
ext/interbase/interbase.c
ext/interbase/php_ibase_includes.h
ext/interbase/php_ibase_udf.c

index 917210a219b8e24c14beaee5fb5b0f6e3efc99d3..70640236c3d0babb4b5ce8bb4a3737d2bbf8d65f 100644 (file)
@@ -90,13 +90,13 @@ typedef struct { /* {{{ */
 /* }}} */
 } IBASE_BLOBINFO;
 
-int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long max_len) /* {{{ */
+int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, zend_ulong max_len) /* {{{ */
 {
        if (ib_blob->bl_qd.gds_quad_high || ib_blob->bl_qd.gds_quad_low) { /*not null ?*/
 
                ISC_STATUS stat;
                zend_string *bl_data;
-               unsigned long cur_len;
+               zend_ulong cur_len;
                unsigned short seg_len;
 
                bl_data = zend_string_alloc(max_len, 0);
@@ -126,7 +126,7 @@ int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long m
 
 int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob) /* {{{ */
 {
-       unsigned long put_cnt = 0, rem_cnt;
+       zend_ulong put_cnt = 0, rem_cnt;
        unsigned short chunk_size;
 
        convert_to_string_ex(string_arg);
@@ -154,7 +154,7 @@ static int _php_ibase_blob_info(isc_blob_handle bl_handle, IBASE_BLOBINFO *bl_in
                isc_info_blob_type
        };
 
-       char bl_inf[sizeof(long)*8], *p;
+       char bl_inf[sizeof(zend_long)*8], *p;
 
        bl_info->max_segment = 0;
        bl_info->num_segments = 0;
index 27844fc73aef7ee83ab4b9a104667c54a43856c8..e748c643af570e385a12f4b1b71975398ff0b913 100644 (file)
@@ -93,7 +93,7 @@ static void _php_ibase_event_block(ibase_db_link *ib_link, unsigned short count,
        char **events, unsigned short *l, char **event_buf, char **result_buf)
 {
        ISC_STATUS dummy_result[20];
-       unsigned long dummy_count[15];
+       ISC_ULONG dummy_count[15];
 
        /**
         * Unfortunately, there's no clean and portable way in C to pass arguments to
@@ -131,7 +131,7 @@ PHP_FUNCTION(ibase_wait_event)
        int num_args;
        char *event_buffer, *result_buffer, *events[15];
        unsigned short i = 0, event_count = 0, buffer_size;
-       unsigned long occurred_event[15];
+       ISC_ULONG occurred_event[15];
 
        RESET_ERRMSG;
 
@@ -190,8 +190,15 @@ PHP_FUNCTION(ibase_wait_event)
 }
 /* }}} */
 
-static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
+#if FB_API_VER >= 20
+#define PHP_ISC_CALLBACK ISC_EVENT_CALLBACK
+static ISC_EVENT_CALLBACK _php_ibase_callback(ibase_event *event, /* {{{ */
+       ISC_USHORT buffer_size, ISC_UCHAR *result_buf)
+#else
+#define PHP_ISC_CALLBACK isc_callback
+static isc_callback  _php_ibase_callback(ibase_event *event, /* {{{ */
        unsigned short buffer_size, char *result_buf)
+#endif
 {
        /* this function is called asynchronously by the Interbase client library. */
        TSRMLS_FETCH_FROM_CTX(event->thread_ctx);
@@ -203,7 +210,7 @@ static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
         */
        switch (event->state) {
                unsigned short i;
-               unsigned long occurred_event[15];
+               ISC_ULONG occurred_event[15];
                zval return_value, args[2];
 
                default: /* == DEAD */
@@ -238,7 +245,7 @@ static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
                case NEW:
                        /* re-register the event */
                        if (isc_que_events(IB_STATUS, &event->link->handle, &event->event_id, buffer_size,
-                               event->event_buffer,(isc_callback)_php_ibase_callback, (void *)event)) {
+                               event->event_buffer,(PHP_ISC_CALLBACK)_php_ibase_callback, (void *)event)) {
 
                                _php_ibase_error();
                        }
@@ -345,7 +352,7 @@ PHP_FUNCTION(ibase_set_event_handler)
 
        /* now register the events with the Interbase API */
        if (isc_que_events(IB_STATUS, &ib_link->handle, &event->event_id, buffer_size,
-               event->event_buffer,(isc_callback)_php_ibase_callback, (void *)event)) {
+               event->event_buffer,(PHP_ISC_CALLBACK)_php_ibase_callback, (void *)event)) {
 
                _php_ibase_error();
                efree(event);
index f01b9d7def27868c4d9f7b808424f366da3be2f2..820cd442b85d4cfd971543abe55b78cf6b7ce708 100644 (file)
@@ -219,7 +219,7 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{
 
        for (i = n = 0; i < sqlda->sqld; ++i) {
                unsigned short dim;
-               unsigned long ar_size = 1;
+               zend_ulong ar_size = 1;
                XSQLVAR *var = &sqlda->sqlvar[i];
 
                if ((var->sqltype & ~1) == SQL_ARRAY) {
@@ -430,7 +430,7 @@ _php_ibase_alloc_query_error:
 }
 /* }}} */
 
-static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, /* {{{ */
+static int _php_ibase_bind_array(zval *val, char *buf, zend_ulong buf_size, /* {{{ */
        ibase_array *array, int dim)
 {
        zval null_val, *pnull_val = &null_val;
@@ -441,7 +441,7 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, /
        ZVAL_NULL(pnull_val);
 
        if (dim < array->ar_desc.array_desc_dimensions) {
-               unsigned long slice_size = buf_size / dim_len;
+               zend_ulong slice_size = buf_size / dim_len;
                unsigned short i;
                zval *subval = val;
 
@@ -533,7 +533,7 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, /
 #ifdef HAVE_STRFTIME
                                unsigned short n;
 #endif
-#if (SIZEOF_LONG < 8)
+#if (SIZEOF_ZEND_LONG < 8)
                                ISC_INT64 l;
 #endif
 
@@ -547,7 +547,7 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, /
                                        break;
                                case SQL_LONG:
                                        convert_to_long(val);
-#if (SIZEOF_LONG > 4)
+#if (SIZEOF_ZEND_LONG > 4)
                                        if (Z_LVAL_P(val) > ISC_LONG_MAX || Z_LVAL_P(val) < ISC_LONG_MIN) {
                                                _php_ibase_module_error("Array parameter exceeds field width");
                                                return FAILURE;
@@ -556,9 +556,9 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, /
                                        *(ISC_LONG *) buf = (ISC_LONG) Z_LVAL_P(val);
                                        break;
                                case SQL_INT64:
-#if (SIZEOF_LONG >= 8)
+#if (SIZEOF_ZEND_LONG >= 8)
                                        convert_to_long(val);
-                                       *(long *) buf = Z_LVAL_P(val);
+                                       *(zend_long *) buf = Z_LVAL_P(val);
 #else
                                        convert_to_string(val);
                                        if (!sscanf(Z_STRVAL_P(val), "%" LL_MASK "d", &l)) {
@@ -1315,7 +1315,7 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
 
        switch (type & ~1) {
                unsigned short l;
-               long n;
+               zend_long n;
                char string_data[255];
                struct tm t;
                char *format;
@@ -1331,8 +1331,8 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
                        n = *(short *) data;
                        goto _sql_long;
                case SQL_INT64:
-#if (SIZEOF_LONG >= 8)
-                       n = *(long *) data;
+#if (SIZEOF_ZEND_LONG >= 8)
+                       n = *(zend_long *) data;
                        goto _sql_long;
 #else
                        if (scale == 0) {
@@ -1358,14 +1358,14 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
                        if (scale == 0) {
                                ZVAL_LONG(val,n);
                        } else {
-                               long f = (long) scales[-scale];
+                               zend_long f = (zend_long) scales[-scale];
 
                                if (n >= 0) {
-                                       l = slprintf(string_data, sizeof(string_data), "%ld.%0*ld", n / f, -scale,  n % f);
+                                       l = slprintf(string_data, sizeof(string_data), ZEND_LONG_FMT ".%0*" ZEND_LONG_FMT_SPEC, n / f, -scale,  n % f);
                                } else if (n <= -f) {
-                                       l = slprintf(string_data, sizeof(string_data), "%ld.%0*ld", n / f, -scale,  -n % f);
+                                       l = slprintf(string_data, sizeof(string_data), ZEND_LONG_FMT ".%0*" ZEND_LONG_FMT_SPEC, n / f, -scale,  -n % f);
                                } else {
-                                       l = slprintf(string_data, sizeof(string_data), "-0.%0*ld", -scale, -n % f);
+                                       l = slprintf(string_data, sizeof(string_data), "-0.%0*" ZEND_LONG_FMT_SPEC, -scale, -n % f);
                                }
                                ZVAL_STRINGL(val, string_data, l);
                        }
@@ -1424,7 +1424,7 @@ format_date_time:
 }
 /* }}} */
 
-static int _php_ibase_arr_zval(zval *ar_zval, char *data, unsigned long data_size, /* {{{ */
+static int _php_ibase_arr_zval(zval *ar_zval, char *data, zend_ulong data_size, /* {{{ */
        ibase_array *ib_array, int dim, int flag)
 {
        /**
@@ -1437,7 +1437,7 @@ static int _php_ibase_arr_zval(zval *ar_zval, char *data, unsigned long data_siz
        unsigned short i;
 
        if (dim < ib_array->ar_desc.array_desc_dimensions) { /* array again */
-               unsigned long slice_size = data_size / dim_len;
+               zend_ulong slice_size = data_size / dim_len;
 
                array_init(ar_zval);
 
@@ -1476,7 +1476,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
 {
        zval *result_arg;
        zend_long flag = 0;
-       long i, array_cnt = 0;
+       zend_long i, array_cnt = 0;
        ibase_result *ib_result;
 
        RESET_ERRMSG;
@@ -1546,7 +1546,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
                                        if (flag & PHP_IBASE_FETCH_BLOBS) { /* fetch blob contents into hash */
 
                                                ibase_blob blob_handle;
-                                               unsigned long max_len = 0;
+                                               zend_ulong max_len = 0;
                                                static char bl_items[] = {isc_info_blob_total_length};
                                                char bl_info[20];
                                                unsigned short i;
index cd43724f00a29b3811a235904ad78a58420a4507..3116ab9def88db868184945dfc4c2aa2c0a8628e 100644 (file)
@@ -274,7 +274,7 @@ static void _php_ibase_service_query(INTERNAL_FUNCTION_PARAMETERS, /* {{{ */
        static char spb[] = { isc_info_svc_timeout, 10, 0, 0, 0 };
 
        char res_buf[400], *result, *heap_buf = NULL, *heap_p;
-       long heap_buf_size = 200, line_len;
+       zend_long heap_buf_size = 200, line_len;
 
        /* info about users requires an action first */
        if (info_action == isc_info_svc_get_users) {
@@ -312,7 +312,7 @@ query_loop:
                                        }
                                }
                                if (!heap_buf || (heap_p - heap_buf + line_len +2) > heap_buf_size) {
-                                       long res_size = heap_buf ? heap_p - heap_buf : 0;
+                                       zend_long res_size = heap_buf ? heap_p - heap_buf : 0;
 
                                        while (heap_buf_size < (res_size + line_len +2)) {
                                                heap_buf_size *= 2;
@@ -520,7 +520,7 @@ static void _php_ibase_service_action(INTERNAL_FUNCTION_PARAMETERS, char svc_act
                switch (action) {
                        default:
 unknown_option:
-                               _php_ibase_module_error("Unrecognised option (%ld)", action);
+                               _php_ibase_module_error("Unrecognised option (" ZEND_LONG_FMT ")", action);
                                RETURN_FALSE;
 
                        case isc_spb_rpr_check_db:
index 8f71569bff6668b00ef52ea7eb3aee585a572607..1b3656ce6df5fe9ccdf5e7c027ba9b8c8a84ef26 100644 (file)
@@ -1450,7 +1450,7 @@ PHP_FUNCTION(ibase_gen_id)
        }
 
        /* don't return the generator value as a string unless it doesn't fit in a long */
-#if SIZEOF_LONG < 8
+#if SIZEOF_ZEND_LONG < 8
        if (result < ZEND_LONG_MIN || result > ZEND_LONG_MAX) {
                char *res;
                int l;
index fbbf7e34ce4d5102c95b6804990ccbaa7149234a..860f94b876da7a1fe237a3586e51c768d2551d8c 100644 (file)
@@ -61,9 +61,9 @@ extern int le_link, le_plink, le_trans;
 ZEND_BEGIN_MODULE_GLOBALS(ibase)
        ISC_STATUS status[20];
        zend_resource *default_link;
-       long num_links, num_persistent;
+       zend_long num_links, num_persistent;
        char errmsg[MAX_ERRMSG];
-       long sql_code;
+       zend_long sql_code;
 ZEND_END_MODULE_GLOBALS(ibase)
 
 ZEND_EXTERN_MODULE_GLOBALS(ibase)
@@ -176,7 +176,7 @@ void php_ibase_query_minit(INIT_FUNC_ARGS);
 void php_ibase_blobs_minit(INIT_FUNC_ARGS);
 int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd);
 zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd);
-int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long max_len);
+int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, zend_ulong max_len);
 int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob);
 
 /* provided by ibase_events.c */
index 7102c17c5679b63cfb5394e1ae36b31b1a3014bf..e3fe6e7edc8473afa4d1cb2ce6665a2929cd2273 100644 (file)
@@ -250,8 +250,8 @@ static void call_php(char *name, PARAMDSC *r, int argc, PARAMDSC **argv)
                                case dtype_int64:
                                        l = *(ISC_INT64*)argv[i]->dsc_address;
 
-                                       if (argv[i]->dsc_scale == 0 && l <= LONG_MAX && l >= LONG_MIN) {
-                                               ZVAL_LONG(&args[i], (long)l);
+                                       if (argv[i]->dsc_scale == 0 && l <= ZEND_LONG_MAX && l >= ZEND_LONG_MIN) {
+                                               ZVAL_LONG(&args[i], (zend_long)l);
                                        } else {
                                                ZVAL_DOUBLE(&args[i], ((double)l)/scales[-argv[i]->dsc_scale]);
                                        }
@@ -309,8 +309,8 @@ static void call_php(char *name, PARAMDSC *r, int argc, PARAMDSC **argv)
 
                        case IS_LONG:
                                r->dsc_dtype = dtype_long;
-                               *(long*)r->dsc_address = Z_LVAL(return_value);
-                               r->dsc_length = sizeof(long);
+                               *(zend_long*)r->dsc_address = Z_LVAL(return_value);
+                               r->dsc_length = sizeof(zend_long);
                                break;
 
                        case IS_DOUBLE: