]> granicus.if.org Git - php/commitdiff
MFH
authorYasuo Ohgaki <yohgaki@php.net>
Thu, 4 Apr 2002 15:29:34 +0000 (15:29 +0000)
committerYasuo Ohgaki <yohgaki@php.net>
Thu, 4 Apr 2002 15:29:34 +0000 (15:29 +0000)
# Fixed crash with pg_escape_*()
# Added test for pg_escape_*()

ext/pgsql/pgsql.c

index 225e3e4b3728ac596ec14bcf44076736b67e0e37..7171f332daf5b8d854b75fd83b8fe3683abf0c19 100644 (file)
@@ -2376,17 +2376,15 @@ PHP_FUNCTION(pg_copy_from)
 PHP_FUNCTION(pg_escape_string)
 {
        char *from = NULL, *to = NULL;
-       int len;
+       size_t from_len, to_len;
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
-                                                         &from, &len) == FAILURE) {
+                                                         &from, &from_len) == FAILURE) {
                return;
        }
 
-       len = (int)PQescapeString(to, from, strlen(from));
-       if (len < 0) {
-               RETURN_FALSE;
-       }
-       RETURN_STRINGL(to, len, 0);
+       to = (char *)emalloc(from_len*2+1);
+       to_len = (int)PQescapeString(to, from, from_len);
+       RETURN_STRINGL(to, to_len, 0);
 }
 /* }}} */
 
@@ -2395,17 +2393,15 @@ PHP_FUNCTION(pg_escape_string)
 PHP_FUNCTION(pg_escape_bytea)
 {
        char *from = NULL, *to = NULL;
-       int len;
+       size_t from_len, to_len;
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
-                                                         &from, &len) == FAILURE) {
+                                                         &from, &from_len) == FAILURE) {
                return;
        }
 
-       to = (char *)PQescapeBytea((unsigned char*)from, strlen(from), (size_t *)&len);
-       if (len < 0) {
-               RETURN_FALSE;
-       }
-       RETURN_STRINGL(to, len, 0);
+       to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len);
+       RETVAL_STRINGL(to, to_len-1, 1);
+       free(to);
 }
 /* }}} */
 #endif