]> granicus.if.org Git - php/commitdiff
MF44: fix #33383 (crash when retrieving empty LOBs)
authorAntony Dovgal <tony2001@php.net>
Mon, 10 Oct 2005 10:44:39 +0000 (10:44 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 10 Oct 2005 10:44:39 +0000 (10:44 +0000)
ext/oci8/oci8.c

index 3f71185cd807be896a27b249fbaf4059b664ac37..0796ac34343af226a9c31c6123e0eb648b0fbecd 100644 (file)
@@ -1489,7 +1489,12 @@ static int _oci_make_zval(zval *value,oci_statement *statement,oci_out_column *c
                        if (oci_loadlob(statement->conn,descr,&buffer,&loblen)) {
                                ZVAL_FALSE(value);
                        } else {
-                               ZVAL_STRINGL(value,buffer,loblen,0);
+                               if (loblen > 0) {
+                                       ZVAL_STRINGL(value,buffer,loblen,0);
+                               }
+                               else {
+                                       ZVAL_EMPTY_STRING(value);
+                               }
                        } 
                } else { 
                        /* return the locator */
@@ -2248,6 +2253,10 @@ static int oci_loadlob(oci_connection *connection, oci_descriptor *mydescr, char
                return -1;
        }
 
+       if (readlen == 0) {
+               return 0;
+       }
+       
        buf = emalloc(readlen + 1);
 
        while (readlen > 0) { /* thies loop should not be entered on readlen == 0 */
@@ -2351,6 +2360,10 @@ static int oci_readlob(oci_connection *connection, oci_descriptor *mydescr, char
                *len = 0;
                return -1;
        }
+
+       if (loblen == 0) {
+               return 0;
+       }
        
        /* check if we're in LOB's borders */
        if ((mydescr->lob_current_position + *len) > loblen) {
@@ -4015,7 +4028,12 @@ PHP_FUNCTION(oci_lob_load)
                }
                
                if (!oci_loadlob(descr->conn,descr,&buffer,&loblen)) {
-                       RETURN_STRINGL(buffer,loblen,0);
+                       if (loblen > 0) {
+                               RETURN_STRINGL(buffer,loblen,0);
+                       }
+                       else {
+                               RETURN_EMPTY_STRING();
+                       }
                } else {
                        RETURN_FALSE;
                }
@@ -4049,7 +4067,12 @@ PHP_FUNCTION(oci_lob_read)
 
                loblen = Z_LVAL_PP(len);
                if (oci_readlob(descr->conn,descr,&buffer,&loblen) == 0) {
-                       RETURN_STRINGL(buffer,loblen,0);
+                       if (loblen > 0) {
+                               RETURN_STRINGL(buffer,loblen,0);
+                       }
+                       else {
+                               RETURN_EMPTY_STRING();
+                       }
                } else {
                        RETURN_FALSE;
                }