summaryrefslogtreecommitdiff
path: root/ext/sybase_ct/php_sybase_ct.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/sybase_ct/php_sybase_ct.c')
-rw-r--r--ext/sybase_ct/php_sybase_ct.c100
1 files changed, 51 insertions, 49 deletions
diff --git a/ext/sybase_ct/php_sybase_ct.c b/ext/sybase_ct/php_sybase_ct.c
index 9b922129e..4479336a9 100644
--- a/ext/sybase_ct/php_sybase_ct.c
+++ b/ext/sybase_ct/php_sybase_ct.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_sybase_ct.c,v 1.103.2.5.2.6 2006/07/25 09:20:32 thetaphi Exp $ */
+/* $Id: php_sybase_ct.c,v 1.103.2.5.2.13 2007/04/10 15:56:31 helly Exp $ */
#ifdef HAVE_CONFIG_H
@@ -135,6 +135,9 @@ static int _clean_invalid_results(zend_rsrc_list_entry *le TSRMLS_DC)
return 0;
}
+#define efree_n(x) { efree(x); x = NULL; }
+#define efree_if(x) if (x) efree_n(x)
+
static void _free_sybase_result(sybase_result *result)
{
int i, j;
@@ -157,6 +160,19 @@ static void _free_sybase_result(sybase_result *result)
efree(result->fields);
}
+ if (result->tmp_buffer) {
+ for (i=0; i<result->num_fields; i++) {
+ efree(result->tmp_buffer[i]);
+ }
+ efree(result->tmp_buffer);
+ }
+
+ efree_if(result->lengths);
+ efree_if(result->indicators);
+ efree_if(result->datafmt);
+ efree_if(result->numerics);
+ efree_if(result->types);
+
efree(result);
}
@@ -246,7 +262,7 @@ static CS_RETCODE CS_PUBLIC _client_message_handler(CS_CONTEXT *context, CS_CONN
TSRMLS_FETCH();
if (CS_SEVERITY(errmsg->msgnumber) >= SybCtG(min_client_severity)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Client message: %s (severity %d)", errmsg->msgstring, CS_SEVERITY(errmsg->msgnumber));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Client message: %s (severity %ld)", errmsg->msgstring, CS_SEVERITY(errmsg->msgnumber));
}
STR_FREE(SybCtG(server_message));
SybCtG(server_message) = estrdup(errmsg->msgstring);
@@ -351,8 +367,8 @@ static CS_RETCODE CS_PUBLIC _server_message_handler(CS_CONTEXT *context, CS_CONN
/* Spit out a warning if neither of them has handled this message */
if (!handled) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Server message: %s (severity %d, procedure %s)",
- srvmsg->text, srvmsg->severity, ((srvmsg->proclen>0) ? srvmsg->proc : "N/A"));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Server message: %s (severity %ld, procedure %s)",
+ srvmsg->text, (long)srvmsg->severity, ((srvmsg->proclen>0) ? srvmsg->proc : "N/A"));
}
return CS_SUCCEED;
@@ -512,16 +528,16 @@ static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char
if (charset) {
if (cs_loc_alloc(SybCtG(context), &tmp_locale)!=CS_SUCCEED) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to allocate locale information.");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to allocate locale information");
} else {
if (cs_locale(SybCtG(context), CS_SET, tmp_locale, CS_LC_ALL, NULL, CS_NULLTERM, NULL)!=CS_SUCCEED) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to load default locale data.");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to load default locale data");
} else {
if (cs_locale(SybCtG(context), CS_SET, tmp_locale, CS_SYB_CHARSET, charset, CS_NULLTERM, NULL)!=CS_SUCCEED) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update character set.");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update character set");
} else {
if (ct_con_props(sybase->connection, CS_SET, CS_LOC_PROP, tmp_locale, CS_UNUSED, NULL)!=CS_SUCCEED) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update connection properties.");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update connection properties");
}
}
}
@@ -530,7 +546,7 @@ static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char
if (cfg_get_long("sybct.packet_size", &packetsize) == SUCCESS) {
if (ct_con_props(sybase->connection, CS_SET, CS_PACKETSIZE, (CS_VOID *)&packetsize, CS_UNUSED, NULL) != CS_SUCCEED) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update connection packetsize.");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update connection packetsize");
}
}
@@ -599,9 +615,7 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
convert_to_string_ex(yyhost);
host = Z_STRVAL_PP(yyhost);
user=passwd=charset=appname=NULL;
- hashed_details_length = Z_STRLEN_PP(yyhost)+6+5;
- hashed_details = (char *) emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s____", Z_STRVAL_PP(yyhost));
+ hashed_details_length = spprintf(&hashed_details, 0, "sybase_%s____", Z_STRVAL_PP(yyhost));
}
break;
case 2: {
@@ -615,9 +629,7 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
host = Z_STRVAL_PP(yyhost);
user = Z_STRVAL_PP(yyuser);
passwd=charset=appname=NULL;
- hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+6+5;
- hashed_details = (char *) emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s___", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser));
+ hashed_details_length = spprintf(&hashed_details, 0, "sybase_%s_%s___", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser));
}
break;
case 3: {
@@ -633,9 +645,7 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
user = Z_STRVAL_PP(yyuser);
passwd = Z_STRVAL_PP(yypasswd);
charset=appname=NULL;
- hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+6+5;
- hashed_details = (char *) emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s_%s__", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd));
+ hashed_details_length = spprintf(&hashed_details, 0, "sybase_%s_%s_%s__", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd));
}
break;
case 4: {
@@ -653,9 +663,7 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
passwd = Z_STRVAL_PP(yypasswd);
charset = Z_STRVAL_PP(yycharset);
appname=NULL;
- hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+Z_STRLEN_PP(yycharset)+6+5;
- hashed_details = (char *) emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s_%s_%s_", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset));
+ hashed_details_length = spprintf(&hashed_details, 0, "sybase_%s_%s_%s_%s_", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset));
}
break;
case 5: {
@@ -674,9 +682,7 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
passwd = Z_STRVAL_PP(yypasswd);
charset = Z_STRVAL_PP(yycharset);
appname = Z_STRVAL_PP(yyappname);
- hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+Z_STRLEN_PP(yycharset)+Z_STRLEN_PP(yyappname)+6+5;
- hashed_details = (char *) emalloc(hashed_details_length+1);
- sprintf(hashed_details, "sybase_%s_%s_%s_%s_%s", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset), Z_STRVAL_PP(yyappname));
+ hashed_details_length = spprintf(&hashed_details, 0, "sybase_%s_%s_%s_%s_%s", Z_STRVAL_PP(yyhost), Z_STRVAL_PP(yyuser), Z_STRVAL_PP(yypasswd), Z_STRVAL_PP(yycharset), Z_STRVAL_PP(yyappname));
}
break;
default:
@@ -1006,8 +1012,7 @@ PHP_FUNCTION(sybase_select_db)
ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, sybase_link_index, id, "Sybase-Link", le_link, le_plink);
convert_to_string_ex(db);
- cmdbuf = (char *) emalloc(sizeof("use ")+Z_STRLEN_PP(db)+1);
- sprintf(cmdbuf, "use %s", Z_STRVAL_PP(db)); /* SAFE */
+ spprintf(&cmdbuf, 0, "use %s", Z_STRVAL_PP(db)); /* SAFE */
if (exec_cmd(sybase_ptr, cmdbuf)==FAILURE) {
efree(cmdbuf);
@@ -1026,15 +1031,15 @@ static int php_sybase_finish_results(sybase_result *result TSRMLS_DC)
CS_RETCODE retcode;
CS_INT restype;
- efree(result->datafmt);
- efree(result->lengths);
- efree(result->indicators);
- efree(result->numerics);
- efree(result->types);
+ efree_n(result->datafmt);
+ efree_n(result->lengths);
+ efree_n(result->indicators);
+ efree_n(result->numerics);
+ efree_n(result->types);
for (i=0; i<result->num_fields; i++) {
efree(result->tmp_buffer[i]);
}
- efree(result->tmp_buffer);
+ efree_n(result->tmp_buffer);
/* Indicate we have read all rows */
result->sybase_ptr->active_result_index= 0;
@@ -1116,7 +1121,7 @@ static int php_sybase_finish_results(sybase_result *result TSRMLS_DC)
#define RETURN_DOUBLE_VAL(result, buf, length) \
if ((length - 1) <= EG(precision)) { \
errno = 0; \
- Z_DVAL(result) = strtod(buf, NULL); \
+ Z_DVAL(result) = zend_strtod(buf, NULL); \
if (errno != ERANGE) { \
Z_TYPE(result) = IS_DOUBLE; \
} else { \
@@ -1138,18 +1143,11 @@ static int php_sybase_fetch_result_row (sybase_result *result, int numrows)
}
if (numrows!=-1) numrows+= result->num_rows;
- while ((retcode=ct_fetch(result->sybase_ptr->cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, NULL))==CS_SUCCEED
- || retcode==CS_ROW_FAIL) {
- /*
- if (retcode==CS_ROW_FAIL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Error reading row %d", result->num_rows);
- }
- */
-
+ while ((retcode=ct_fetch(result->sybase_ptr->cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, NULL))==CS_SUCCEED) {
result->num_rows++;
i= result->store ? result->num_rows- 1 : 0;
if (i >= result->blocks_initialized*SYBASE_ROWS_BLOCK) {
- result->data = (zval **) erealloc(result->data, sizeof(zval *)*SYBASE_ROWS_BLOCK*(++result->blocks_initialized));
+ result->data = (zval **) safe_erealloc(result->data, SYBASE_ROWS_BLOCK*(++result->blocks_initialized), sizeof(zval *), 0);
}
if (result->store || 1 == result->num_rows) {
result->data[i] = (zval *) safe_emalloc(sizeof(zval), result->num_fields, 0);
@@ -1202,7 +1200,11 @@ static int php_sybase_fetch_result_row (sybase_result *result, int numrows)
}
if (numrows!=-1 && result->num_rows>=numrows) break;
}
-
+
+ if (retcode==CS_ROW_FAIL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Error reading row %d", result->num_rows);
+ return retcode;
+ }
result->last_retcode= retcode;
switch (retcode) {
case CS_END_DATA:
@@ -2125,16 +2127,16 @@ PHP_MINFO_FUNCTION(sybase)
php_info_print_table_start();
php_info_print_table_header(2, "Sybase_CT Support", "enabled" );
- sprintf(buf, "%ld", SybCtG(num_persistent));
+ snprintf(buf, sizeof(buf), "%ld", SybCtG(num_persistent));
php_info_print_table_row(2, "Active Persistent Links", buf);
- sprintf(buf, "%ld", SybCtG(num_links));
+ snprintf(buf, sizeof(buf), "%ld", SybCtG(num_links));
php_info_print_table_row(2, "Active Links", buf);
- sprintf(buf, "%ld", SybCtG(min_server_severity));
+ snprintf(buf, sizeof(buf), "%ld", SybCtG(min_server_severity));
php_info_print_table_row(2, "Min server severity", buf);
- sprintf(buf, "%ld", SybCtG(min_client_severity));
+ snprintf(buf, sizeof(buf), "%ld", SybCtG(min_client_severity));
php_info_print_table_row(2, "Min client severity", buf);
php_info_print_table_row(2, "Application Name", SybCtG(appname));
- sprintf(buf, "%ld", SybCtG(deadlock_retry_count));
+ snprintf(buf, sizeof(buf), "%ld", SybCtG(deadlock_retry_count));
php_info_print_table_row(2, "Deadlock retry count", buf);
php_info_print_table_end();