]> granicus.if.org Git - php/commitdiff
Added missing sanity check in fgetcsv()
authorMoriyoshi Koizumi <moriyoshi@php.net>
Mon, 28 Apr 2003 15:04:56 +0000 (15:04 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Mon, 28 Apr 2003 15:04:56 +0000 (15:04 +0000)
ext/standard/file.c

index 6c98e8aa2983a4070510d51426fc1b4a1e8b0645..0950dfccd857ca265fbdcb3d917b1d3a579f4fed 100644 (file)
@@ -1665,32 +1665,12 @@ PHP_FUNCTION(fgetcsv)
                        if (zend_get_parameters_ex(3, &fd, &bytes, &p_delim) == FAILURE) {
                                WRONG_PARAM_COUNT;
                        }
-                       convert_to_string_ex(p_delim);
-                       /* Make sure that there is at least one character in string */
-                       if (Z_STRLEN_PP(p_delim) < 1) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third parameter must be a character");
-                               return;
-                       }
-                       /* use first character from string */
-                       delimiter = Z_STRVAL_PP(p_delim)[0];
                        break;
 
                case 4:
                        if (zend_get_parameters_ex(4, &fd, &bytes, &p_delim, &p_enclosure) == FAILURE) {
                                WRONG_PARAM_COUNT;
                        }
-                       convert_to_string_ex(p_delim);
-                       /* Make sure that there is at least one character in string */
-                       if (Z_STRLEN_PP(p_delim) < 1) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third parameter must be a character");
-                               return;
-                       }
-                       /* use first character from string */
-                       delimiter = Z_STRVAL_PP(p_delim)[0];
-
-                       convert_to_string_ex(p_enclosure);
-                       /* use first character from string */
-                       enclosure = Z_STRVAL_PP(p_enclosure)[0];
                        break;
 
                default:
@@ -1699,6 +1679,28 @@ PHP_FUNCTION(fgetcsv)
                        break;
        }
 
+       if (ZEND_NUM_ARGS() >= 3) {
+               convert_to_string_ex(p_delim);
+               /* Make sure that there is at least one character in string */
+               if (Z_STRLEN_PP(p_delim) < 1) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
+                       RETURN_FALSE;
+               }
+               /* use first character from string */
+               delimiter = Z_STRVAL_PP(p_delim)[0];
+       }
+
+       if (ZEND_NUM_ARGS() >= 4) {
+               convert_to_string_ex(p_enclosure);
+               /* Make sure that there is at least one character in string */
+               if (Z_STRLEN_PP(p_enclosure) < 1) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
+                       RETURN_FALSE;
+               }
+               /* use first character from string */
+               enclosure = Z_STRVAL_PP(p_enclosure)[0];
+       }
+
        php_stream_from_zval(stream, fd);
 
        convert_to_long_ex(bytes);