com php-src: Fixed bug #73448 odbc_errormsg returns trash , always 513 bytes: ext/odbc/php_odbc.c
| From: | Anatol Belski | Date: | Mon, 07 Nov 2016 19:18:29 +0000 |
| Subject: | com php-src: Fixed bug #73448 odbc_errormsg returns trash , always 513 bytes: ext/odbc/php_odbc.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95423@lists.php.net to get a copy of this message | ||
Commit: 3558e70e58f0980cb86e5343947f4876017ef3e3
Author: Anatol Belski <ab@php.net> Mon, 7 Nov 2016 20:18:29 +0100
Parents: 20587805f90023ac90e0c6891e9dd5833c5fc089
Branches: PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3558e70e58f0980cb86e5343947f4876017ef3e3
Log:
Fixed bug #73448 odbc_errormsg returns trash, always 513 bytes
Bugs:
https://bugs.php.net/73448
Changed paths:
M ext/odbc/php_odbc.c
Diff:
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index f432dcd..eb722f7 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -2442,6 +2442,7 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd,
int
RETCODE rc;
*conn = (odbc_connection *)pemalloc(sizeof(odbc_connection), persistent);
+ memset(*conn, 0, sizeof(odbc_connection));
(*conn)->persistent = persistent;
SQLAllocEnv(&((*conn)->henv));
SQLAllocConnect((*conn)->henv, &((*conn)->hdbc));
@@ -3047,38 +3048,30 @@ static void php_odbc_lasterror(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
odbc_connection *conn;
zval *pv_handle;
- zend_string *ptr;
- int len;
+ char *ret;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pv_handle) == FAILURE) {
return;
}
- if (mode == 0) { /* last state */
- len = 6;
- } else { /* last error message */
- len = SQL_MAX_MESSAGE_LENGTH;
- }
-
if (ZEND_NUM_ARGS() == 1) {
if (!(conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_handle), "ODBC-Link",
le_conn, le_pconn))) {
RETURN_FALSE;
}
- ptr = zend_string_alloc(len + 1, 0);
if (mode == 0) {
- strlcpy(ZSTR_VAL(ptr), conn->laststate, len+1);
+ ret = conn->laststate;
} else {
- strlcpy(ZSTR_VAL(ptr), conn->lasterrormsg, len+1);
+ ret = conn->lasterrormsg;
}
} else {
- ptr = zend_string_alloc(len, 0);
if (mode == 0) {
- strlcpy(ZSTR_VAL(ptr), ODBCG(laststate), len+1);
+ ret = ODBCG(laststate);
} else {
- strlcpy(ZSTR_VAL(ptr), ODBCG(lasterrormsg), len+1);
+ ret = ODBCG(lasterrormsg);
}
}
- RETVAL_STR(ptr);
+
+ RETURN_STRING(ret);
}
/* }}} */