idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
12,200 | static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageEmboss(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageEmboss(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,201 | static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageGaussianBlur(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageGaussianBlur(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,202 | static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageGrayScale(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageGrayScale(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,203 | static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageMeanRemoval(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageMeanRemoval(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,204 | static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageNegate(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageNegate(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,205 | static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)
{
zval *IM;
gdImagePtr im;
long tmp, blocksize;
zend_bool mode = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll|b", &IM, &tmp, &blocksize, &mode) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
if (im == NULL) {
RETURN_FALSE;
}
if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)
{
zval *IM;
gdImagePtr im;
long tmp, blocksize;
zend_bool mode = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll|b", &IM, &tmp, &blocksize, &mode) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
if (im == NULL) {
RETURN_FALSE;
}
if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,206 | static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageSelectiveBlur(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
{
PHP_GD_SINGLE_RES
if (gdImageSelectiveBlur(im_src) == 1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,207 | static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
{
zval *SIM;
long tmp;
gdImagePtr im_src;
double weight;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
if (im_src == NULL) {
RETURN_FALSE;
}
if (gdImageSmooth(im_src, (float)weight)==1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
{
zval *SIM;
long tmp;
gdImagePtr im_src;
double weight;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
if (im_src == NULL) {
RETURN_FALSE;
}
if (gdImageSmooth(im_src, (float)weight)==1) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,208 | static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
zval *IM;
long SIZE, X, Y, COL;
char *C;
int C_len;
gdImagePtr im;
int ch = 0, col, x, y, size, i, l = 0;
unsigned char *str = NULL;
gdFontPtr font;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllsl", &IM, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
col = COL;
if (mode < 2) {
ch = (int)((unsigned char)*C);
} else {
str = (unsigned char *) estrndup(C, C_len);
l = strlen((char *)str);
}
y = Y;
x = X;
size = SIZE;
font = php_find_gd_font(size TSRMLS_CC);
switch (mode) {
case 0:
gdImageChar(im, font, x, y, ch, col);
break;
case 1:
php_gdimagecharup(im, font, x, y, ch, col);
break;
case 2:
for (i = 0; (i < l); i++) {
gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
x += font->w;
}
break;
case 3: {
for (i = 0; (i < l); i++) {
/* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
gdImageCharUp(im, font, x, y, (int) str[i], col);
y -= font->w;
}
break;
}
}
if (str) {
efree(str);
}
RETURN_TRUE;
}
| Bypass | 0 | static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
zval *IM;
long SIZE, X, Y, COL;
char *C;
int C_len;
gdImagePtr im;
int ch = 0, col, x, y, size, i, l = 0;
unsigned char *str = NULL;
gdFontPtr font;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllsl", &IM, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
col = COL;
if (mode < 2) {
ch = (int)((unsigned char)*C);
} else {
str = (unsigned char *) estrndup(C, C_len);
l = strlen((char *)str);
}
y = Y;
x = X;
size = SIZE;
font = php_find_gd_font(size TSRMLS_CC);
switch (mode) {
case 0:
gdImageChar(im, font, x, y, ch, col);
break;
case 1:
php_gdimagecharup(im, font, x, y, ch, col);
break;
case 2:
for (i = 0; (i < l); i++) {
gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
x += font->w;
}
break;
case 3: {
for (i = 0; (i < l); i++) {
/* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
gdImageCharUp(im, font, x, y, (int) str[i], col);
y -= font->w;
}
break;
}
}
if (str) {
efree(str);
}
RETURN_TRUE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,209 | static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
{
long SIZE;
gdFontPtr font;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &SIZE) == FAILURE) {
return;
}
font = php_find_gd_font(SIZE TSRMLS_CC);
RETURN_LONG(arg ? font->h : font->w);
}
| Bypass | 0 | static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
{
long SIZE;
gdFontPtr font;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &SIZE) == FAILURE) {
return;
}
font = php_find_gd_font(SIZE TSRMLS_CC);
RETURN_LONG(arg ? font->h : font->w);
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,210 | static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
{
zval *IM, *POINTS;
long NPOINTS, COL;
zval **var = NULL;
gdImagePtr im;
gdPointPtr points;
int npoints, col, nelem, i;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rall", &IM, &POINTS, &NPOINTS, &COL) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
npoints = NPOINTS;
col = COL;
nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
if (nelem < 6) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have at least 3 points in your array");
RETURN_FALSE;
}
if (npoints <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must give a positive number of points");
RETURN_FALSE;
}
if (nelem < npoints * 2) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
RETURN_FALSE;
}
points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
for (i = 0; i < npoints; i++) {
if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2), (void **) &var) == SUCCESS) {
SEPARATE_ZVAL((var));
convert_to_long(*var);
points[i].x = Z_LVAL_PP(var);
}
if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) {
SEPARATE_ZVAL(var);
convert_to_long(*var);
points[i].y = Z_LVAL_PP(var);
}
}
if (filled) {
gdImageFilledPolygon(im, points, npoints, col);
} else {
gdImagePolygon(im, points, npoints, col);
}
efree(points);
RETURN_TRUE;
}
| Bypass | 0 | static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
{
zval *IM, *POINTS;
long NPOINTS, COL;
zval **var = NULL;
gdImagePtr im;
gdPointPtr points;
int npoints, col, nelem, i;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rall", &IM, &POINTS, &NPOINTS, &COL) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
npoints = NPOINTS;
col = COL;
nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
if (nelem < 6) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have at least 3 points in your array");
RETURN_FALSE;
}
if (npoints <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must give a positive number of points");
RETURN_FALSE;
}
if (nelem < npoints * 2) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
RETURN_FALSE;
}
points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
for (i = 0; i < npoints; i++) {
if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2), (void **) &var) == SUCCESS) {
SEPARATE_ZVAL((var));
convert_to_long(*var);
points[i].x = Z_LVAL_PP(var);
}
if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) {
SEPARATE_ZVAL(var);
convert_to_long(*var);
points[i].y = Z_LVAL_PP(var);
}
}
if (filled) {
gdImageFilledPolygon(im, points, npoints, col);
} else {
gdImagePolygon(im, points, npoints, col);
}
efree(points);
RETURN_TRUE;
}
| @@ -1495,7 +1495,7 @@ PHP_FUNCTION(imageloadfont)
gdFontPtr font;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_name) == FAILURE) {
return;
}
@@ -2438,7 +2438,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
long ignore_warning;
#endif
if (image_type == PHP_GDIMG_TYPE_GD2PART) {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
return;
}
if (width < 1 || height < 1) {
@@ -2446,7 +2446,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
RETURN_FALSE;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &file, &file_len) == FAILURE) {
return;
}
}
@@ -4178,7 +4178,7 @@ PHP_FUNCTION(imagepsencodefont)
char *enc, **enc_vector;
int enc_len, *f_ind;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &fnt, &enc, &enc_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,211 | PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context) /* {{{ */
{
php_hash_ops *hash_ops = (php_hash_ops *)ops;
memcpy(dest_context, orig_context, hash_ops->context_size);
return SUCCESS;
}
/* }}} */
| Bypass | 0 | PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context) /* {{{ */
{
php_hash_ops *hash_ops = (php_hash_ops *)ops;
memcpy(dest_context, orig_context, hash_ops->context_size);
return SUCCESS;
}
/* }}} */
| @@ -142,6 +142,7 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_
}
if (isfilename) {
if (CHECK_NULL_PATH(data, data_len)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid path");
RETURN_FALSE;
}
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
@@ -222,6 +223,10 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
RETURN_FALSE;
}
if (isfilename) {
+ if (CHECK_NULL_PATH(data, data_len)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid path");
+ RETURN_FALSE;
+ }
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
if (!stream) {
/* Stream will report errors opening file */
@@ -449,7 +454,7 @@ PHP_FUNCTION(hash_update_file)
char *filename, buf[1024];
int filename_len, n;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|r", &zhash, &filename, &filename_len, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp|r", &zhash, &filename, &filename_len, &zcontext) == FAILURE) {
return;
} | CWE-254 | null | null |
12,212 | PHP_FUNCTION(pg_query_params)
{
zval *pgsql_link = NULL;
zval *pv_param_arr, **tmp;
char *query;
int query_len, id = -1, argc = ZEND_NUM_ARGS();
int leftover = 0;
int num_params = 0;
char **params = NULL;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
pgsql_result_handle *pg_result;
if (argc == 2) {
if (zend_parse_parameters(argc TSRMLS_CC, "sa", &query, &query_len, &pv_param_arr) == FAILURE) {
return;
}
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
} else {
if (zend_parse_parameters(argc TSRMLS_CC, "rsa", &pgsql_link, &query, &query_len, &pv_param_arr) == FAILURE) {
return;
}
}
if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (PQ_SETNONBLOCKING(pgsql, 0)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE,"Cannot set connection to blocking mode");
RETURN_FALSE;
}
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
leftover = 1;
}
if (leftover) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first");
}
zend_hash_internal_pointer_reset(Z_ARRVAL_P(pv_param_arr));
num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr));
if (num_params > 0) {
int i = 0;
params = (char **)safe_emalloc(sizeof(char *), num_params, 0);
for(i = 0; i < num_params; i++) {
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter");
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
}
zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));
}
}
pgsql_result = PQexecParams(pgsql, query, num_params,
NULL, (const char * const *)params, NULL, NULL, 0);
if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
PQclear(pgsql_result);
PQreset(pgsql);
pgsql_result = PQexecParams(pgsql, query, num_params,
NULL, (const char * const *)params, NULL, NULL, 0);
}
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
_php_pgsql_free_params(params, num_params);
switch (status) {
case PGRES_EMPTY_QUERY:
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
PHP_PQ_ERROR("Query failed: %s", pgsql);
PQclear(pgsql_result);
RETURN_FALSE;
break;
case PGRES_COMMAND_OK: /* successful command that did not return rows */
default:
if (pgsql_result) {
pg_result = (pgsql_result_handle *) emalloc(sizeof(pgsql_result_handle));
pg_result->conn = pgsql;
pg_result->result = pgsql_result;
pg_result->row = 0;
ZEND_REGISTER_RESOURCE(return_value, pg_result, le_result);
} else {
PQclear(pgsql_result);
RETURN_FALSE;
}
break;
}
}
| Bypass | 0 | PHP_FUNCTION(pg_query_params)
{
zval *pgsql_link = NULL;
zval *pv_param_arr, **tmp;
char *query;
int query_len, id = -1, argc = ZEND_NUM_ARGS();
int leftover = 0;
int num_params = 0;
char **params = NULL;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
pgsql_result_handle *pg_result;
if (argc == 2) {
if (zend_parse_parameters(argc TSRMLS_CC, "sa", &query, &query_len, &pv_param_arr) == FAILURE) {
return;
}
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
} else {
if (zend_parse_parameters(argc TSRMLS_CC, "rsa", &pgsql_link, &query, &query_len, &pv_param_arr) == FAILURE) {
return;
}
}
if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (PQ_SETNONBLOCKING(pgsql, 0)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE,"Cannot set connection to blocking mode");
RETURN_FALSE;
}
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
leftover = 1;
}
if (leftover) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first");
}
zend_hash_internal_pointer_reset(Z_ARRVAL_P(pv_param_arr));
num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr));
if (num_params > 0) {
int i = 0;
params = (char **)safe_emalloc(sizeof(char *), num_params, 0);
for(i = 0; i < num_params; i++) {
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter");
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
convert_to_string(&tmp_val);
if (Z_TYPE(tmp_val) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error converting parameter");
zval_dtor(&tmp_val);
_php_pgsql_free_params(params, num_params);
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
zval_dtor(&tmp_val);
}
zend_hash_move_forward(Z_ARRVAL_P(pv_param_arr));
}
}
pgsql_result = PQexecParams(pgsql, query, num_params,
NULL, (const char * const *)params, NULL, NULL, 0);
if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
PQclear(pgsql_result);
PQreset(pgsql);
pgsql_result = PQexecParams(pgsql, query, num_params,
NULL, (const char * const *)params, NULL, NULL, 0);
}
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
_php_pgsql_free_params(params, num_params);
switch (status) {
case PGRES_EMPTY_QUERY:
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
PHP_PQ_ERROR("Query failed: %s", pgsql);
PQclear(pgsql_result);
RETURN_FALSE;
break;
case PGRES_COMMAND_OK: /* successful command that did not return rows */
default:
if (pgsql_result) {
pg_result = (pgsql_result_handle *) emalloc(sizeof(pgsql_result_handle));
pg_result->conn = pgsql;
pg_result->result = pgsql_result;
pg_result->row = 0;
ZEND_REGISTER_RESOURCE(return_value, pg_result, le_result);
} else {
PQclear(pgsql_result);
RETURN_FALSE;
}
break;
}
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,213 | PHP_FUNCTION(pg_lo_export)
{
zval *pgsql_link = NULL;
char *file_out, *oid_string, *end_ptr;
int oid_strlen;
int id = -1, name_len;
long oid_long;
Oid oid;
PGconn *pgsql;
int argc = ZEND_NUM_ARGS();
/* allow string to handle large OID value correctly */
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"rlp", &pgsql_link, &oid_long, &file_out, &name_len) == SUCCESS) {
if (oid_long <= InvalidOid) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified");
RETURN_FALSE;
}
oid = (Oid)oid_long;
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"rss", &pgsql_link, &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) {
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
if ((oid_string+oid_strlen) != end_ptr) {
/* wrong integer format */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed");
RETURN_FALSE;
}
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"lp", &oid_long, &file_out, &name_len) == SUCCESS) {
if (oid_long <= InvalidOid) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified");
RETURN_FALSE;
}
oid = (Oid)oid_long;
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"sp", &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) {
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
if ((oid_string+oid_strlen) != end_ptr) {
/* wrong integer format */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed");
RETURN_FALSE;
}
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"spr", &oid_string, &oid_strlen, &file_out, &name_len, &pgsql_link) == SUCCESS) {
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
if ((oid_string+oid_strlen) != end_ptr) {
/* wrong integer format */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed");
RETURN_FALSE;
}
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"lpr", &oid_long, &file_out, &name_len, &pgsql_link) == SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Old API is used");
if (oid_long <= InvalidOid) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified");
RETURN_FALSE;
}
oid = (Oid)oid_long;
}
else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 2 or 3 arguments");
RETURN_FALSE;
}
if (php_check_open_basedir(file_out TSRMLS_CC)) {
RETURN_FALSE;
}
if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (lo_export(pgsql, oid, file_out)) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | PHP_FUNCTION(pg_lo_export)
{
zval *pgsql_link = NULL;
char *file_out, *oid_string, *end_ptr;
int oid_strlen;
int id = -1, name_len;
long oid_long;
Oid oid;
PGconn *pgsql;
int argc = ZEND_NUM_ARGS();
/* allow string to handle large OID value correctly */
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"rlp", &pgsql_link, &oid_long, &file_out, &name_len) == SUCCESS) {
if (oid_long <= InvalidOid) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified");
RETURN_FALSE;
}
oid = (Oid)oid_long;
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"rss", &pgsql_link, &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) {
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
if ((oid_string+oid_strlen) != end_ptr) {
/* wrong integer format */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed");
RETURN_FALSE;
}
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"lp", &oid_long, &file_out, &name_len) == SUCCESS) {
if (oid_long <= InvalidOid) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified");
RETURN_FALSE;
}
oid = (Oid)oid_long;
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"sp", &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) {
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
if ((oid_string+oid_strlen) != end_ptr) {
/* wrong integer format */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed");
RETURN_FALSE;
}
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"spr", &oid_string, &oid_strlen, &file_out, &name_len, &pgsql_link) == SUCCESS) {
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
if ((oid_string+oid_strlen) != end_ptr) {
/* wrong integer format */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed");
RETURN_FALSE;
}
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
"lpr", &oid_long, &file_out, &name_len, &pgsql_link) == SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Old API is used");
if (oid_long <= InvalidOid) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified");
RETURN_FALSE;
}
oid = (Oid)oid_long;
}
else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 2 or 3 arguments");
RETURN_FALSE;
}
if (php_check_open_basedir(file_out TSRMLS_CC)) {
RETURN_FALSE;
}
if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (lo_export(pgsql, oid, file_out)) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,214 | PHP_FUNCTION(pg_copy_from)
{
zval *pgsql_link = NULL, *pg_rows;
zval **tmp;
char *table_name, *pg_delim = NULL, *pg_null_as = NULL;
int table_name_len, pg_delim_len, pg_null_as_len;
int pg_null_as_free = 0;
char *query;
HashPosition pos;
int id = -1;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|ss",
&pgsql_link, &table_name, &table_name_len, &pg_rows,
&pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) {
return;
}
if (!pg_delim) {
pg_delim = "\t";
}
if (!pg_null_as) {
pg_null_as = safe_estrdup("\\\\N");
pg_null_as_free = 1;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
spprintf(&query, 0, "COPY %s FROM STDIN DELIMITERS E'%c' WITH NULL AS E'%s'", table_name, *pg_delim, pg_null_as);
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
pgsql_result = PQexec(pgsql, query);
if (pg_null_as_free) {
efree(pg_null_as);
}
efree(query);
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
switch (status) {
case PGRES_COPY_IN:
if (pgsql_result) {
int command_failed = 0;
PQclear(pgsql_result);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pg_rows), &pos);
#if HAVE_PQPUTCOPYDATA
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
convert_to_string_ex(tmp);
query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
}
if (PQputCopyData(pgsql, query, strlen(query)) != 1) {
efree(query);
PHP_PQ_ERROR("copy failed: %s", pgsql);
RETURN_FALSE;
}
efree(query);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
}
if (PQputCopyEnd(pgsql, NULL) != 1) {
PHP_PQ_ERROR("putcopyend failed: %s", pgsql);
RETURN_FALSE;
}
#else
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
convert_to_string_ex(tmp);
query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
}
if (PQputline(pgsql, query)==EOF) {
efree(query);
PHP_PQ_ERROR("copy failed: %s", pgsql);
RETURN_FALSE;
}
efree(query);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
}
if (PQputline(pgsql, "\\.\n") == EOF) {
PHP_PQ_ERROR("putline failed: %s", pgsql);
RETURN_FALSE;
}
if (PQendcopy(pgsql)) {
PHP_PQ_ERROR("endcopy failed: %s", pgsql);
RETURN_FALSE;
}
#endif
while ((pgsql_result = PQgetResult(pgsql))) {
if (PGRES_COMMAND_OK != PQresultStatus(pgsql_result)) {
PHP_PQ_ERROR("Copy command failed: %s", pgsql);
command_failed = 1;
}
PQclear(pgsql_result);
}
if (command_failed) {
RETURN_FALSE;
}
} else {
PQclear(pgsql_result);
RETURN_FALSE;
}
RETURN_TRUE;
break;
default:
PQclear(pgsql_result);
PHP_PQ_ERROR("Copy command failed: %s", pgsql);
RETURN_FALSE;
break;
}
}
| Bypass | 0 | PHP_FUNCTION(pg_copy_from)
{
zval *pgsql_link = NULL, *pg_rows;
zval **tmp;
char *table_name, *pg_delim = NULL, *pg_null_as = NULL;
int table_name_len, pg_delim_len, pg_null_as_len;
int pg_null_as_free = 0;
char *query;
HashPosition pos;
int id = -1;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|ss",
&pgsql_link, &table_name, &table_name_len, &pg_rows,
&pg_delim, &pg_delim_len, &pg_null_as, &pg_null_as_len) == FAILURE) {
return;
}
if (!pg_delim) {
pg_delim = "\t";
}
if (!pg_null_as) {
pg_null_as = safe_estrdup("\\\\N");
pg_null_as_free = 1;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
spprintf(&query, 0, "COPY %s FROM STDIN DELIMITERS E'%c' WITH NULL AS E'%s'", table_name, *pg_delim, pg_null_as);
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
pgsql_result = PQexec(pgsql, query);
if (pg_null_as_free) {
efree(pg_null_as);
}
efree(query);
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
switch (status) {
case PGRES_COPY_IN:
if (pgsql_result) {
int command_failed = 0;
PQclear(pgsql_result);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pg_rows), &pos);
#if HAVE_PQPUTCOPYDATA
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
convert_to_string_ex(tmp);
query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
}
if (PQputCopyData(pgsql, query, strlen(query)) != 1) {
efree(query);
PHP_PQ_ERROR("copy failed: %s", pgsql);
RETURN_FALSE;
}
efree(query);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
}
if (PQputCopyEnd(pgsql, NULL) != 1) {
PHP_PQ_ERROR("putcopyend failed: %s", pgsql);
RETURN_FALSE;
}
#else
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
convert_to_string_ex(tmp);
query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
}
if (PQputline(pgsql, query)==EOF) {
efree(query);
PHP_PQ_ERROR("copy failed: %s", pgsql);
RETURN_FALSE;
}
efree(query);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
}
if (PQputline(pgsql, "\\.\n") == EOF) {
PHP_PQ_ERROR("putline failed: %s", pgsql);
RETURN_FALSE;
}
if (PQendcopy(pgsql)) {
PHP_PQ_ERROR("endcopy failed: %s", pgsql);
RETURN_FALSE;
}
#endif
while ((pgsql_result = PQgetResult(pgsql))) {
if (PGRES_COMMAND_OK != PQresultStatus(pgsql_result)) {
PHP_PQ_ERROR("Copy command failed: %s", pgsql);
command_failed = 1;
}
PQclear(pgsql_result);
}
if (command_failed) {
RETURN_FALSE;
}
} else {
PQclear(pgsql_result);
RETURN_FALSE;
}
RETURN_TRUE;
break;
default:
PQclear(pgsql_result);
PHP_PQ_ERROR("Copy command failed: %s", pgsql);
RETURN_FALSE;
break;
}
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,215 | PHP_FUNCTION(pg_get_notify)
{
zval *pgsql_link;
int id = -1;
long result_type = PGSQL_ASSOC;
PGconn *pgsql;
PGnotify *pgsql_notify;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r|l",
&pgsql_link, &result_type) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (!(result_type & PGSQL_BOTH)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid result type");
RETURN_FALSE;
}
PQconsumeInput(pgsql);
pgsql_notify = PQnotifies(pgsql);
if (!pgsql_notify) {
/* no notify message */
RETURN_FALSE;
}
array_init(return_value);
if (result_type & PGSQL_NUM) {
add_index_string(return_value, 0, pgsql_notify->relname, 1);
add_index_long(return_value, 1, pgsql_notify->be_pid);
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
#else
if (atof(PG_VERSION) >= 9.0) {
#endif
#if HAVE_PQPARAMETERSTATUS
add_index_string(return_value, 2, pgsql_notify->extra, 1);
#endif
}
}
if (result_type & PGSQL_ASSOC) {
add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
#else
if (atof(PG_VERSION) >= 9.0) {
#endif
#if HAVE_PQPARAMETERSTATUS
add_assoc_string(return_value, "payload", pgsql_notify->extra, 1);
#endif
}
}
PQfreemem(pgsql_notify);
}
/* }}} */
/* {{{ proto int pg_get_pid([resource connection)
Get backend(server) pid */
PHP_FUNCTION(pg_get_pid)
{
zval *pgsql_link;
int id = -1;
PGconn *pgsql;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r",
&pgsql_link) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
RETURN_LONG(PQbackendPID(pgsql));
}
/* }}} */
/* {{{ php_pgsql_meta_data
* TODO: Add meta_data cache for better performance
*/
PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC)
{
PGresult *pg_result;
char *src, *tmp_name, *tmp_name2 = NULL;
char *escaped;
smart_str querystr = {0};
size_t new_len;
int i, num_rows;
zval *elem;
if (!*table_name) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified");
return FAILURE;
}
src = estrdup(table_name);
tmp_name = php_strtok_r(src, ".", &tmp_name2);
if (!tmp_name2 || !*tmp_name2) {
/* Default schema */
tmp_name2 = tmp_name;
tmp_name = "public";
}
smart_str_appends(&querystr,
"SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotnull, a.atthasdef, a.attndims, t.typtype = 'e' "
"FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n "
"WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;");
smart_str_0(&querystr);
efree(src);
pg_result = PQexec(pg_link, querystr.c);
if (PQresultStatus(pg_result) != PGRES_TUPLES_OK || (num_rows = PQntuples(pg_result)) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Table '%s' doesn't exists", table_name);
smart_str_free(&querystr);
PQclear(pg_result);
return FAILURE;
}
smart_str_free(&querystr);
for (i = 0; i < num_rows; i++) {
char *name;
MAKE_STD_ZVAL(elem);
array_init(elem);
add_assoc_long(elem, "num", atoi(PQgetvalue(pg_result,i,1)));
add_assoc_string(elem, "type", PQgetvalue(pg_result,i,2), 1);
add_assoc_long(elem, "len", atoi(PQgetvalue(pg_result,i,3)));
if (!strcmp(PQgetvalue(pg_result,i,4), "t")) {
add_assoc_bool(elem, "not null", 1);
}
else {
add_assoc_bool(elem, "not null", 0);
}
if (!strcmp(PQgetvalue(pg_result,i,5), "t")) {
add_assoc_bool(elem, "has default", 1);
}
else {
add_assoc_bool(elem, "has default", 0);
}
add_assoc_long(elem, "array dims", atoi(PQgetvalue(pg_result,i,6)));
if (!strcmp(PQgetvalue(pg_result,i,7), "t")) {
add_assoc_bool(elem, "is enum", 1);
}
else {
add_assoc_bool(elem, "is enum", 0);
}
name = PQgetvalue(pg_result,i,0);
add_assoc_zval(meta, name, elem);
}
PQclear(pg_result);
return SUCCESS;
}
/* }}} */
/* {{{ proto array pg_meta_data(resource db, string table)
Get meta_data */
PHP_FUNCTION(pg_meta_data)
{
zval *pgsql_link;
char *table_name;
uint table_name_len;
PGconn *pgsql;
int id = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
&pgsql_link, &table_name, &table_name_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
array_init(return_value);
if (php_pgsql_meta_data(pgsql, table_name, return_value TSRMLS_CC) == FAILURE) {
zval_dtor(return_value); /* destroy array */
RETURN_FALSE;
}
else {
HashPosition pos;
zval **val;
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(return_value), &pos);
zend_hash_get_current_data_ex(Z_ARRVAL_P(return_value), (void **)&val, &pos) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(return_value), &pos)) {
/* delete newly added entry, in order to keep BC */
zend_hash_del_key_or_index(Z_ARRVAL_PP(val), "is enum", sizeof("is enum"), 0, HASH_DEL_KEY);
}
}
}
/* }}} */
/* {{{ php_pgsql_get_data_type
*/
static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t len)
{
/* This is stupid way to do. I'll fix it when I decied how to support
user defined types. (Yasuo) */
/* boolean */
if (!strcmp(type_name, "bool")|| !strcmp(type_name, "boolean"))
return PG_BOOL;
/* object id */
if (!strcmp(type_name, "oid"))
return PG_OID;
/* integer */
if (!strcmp(type_name, "int2") || !strcmp(type_name, "smallint"))
return PG_INT2;
if (!strcmp(type_name, "int4") || !strcmp(type_name, "integer"))
return PG_INT4;
if (!strcmp(type_name, "int8") || !strcmp(type_name, "bigint"))
return PG_INT8;
/* real and other */
if (!strcmp(type_name, "float4") || !strcmp(type_name, "real"))
return PG_FLOAT4;
if (!strcmp(type_name, "float8") || !strcmp(type_name, "double precision"))
return PG_FLOAT8;
if (!strcmp(type_name, "numeric"))
return PG_NUMERIC;
if (!strcmp(type_name, "money"))
return PG_MONEY;
/* character */
if (!strcmp(type_name, "text"))
return PG_TEXT;
if (!strcmp(type_name, "bpchar") || !strcmp(type_name, "character"))
return PG_CHAR;
if (!strcmp(type_name, "varchar") || !strcmp(type_name, "character varying"))
return PG_VARCHAR;
/* time and interval */
if (!strcmp(type_name, "abstime"))
return PG_UNIX_TIME;
if (!strcmp(type_name, "reltime"))
return PG_UNIX_TIME_INTERVAL;
if (!strcmp(type_name, "tinterval"))
return PG_UNIX_TIME_INTERVAL;
if (!strcmp(type_name, "date"))
return PG_DATE;
if (!strcmp(type_name, "time"))
return PG_TIME;
if (!strcmp(type_name, "time with time zone") || !strcmp(type_name, "timetz"))
return PG_TIME_WITH_TIMEZONE;
if (!strcmp(type_name, "timestamp without time zone") || !strcmp(type_name, "timestamp"))
return PG_TIMESTAMP;
if (!strcmp(type_name, "timestamp with time zone") || !strcmp(type_name, "timestamptz"))
return PG_TIMESTAMP_WITH_TIMEZONE;
if (!strcmp(type_name, "interval"))
return PG_INTERVAL;
/* binary */
if (!strcmp(type_name, "bytea"))
return PG_BYTEA;
/* network */
if (!strcmp(type_name, "cidr"))
return PG_CIDR;
if (!strcmp(type_name, "inet"))
return PG_INET;
if (!strcmp(type_name, "macaddr"))
return PG_MACADDR;
/* bit */
if (!strcmp(type_name, "bit"))
return PG_BIT;
if (!strcmp(type_name, "bit varying"))
return PG_VARBIT;
/* geometric */
if (!strcmp(type_name, "line"))
return PG_LINE;
if (!strcmp(type_name, "lseg"))
return PG_LSEG;
if (!strcmp(type_name, "box"))
return PG_BOX;
if (!strcmp(type_name, "path"))
return PG_PATH;
if (!strcmp(type_name, "point"))
return PG_POINT;
if (!strcmp(type_name, "polygon"))
return PG_POLYGON;
if (!strcmp(type_name, "circle"))
return PG_CIRCLE;
return PG_UNKNOWN;
}
/* }}} */
/* {{{ php_pgsql_convert_match
* test field value with regular expression specified.
*/
static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , int icase TSRMLS_DC)
{
regex_t re;
regmatch_t *subs;
int regopt = REG_EXTENDED;
int regerr, ret = SUCCESS;
int i;
/* Check invalid chars for POSIX regex */
for (i = 0; i < str_len; i++) {
if (str[i] == '\n' ||
str[i] == '\r' ||
str[i] == '\0' ) {
return FAILURE;
}
}
if (icase) {
regopt |= REG_ICASE;
}
regerr = regcomp(&re, regex, regopt);
if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex");
regfree(&re);
return FAILURE;
}
subs = (regmatch_t *)ecalloc(sizeof(regmatch_t), re.re_nsub+1);
regerr = regexec(&re, str, re.re_nsub+1, subs, 0);
if (regerr == REG_NOMATCH) {
#ifdef PHP_DEBUG
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex);
#endif
ret = FAILURE;
}
else if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot exec regex");
ret = FAILURE;
}
regfree(&re);
efree(subs);
return ret;
}
/* }}} */
/* {{{ php_pgsql_add_quote
* add quotes around string.
*/
static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC)
{
smart_str str = {0};
assert(Z_TYPE_P(src) == IS_STRING);
assert(should_free == 1 || should_free == 0);
smart_str_appendc(&str, 'E');
smart_str_appendc(&str, '\'');
smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src));
smart_str_appendc(&str, '\'');
smart_str_0(&str);
if (should_free) {
efree(Z_STRVAL_P(src));
}
Z_STRVAL_P(src) = str.c;
Z_STRLEN_P(src) = str.len;
return SUCCESS;
}
/* }}} */
#define PGSQL_CONV_CHECK_IGNORE() \
if (!err && Z_TYPE_P(new_val) == IS_STRING && !strcmp(Z_STRVAL_P(new_val), "NULL")) { \
| Bypass | 0 | PHP_FUNCTION(pg_get_notify)
{
zval *pgsql_link;
int id = -1;
long result_type = PGSQL_ASSOC;
PGconn *pgsql;
PGnotify *pgsql_notify;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r|l",
&pgsql_link, &result_type) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (!(result_type & PGSQL_BOTH)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid result type");
RETURN_FALSE;
}
PQconsumeInput(pgsql);
pgsql_notify = PQnotifies(pgsql);
if (!pgsql_notify) {
/* no notify message */
RETURN_FALSE;
}
array_init(return_value);
if (result_type & PGSQL_NUM) {
add_index_string(return_value, 0, pgsql_notify->relname, 1);
add_index_long(return_value, 1, pgsql_notify->be_pid);
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
#else
if (atof(PG_VERSION) >= 9.0) {
#endif
#if HAVE_PQPARAMETERSTATUS
add_index_string(return_value, 2, pgsql_notify->extra, 1);
#endif
}
}
if (result_type & PGSQL_ASSOC) {
add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
#else
if (atof(PG_VERSION) >= 9.0) {
#endif
#if HAVE_PQPARAMETERSTATUS
add_assoc_string(return_value, "payload", pgsql_notify->extra, 1);
#endif
}
}
PQfreemem(pgsql_notify);
}
/* }}} */
/* {{{ proto int pg_get_pid([resource connection)
Get backend(server) pid */
PHP_FUNCTION(pg_get_pid)
{
zval *pgsql_link;
int id = -1;
PGconn *pgsql;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r",
&pgsql_link) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
RETURN_LONG(PQbackendPID(pgsql));
}
/* }}} */
/* {{{ php_pgsql_meta_data
* TODO: Add meta_data cache for better performance
*/
PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC)
{
PGresult *pg_result;
char *src, *tmp_name, *tmp_name2 = NULL;
char *escaped;
smart_str querystr = {0};
size_t new_len;
int i, num_rows;
zval *elem;
if (!*table_name) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified");
return FAILURE;
}
src = estrdup(table_name);
tmp_name = php_strtok_r(src, ".", &tmp_name2);
if (!tmp_name2 || !*tmp_name2) {
/* Default schema */
tmp_name2 = tmp_name;
tmp_name = "public";
}
smart_str_appends(&querystr,
"SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotnull, a.atthasdef, a.attndims, t.typtype = 'e' "
"FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n "
"WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;");
smart_str_0(&querystr);
efree(src);
pg_result = PQexec(pg_link, querystr.c);
if (PQresultStatus(pg_result) != PGRES_TUPLES_OK || (num_rows = PQntuples(pg_result)) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Table '%s' doesn't exists", table_name);
smart_str_free(&querystr);
PQclear(pg_result);
return FAILURE;
}
smart_str_free(&querystr);
for (i = 0; i < num_rows; i++) {
char *name;
MAKE_STD_ZVAL(elem);
array_init(elem);
add_assoc_long(elem, "num", atoi(PQgetvalue(pg_result,i,1)));
add_assoc_string(elem, "type", PQgetvalue(pg_result,i,2), 1);
add_assoc_long(elem, "len", atoi(PQgetvalue(pg_result,i,3)));
if (!strcmp(PQgetvalue(pg_result,i,4), "t")) {
add_assoc_bool(elem, "not null", 1);
}
else {
add_assoc_bool(elem, "not null", 0);
}
if (!strcmp(PQgetvalue(pg_result,i,5), "t")) {
add_assoc_bool(elem, "has default", 1);
}
else {
add_assoc_bool(elem, "has default", 0);
}
add_assoc_long(elem, "array dims", atoi(PQgetvalue(pg_result,i,6)));
if (!strcmp(PQgetvalue(pg_result,i,7), "t")) {
add_assoc_bool(elem, "is enum", 1);
}
else {
add_assoc_bool(elem, "is enum", 0);
}
name = PQgetvalue(pg_result,i,0);
add_assoc_zval(meta, name, elem);
}
PQclear(pg_result);
return SUCCESS;
}
/* }}} */
/* {{{ proto array pg_meta_data(resource db, string table)
Get meta_data */
PHP_FUNCTION(pg_meta_data)
{
zval *pgsql_link;
char *table_name;
uint table_name_len;
PGconn *pgsql;
int id = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
&pgsql_link, &table_name, &table_name_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
array_init(return_value);
if (php_pgsql_meta_data(pgsql, table_name, return_value TSRMLS_CC) == FAILURE) {
zval_dtor(return_value); /* destroy array */
RETURN_FALSE;
}
else {
HashPosition pos;
zval **val;
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(return_value), &pos);
zend_hash_get_current_data_ex(Z_ARRVAL_P(return_value), (void **)&val, &pos) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(return_value), &pos)) {
/* delete newly added entry, in order to keep BC */
zend_hash_del_key_or_index(Z_ARRVAL_PP(val), "is enum", sizeof("is enum"), 0, HASH_DEL_KEY);
}
}
}
/* }}} */
/* {{{ php_pgsql_get_data_type
*/
static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t len)
{
/* This is stupid way to do. I'll fix it when I decied how to support
user defined types. (Yasuo) */
/* boolean */
if (!strcmp(type_name, "bool")|| !strcmp(type_name, "boolean"))
return PG_BOOL;
/* object id */
if (!strcmp(type_name, "oid"))
return PG_OID;
/* integer */
if (!strcmp(type_name, "int2") || !strcmp(type_name, "smallint"))
return PG_INT2;
if (!strcmp(type_name, "int4") || !strcmp(type_name, "integer"))
return PG_INT4;
if (!strcmp(type_name, "int8") || !strcmp(type_name, "bigint"))
return PG_INT8;
/* real and other */
if (!strcmp(type_name, "float4") || !strcmp(type_name, "real"))
return PG_FLOAT4;
if (!strcmp(type_name, "float8") || !strcmp(type_name, "double precision"))
return PG_FLOAT8;
if (!strcmp(type_name, "numeric"))
return PG_NUMERIC;
if (!strcmp(type_name, "money"))
return PG_MONEY;
/* character */
if (!strcmp(type_name, "text"))
return PG_TEXT;
if (!strcmp(type_name, "bpchar") || !strcmp(type_name, "character"))
return PG_CHAR;
if (!strcmp(type_name, "varchar") || !strcmp(type_name, "character varying"))
return PG_VARCHAR;
/* time and interval */
if (!strcmp(type_name, "abstime"))
return PG_UNIX_TIME;
if (!strcmp(type_name, "reltime"))
return PG_UNIX_TIME_INTERVAL;
if (!strcmp(type_name, "tinterval"))
return PG_UNIX_TIME_INTERVAL;
if (!strcmp(type_name, "date"))
return PG_DATE;
if (!strcmp(type_name, "time"))
return PG_TIME;
if (!strcmp(type_name, "time with time zone") || !strcmp(type_name, "timetz"))
return PG_TIME_WITH_TIMEZONE;
if (!strcmp(type_name, "timestamp without time zone") || !strcmp(type_name, "timestamp"))
return PG_TIMESTAMP;
if (!strcmp(type_name, "timestamp with time zone") || !strcmp(type_name, "timestamptz"))
return PG_TIMESTAMP_WITH_TIMEZONE;
if (!strcmp(type_name, "interval"))
return PG_INTERVAL;
/* binary */
if (!strcmp(type_name, "bytea"))
return PG_BYTEA;
/* network */
if (!strcmp(type_name, "cidr"))
return PG_CIDR;
if (!strcmp(type_name, "inet"))
return PG_INET;
if (!strcmp(type_name, "macaddr"))
return PG_MACADDR;
/* bit */
if (!strcmp(type_name, "bit"))
return PG_BIT;
if (!strcmp(type_name, "bit varying"))
return PG_VARBIT;
/* geometric */
if (!strcmp(type_name, "line"))
return PG_LINE;
if (!strcmp(type_name, "lseg"))
return PG_LSEG;
if (!strcmp(type_name, "box"))
return PG_BOX;
if (!strcmp(type_name, "path"))
return PG_PATH;
if (!strcmp(type_name, "point"))
return PG_POINT;
if (!strcmp(type_name, "polygon"))
return PG_POLYGON;
if (!strcmp(type_name, "circle"))
return PG_CIRCLE;
return PG_UNKNOWN;
}
/* }}} */
/* {{{ php_pgsql_convert_match
* test field value with regular expression specified.
*/
static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , int icase TSRMLS_DC)
{
regex_t re;
regmatch_t *subs;
int regopt = REG_EXTENDED;
int regerr, ret = SUCCESS;
int i;
/* Check invalid chars for POSIX regex */
for (i = 0; i < str_len; i++) {
if (str[i] == '\n' ||
str[i] == '\r' ||
str[i] == '\0' ) {
return FAILURE;
}
}
if (icase) {
regopt |= REG_ICASE;
}
regerr = regcomp(&re, regex, regopt);
if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex");
regfree(&re);
return FAILURE;
}
subs = (regmatch_t *)ecalloc(sizeof(regmatch_t), re.re_nsub+1);
regerr = regexec(&re, str, re.re_nsub+1, subs, 0);
if (regerr == REG_NOMATCH) {
#ifdef PHP_DEBUG
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex);
#endif
ret = FAILURE;
}
else if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot exec regex");
ret = FAILURE;
}
regfree(&re);
efree(subs);
return ret;
}
/* }}} */
/* {{{ php_pgsql_add_quote
* add quotes around string.
*/
static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC)
{
smart_str str = {0};
assert(Z_TYPE_P(src) == IS_STRING);
assert(should_free == 1 || should_free == 0);
smart_str_appendc(&str, 'E');
smart_str_appendc(&str, '\'');
smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src));
smart_str_appendc(&str, '\'');
smart_str_0(&str);
if (should_free) {
efree(Z_STRVAL_P(src));
}
Z_STRVAL_P(src) = str.c;
Z_STRLEN_P(src) = str.len;
return SUCCESS;
}
/* }}} */
#define PGSQL_CONV_CHECK_IGNORE() \
if (!err && Z_TYPE_P(new_val) == IS_STRING && !strcmp(Z_STRVAL_P(new_val), "NULL")) { \
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,216 | PHP_FUNCTION(pg_insert)
{
zval *pgsql_link, *values;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l",
&pgsql_link, &table, &table_len, &values, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
if (php_pgsql_insert(pg_link, table, values, option, &sql TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
RETURN_STRING(sql, 0);
}
RETURN_TRUE;
}
| Bypass | 0 | PHP_FUNCTION(pg_insert)
{
zval *pgsql_link, *values;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l",
&pgsql_link, &table, &table_len, &values, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
if (php_pgsql_insert(pg_link, table, values, option, &sql TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
RETURN_STRING(sql, 0);
}
RETURN_TRUE;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,217 | PHP_FUNCTION(pg_update)
{
zval *pgsql_link, *values, *ids;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsaa|l",
&pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
if (php_pgsql_update(pg_link, table, values, ids, option, &sql TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
RETURN_STRING(sql, 0);
}
RETURN_TRUE;
}
| Bypass | 0 | PHP_FUNCTION(pg_update)
{
zval *pgsql_link, *values, *ids;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsaa|l",
&pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
if (php_pgsql_update(pg_link, table, values, ids, option, &sql TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
RETURN_STRING(sql, 0);
}
RETURN_TRUE;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,218 | PHP_FUNCTION(pg_delete)
{
zval *pgsql_link, *ids;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l",
&pgsql_link, &table, &table_len, &ids, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
if (php_pgsql_delete(pg_link, table, ids, option, &sql TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
RETURN_STRING(sql, 0);
}
RETURN_TRUE;
}
| Bypass | 0 | PHP_FUNCTION(pg_delete)
{
zval *pgsql_link, *ids;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l",
&pgsql_link, &table, &table_len, &ids, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
if (php_pgsql_delete(pg_link, table, ids, option, &sql TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
RETURN_STRING(sql, 0);
}
RETURN_TRUE;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,219 | PHP_FUNCTION(pg_select)
{
zval *pgsql_link, *ids;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l",
&pgsql_link, &table, &table_len, &ids, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
array_init(return_value);
if (php_pgsql_select(pg_link, table, ids, return_value, option, &sql TSRMLS_CC) == FAILURE) {
zval_dtor(return_value);
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
zval_dtor(return_value);
RETURN_STRING(sql, 0);
}
return;
}
| Bypass | 0 | PHP_FUNCTION(pg_select)
{
zval *pgsql_link, *ids;
char *table, *sql = NULL;
int table_len;
ulong option = PGSQL_DML_EXEC;
PGconn *pg_link;
int id = -1, argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rsa|l",
&pgsql_link, &table, &table_len, &ids, &option) == FAILURE) {
return;
}
if (option & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid option is specified");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (php_pgsql_flush_query(pg_link TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected unhandled result(s) in connection");
}
array_init(return_value);
if (php_pgsql_select(pg_link, table, ids, return_value, option, &sql TSRMLS_CC) == FAILURE) {
zval_dtor(return_value);
RETURN_FALSE;
}
if (option & PGSQL_DML_STRING) {
zval_dtor(return_value);
RETURN_STRING(sql, 0);
}
return;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,220 | static inline int build_assignment_string(smart_str *querystr, HashTable *ht, int where_cond, const char *pad, int pad_len TSRMLS_DC)
{
HashPosition pos;
uint fld_len;
int key_type;
ulong num_idx;
char *fld;
char buf[256];
zval **val;
for (zend_hash_internal_pointer_reset_ex(ht, &pos);
zend_hash_get_current_data_ex(ht, (void **)&val, &pos) == SUCCESS;
zend_hash_move_forward_ex(ht, &pos)) {
key_type = zend_hash_get_current_key_ex(ht, &fld, &fld_len, &num_idx, 0, &pos);
if (key_type == HASH_KEY_IS_LONG) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects associative array for values to be inserted");
return -1;
}
smart_str_appendl(querystr, fld, fld_len - 1);
if (where_cond && Z_TYPE_PP(val) == IS_STRING && !strcmp(Z_STRVAL_PP(val), "NULL")) {
smart_str_appends(querystr, " IS ");
} else {
smart_str_appendc(querystr, '=');
}
switch(Z_TYPE_PP(val)) {
case IS_STRING:
smart_str_appendl(querystr, Z_STRVAL_PP(val), Z_STRLEN_PP(val));
break;
case IS_LONG:
smart_str_append_long(querystr, Z_LVAL_PP(val));
break;
case IS_DOUBLE:
smart_str_appendl(querystr, buf, MIN(snprintf(buf, sizeof(buf), "%F", Z_DVAL_PP(val)), sizeof(buf)-1));
break;
default:
/* should not happen */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects scaler values other than NULL. Need to convert?");
return -1;
}
smart_str_appendl(querystr, pad, pad_len);
}
querystr->len -= pad_len;
return 0;
}
| Bypass | 0 | static inline int build_assignment_string(smart_str *querystr, HashTable *ht, int where_cond, const char *pad, int pad_len TSRMLS_DC)
{
HashPosition pos;
uint fld_len;
int key_type;
ulong num_idx;
char *fld;
char buf[256];
zval **val;
for (zend_hash_internal_pointer_reset_ex(ht, &pos);
zend_hash_get_current_data_ex(ht, (void **)&val, &pos) == SUCCESS;
zend_hash_move_forward_ex(ht, &pos)) {
key_type = zend_hash_get_current_key_ex(ht, &fld, &fld_len, &num_idx, 0, &pos);
if (key_type == HASH_KEY_IS_LONG) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects associative array for values to be inserted");
return -1;
}
smart_str_appendl(querystr, fld, fld_len - 1);
if (where_cond && Z_TYPE_PP(val) == IS_STRING && !strcmp(Z_STRVAL_PP(val), "NULL")) {
smart_str_appends(querystr, " IS ");
} else {
smart_str_appendc(querystr, '=');
}
switch(Z_TYPE_PP(val)) {
case IS_STRING:
smart_str_appendl(querystr, Z_STRVAL_PP(val), Z_STRLEN_PP(val));
break;
case IS_LONG:
smart_str_append_long(querystr, Z_LVAL_PP(val));
break;
case IS_DOUBLE:
smart_str_appendl(querystr, buf, MIN(snprintf(buf, sizeof(buf), "%F", Z_DVAL_PP(val)), sizeof(buf)-1));
break;
default:
/* should not happen */
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects scaler values other than NULL. Need to convert?");
return -1;
}
smart_str_appendl(querystr, pad, pad_len);
}
querystr->len -= pad_len;
return 0;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,221 | static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const char *table)
{
char *table_copy, *escaped, *token, *tmp;
size_t len;
/* schame.table should be "schame"."table" */
table_copy = estrdup(table);
token = php_strtok_r(table_copy, ".", &tmp);
if (token == NULL) {
token = table;
}
len = strlen(token);
if (_php_pgsql_detect_identifier_escape(token, len) == SUCCESS) {
smart_str_appendl(querystr, token, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, token, len);
smart_str_appends(querystr, escaped);
PGSQLfree(escaped);
}
if (tmp && *tmp) {
len = strlen(tmp);
/* "schema"."table" format */
if (_php_pgsql_detect_identifier_escape(tmp, len) == SUCCESS) {
smart_str_appendc(querystr, '.');
smart_str_appendl(querystr, tmp, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, tmp, len);
smart_str_appendc(querystr, '.');
smart_str_appends(querystr, escaped);
PGSQLfree(escaped);
}
}
efree(table_copy);
}
| Bypass | 0 | static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const char *table)
{
char *table_copy, *escaped, *token, *tmp;
size_t len;
/* schame.table should be "schame"."table" */
table_copy = estrdup(table);
token = php_strtok_r(table_copy, ".", &tmp);
if (token == NULL) {
token = table;
}
len = strlen(token);
if (_php_pgsql_detect_identifier_escape(token, len) == SUCCESS) {
smart_str_appendl(querystr, token, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, token, len);
smart_str_appends(querystr, escaped);
PGSQLfree(escaped);
}
if (tmp && *tmp) {
len = strlen(tmp);
/* "schema"."table" format */
if (_php_pgsql_detect_identifier_escape(tmp, len) == SUCCESS) {
smart_str_appendc(querystr, '.');
smart_str_appendl(querystr, tmp, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, tmp, len);
smart_str_appendc(querystr, '.');
smart_str_appends(querystr, escaped);
PGSQLfree(escaped);
}
}
efree(table_copy);
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,222 | static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, ulong opt TSRMLS_DC)
{
if (opt & PGSQL_DML_ASYNC) {
if (PQsendQuery(pg_link, querystr->c)) {
return 0;
}
}
else {
PGresult *pg_result;
pg_result = PQexec(pg_link, querystr->c);
if (PQresultStatus(pg_result) == expect) {
PQclear(pg_result);
return 0;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", PQresultErrorMessage(pg_result));
PQclear(pg_result);
}
}
return -1;
}
| Bypass | 0 | static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, ulong opt TSRMLS_DC)
{
if (opt & PGSQL_DML_ASYNC) {
if (PQsendQuery(pg_link, querystr->c)) {
return 0;
}
}
else {
PGresult *pg_result;
pg_result = PQexec(pg_link, querystr->c);
if (PQresultStatus(pg_result) == expect) {
PQclear(pg_result);
return 0;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", PQresultErrorMessage(pg_result));
PQclear(pg_result);
}
}
return -1;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,223 | static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC)
{
PGresult *result;
smart_str str = {0};
zend_rsrc_list_entry *field_type;
char *ret=NULL;
/* try to lookup the type in the resource list */
smart_str_appends(&str, "pgsql_oid_");
smart_str_append_unsigned(&str, oid);
smart_str_0(&str);
if (zend_hash_find(list,str.c,str.len+1,(void **) &field_type)==SUCCESS) {
ret = estrdup((char *)field_type->ptr);
} else { /* hash all oid's */
int i,num_rows;
int oid_offset,name_offset;
char *tmp_oid, *end_ptr, *tmp_name;
zend_rsrc_list_entry new_oid_entry;
if ((result = PQexec(pgsql,"select oid,typname from pg_type")) == NULL || PQresultStatus(result) != PGRES_TUPLES_OK) {
if (result) {
PQclear(result);
}
smart_str_free(&str);
return STR_EMPTY_ALLOC();
}
num_rows = PQntuples(result);
oid_offset = PQfnumber(result,"oid");
name_offset = PQfnumber(result,"typname");
for (i=0; i<num_rows; i++) {
if ((tmp_oid = PQgetvalue(result,i,oid_offset))==NULL) {
continue;
}
str.len = 0;
smart_str_appends(&str, "pgsql_oid_");
smart_str_appends(&str, tmp_oid);
smart_str_0(&str);
if ((tmp_name = PQgetvalue(result,i,name_offset))==NULL) {
continue;
}
Z_TYPE(new_oid_entry) = le_string;
new_oid_entry.ptr = estrdup(tmp_name);
zend_hash_update(list,str.c,str.len+1,(void *) &new_oid_entry, sizeof(zend_rsrc_list_entry), NULL);
if (!ret && strtoul(tmp_oid, &end_ptr, 10)==oid) {
ret = estrdup(tmp_name);
}
}
PQclear(result);
}
smart_str_free(&str);
return ret;
}
| Bypass | 0 | static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC)
{
PGresult *result;
smart_str str = {0};
zend_rsrc_list_entry *field_type;
char *ret=NULL;
/* try to lookup the type in the resource list */
smart_str_appends(&str, "pgsql_oid_");
smart_str_append_unsigned(&str, oid);
smart_str_0(&str);
if (zend_hash_find(list,str.c,str.len+1,(void **) &field_type)==SUCCESS) {
ret = estrdup((char *)field_type->ptr);
} else { /* hash all oid's */
int i,num_rows;
int oid_offset,name_offset;
char *tmp_oid, *end_ptr, *tmp_name;
zend_rsrc_list_entry new_oid_entry;
if ((result = PQexec(pgsql,"select oid,typname from pg_type")) == NULL || PQresultStatus(result) != PGRES_TUPLES_OK) {
if (result) {
PQclear(result);
}
smart_str_free(&str);
return STR_EMPTY_ALLOC();
}
num_rows = PQntuples(result);
oid_offset = PQfnumber(result,"oid");
name_offset = PQfnumber(result,"typname");
for (i=0; i<num_rows; i++) {
if ((tmp_oid = PQgetvalue(result,i,oid_offset))==NULL) {
continue;
}
str.len = 0;
smart_str_appends(&str, "pgsql_oid_");
smart_str_appends(&str, tmp_oid);
smart_str_0(&str);
if ((tmp_name = PQgetvalue(result,i,name_offset))==NULL) {
continue;
}
Z_TYPE(new_oid_entry) = le_string;
new_oid_entry.ptr = estrdup(tmp_name);
zend_hash_update(list,str.c,str.len+1,(void *) &new_oid_entry, sizeof(zend_rsrc_list_entry), NULL);
if (!ret && strtoul(tmp_oid, &end_ptr, 10)==oid) {
ret = estrdup(tmp_name);
}
}
PQclear(result);
}
smart_str_free(&str);
return ret;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,224 | static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t len, int escape_literal, int safe) {
char *result, *rp, *s;
size_t tmp_len;
if (!conn) {
return NULL;
}
/* allocate enough memory */
rp = result = (char *)safe_emalloc(len, 2, 5); /* leading " E" needs extra 2 bytes + quote_chars on both end for 2 bytes + NULL */
if (escape_literal) {
size_t new_len;
if (safe) {
char *tmp = (char *)safe_emalloc(len, 2, 1);
*rp++ = '\'';
/* PQescapeString does not escape \, but it handles multibyte chars safely.
This escape is incompatible with PQescapeLiteral. */
new_len = PQescapeStringConn(conn, tmp, str, len, NULL);
strncpy(rp, tmp, new_len);
efree(tmp);
rp += new_len;
} else {
char *encoding;
/* This is compatible with PQescapeLiteral, but it cannot handle multbyte chars
such as SJIS, BIG5. Raise warning and return NULL by checking
client_encoding. */
encoding = (char *) pg_encoding_to_char(PQclientEncoding(conn));
if (!strncmp(encoding, "SJIS", sizeof("SJIS")-1) ||
!strncmp(encoding, "SHIFT_JIS_2004", sizeof("SHIFT_JIS_2004")-1) ||
!strncmp(encoding, "BIG5", sizeof("BIG5")-1) ||
!strncmp(encoding, "GB18030", sizeof("GB18030")-1) ||
!strncmp(encoding, "GBK", sizeof("GBK")-1) ||
!strncmp(encoding, "JOHAB", sizeof("JOHAB")-1) ||
!strncmp(encoding, "UHC", sizeof("UHC")-1) ) {
TSRMLS_FETCH();
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsafe encoding is used. Do not use '%s' encoding or use PostgreSQL 9.0 or later libpq.", encoding);
}
/* check backslashes */
tmp_len = strspn(str, "\\");
if (tmp_len != len) {
/* add " E" for escaping slashes */
*rp++ = ' ';
*rp++ = 'E';
}
*rp++ = '\'';
for (s = (char *)str; s - str < len; ++s) {
if (*s == '\'' || *s == '\\') {
*rp++ = *s;
*rp++ = *s;
} else {
*rp++ = *s;
}
}
}
*rp++ = '\'';
} else {
/* Identifier escape. */
*rp++ = '"';
for (s = (char *)str; s - str < len; ++s) {
if (*s == '"') {
*rp++ = '"';
*rp++ = '"';
} else {
*rp++ = *s;
}
}
*rp++ = '"';
}
*rp = '\0';
return result;
}
| Bypass | 0 | static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t len, int escape_literal, int safe) {
char *result, *rp, *s;
size_t tmp_len;
if (!conn) {
return NULL;
}
/* allocate enough memory */
rp = result = (char *)safe_emalloc(len, 2, 5); /* leading " E" needs extra 2 bytes + quote_chars on both end for 2 bytes + NULL */
if (escape_literal) {
size_t new_len;
if (safe) {
char *tmp = (char *)safe_emalloc(len, 2, 1);
*rp++ = '\'';
/* PQescapeString does not escape \, but it handles multibyte chars safely.
This escape is incompatible with PQescapeLiteral. */
new_len = PQescapeStringConn(conn, tmp, str, len, NULL);
strncpy(rp, tmp, new_len);
efree(tmp);
rp += new_len;
} else {
char *encoding;
/* This is compatible with PQescapeLiteral, but it cannot handle multbyte chars
such as SJIS, BIG5. Raise warning and return NULL by checking
client_encoding. */
encoding = (char *) pg_encoding_to_char(PQclientEncoding(conn));
if (!strncmp(encoding, "SJIS", sizeof("SJIS")-1) ||
!strncmp(encoding, "SHIFT_JIS_2004", sizeof("SHIFT_JIS_2004")-1) ||
!strncmp(encoding, "BIG5", sizeof("BIG5")-1) ||
!strncmp(encoding, "GB18030", sizeof("GB18030")-1) ||
!strncmp(encoding, "GBK", sizeof("GBK")-1) ||
!strncmp(encoding, "JOHAB", sizeof("JOHAB")-1) ||
!strncmp(encoding, "UHC", sizeof("UHC")-1) ) {
TSRMLS_FETCH();
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsafe encoding is used. Do not use '%s' encoding or use PostgreSQL 9.0 or later libpq.", encoding);
}
/* check backslashes */
tmp_len = strspn(str, "\\");
if (tmp_len != len) {
/* add " E" for escaping slashes */
*rp++ = ' ';
*rp++ = 'E';
}
*rp++ = '\'';
for (s = (char *)str; s - str < len; ++s) {
if (*s == '\'' || *s == '\\') {
*rp++ = *s;
*rp++ = *s;
} else {
*rp++ = *s;
}
}
}
*rp++ = '\'';
} else {
/* Identifier escape. */
*rp++ = '"';
for (s = (char *)str; s - str < len; ++s) {
if (*s == '"') {
*rp++ = '"';
*rp++ = '"';
} else {
*rp++ = *s;
}
}
*rp++ = '"';
}
*rp = '\0';
return result;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,225 | static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC)
{
smart_str str = {0};
assert(Z_TYPE_P(src) == IS_STRING);
assert(should_free == 1 || should_free == 0);
smart_str_appendc(&str, 'E');
smart_str_appendc(&str, '\'');
smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src));
smart_str_appendc(&str, '\'');
smart_str_0(&str);
if (should_free) {
efree(Z_STRVAL_P(src));
}
Z_STRVAL_P(src) = str.c;
Z_STRLEN_P(src) = str.len;
return SUCCESS;
}
| Bypass | 0 | static int php_pgsql_add_quotes(zval *src, zend_bool should_free TSRMLS_DC)
{
smart_str str = {0};
assert(Z_TYPE_P(src) == IS_STRING);
assert(should_free == 1 || should_free == 0);
smart_str_appendc(&str, 'E');
smart_str_appendc(&str, '\'');
smart_str_appendl(&str, Z_STRVAL_P(src), Z_STRLEN_P(src));
smart_str_appendc(&str, '\'');
smart_str_0(&str);
if (should_free) {
efree(Z_STRVAL_P(src));
}
Z_STRVAL_P(src) = str.c;
Z_STRLEN_P(src) = str.len;
return SUCCESS;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,226 | PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC)
{
HashPosition pos;
char *field = NULL;
uint field_len = -1;
ulong num_idx = -1;
zval *meta, **def, **type, **not_null, **has_default, **is_enum, **val, *new_val;
int key_type, err = 0, skip_field;
php_pgsql_data_type data_type;
assert(pg_link != NULL);
assert(Z_TYPE_P(values) == IS_ARRAY);
assert(Z_TYPE_P(result) == IS_ARRAY);
assert(!(opt & ~PGSQL_CONV_OPTS));
if (!table_name) {
return FAILURE;
}
MAKE_STD_ZVAL(meta);
array_init(meta);
/* table_name is escaped by php_pgsql_meta_data */
if (php_pgsql_meta_data(pg_link, table_name, meta TSRMLS_CC) == FAILURE) {
zval_dtor(meta);
FREE_ZVAL(meta);
return FAILURE;
}
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos);
zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&val, &pos) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos)) {
skip_field = 0;
new_val = NULL;
if ((key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &field, &field_len, &num_idx, 0, &pos)) == HASH_KEY_NON_EXISTANT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to get array key type");
err = 1;
}
if (!err && key_type == HASH_KEY_IS_LONG) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Accepts only string key for values");
err = 1;
}
if (!err && key_type == HASH_KEY_NON_EXISTANT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Accepts only string key for values");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_P(meta), field, field_len, (void **)&def) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid field name (%s) in values", field);
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "type", sizeof("type"), (void **)&type) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'type'");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "not null", sizeof("not null"), (void **)¬_null) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'not null'");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "has default", sizeof("has default"), (void **)&has_default) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'has default'");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "is enum", sizeof("is enum"), (void **)&is_enum) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'is enum'");
err = 1;
}
if (!err && (Z_TYPE_PP(val) == IS_ARRAY ||
Z_TYPE_PP(val) == IS_OBJECT ||
Z_TYPE_PP(val) == IS_CONSTANT_ARRAY)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects scalar values as field values");
err = 1;
}
if (err) {
break; /* break out for() */
}
ALLOC_INIT_ZVAL(new_val);
if (Z_BVAL_PP(is_enum)) {
/* enums need to be treated like strings */
data_type = PG_TEXT;
}
else {
data_type = php_pgsql_get_data_type(Z_STRVAL_PP(type), Z_STRLEN_PP(type));
}
switch(data_type)
{
case PG_BOOL:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
if (!strcmp(Z_STRVAL_PP(val), "t") || !strcmp(Z_STRVAL_PP(val), "T") ||
!strcmp(Z_STRVAL_PP(val), "y") || !strcmp(Z_STRVAL_PP(val), "Y") ||
!strcmp(Z_STRVAL_PP(val), "true") || !strcmp(Z_STRVAL_PP(val), "True") ||
!strcmp(Z_STRVAL_PP(val), "yes") || !strcmp(Z_STRVAL_PP(val), "Yes") ||
!strcmp(Z_STRVAL_PP(val), "1")) {
ZVAL_STRING(new_val, "'t'", 1);
}
else if (!strcmp(Z_STRVAL_PP(val), "f") || !strcmp(Z_STRVAL_PP(val), "F") ||
!strcmp(Z_STRVAL_PP(val), "n") || !strcmp(Z_STRVAL_PP(val), "N") ||
!strcmp(Z_STRVAL_PP(val), "false") || !strcmp(Z_STRVAL_PP(val), "False") ||
!strcmp(Z_STRVAL_PP(val), "no") || !strcmp(Z_STRVAL_PP(val), "No") ||
!strcmp(Z_STRVAL_PP(val), "0")) {
ZVAL_STRING(new_val, "'f'", 1);
}
else {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected invalid value (%s) for PostgreSQL %s field (%s)", Z_STRVAL_PP(val), Z_STRVAL_PP(type), field);
err = 1;
}
}
break;
case IS_LONG:
case IS_BOOL:
if (Z_LVAL_PP(val)) {
ZVAL_STRING(new_val, "'t'", 1);
}
else {
ZVAL_STRING(new_val, "'f'", 1);
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects string, null, long or boolelan value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_OID:
case PG_INT2:
case PG_INT4:
case PG_INT8:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([+-]{0,1}[0-9]+)$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
}
}
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_long_ex(&new_val);
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for pgsql '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_NUMERIC:
case PG_MONEY:
case PG_FLOAT4:
case PG_FLOAT8:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([+-]{0,1}[0-9]+)|([+-]{0,1}[0-9]*[\\.][0-9]+)|([+-]{0,1}[0-9]+[\\.][0-9]*)$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
}
}
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_TEXT:
case PG_CHAR:
case PG_VARCHAR:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
if (opt & PGSQL_CONV_FORCE_NULL) {
ZVAL_STRING(new_val, "NULL", 1);
} else {
ZVAL_STRING(new_val, "''", 1);
}
}
else {
char *tmp;
Z_TYPE_P(new_val) = IS_STRING;
tmp = (char *)safe_emalloc(Z_STRLEN_PP(val), 2, 1);
Z_STRLEN_P(new_val) = (int)PQescapeStringConn(pg_link, tmp, Z_STRVAL_PP(val), Z_STRLEN_PP(val), NULL);
Z_STRVAL_P(new_val) = tmp;
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_UNIX_TIME:
case PG_UNIX_TIME_INTERVAL:
/* these are the actallay a integer */
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: Better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^[0-9]+$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
convert_to_long_ex(&new_val);
}
}
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_long_ex(&new_val);
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_CIDR:
case PG_INET:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: Better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{1,3}\\.){3}[0-9]{1,3}(/[0-9]{1,2}){0,1}$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_TIME_WITH_TIMEZONE:
case PG_TIMESTAMP:
case PG_TIMESTAMP_WITH_TIMEZONE:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1);
} else if (!strcasecmp(Z_STRVAL_PP(val), "now()")) {
ZVAL_STRINGL(new_val, "NOW()", sizeof("NOW()")-1, 1);
} else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,4}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
} else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_DATE:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_TIME:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_INTERVAL:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* From the Postgres docs:
interval values can be written with the following syntax:
[@] quantity unit [quantity unit...] [direction]
Where: quantity is a number (possibly signed); unit is second, minute, hour,
day, week, month, year, decade, century, millennium, or abbreviations or
plurals of these units [note not *all* abbreviations] ; direction can be
ago or empty. The at sign (@) is optional noise.
...
Quantities of days, hours, minutes, and seconds can be specified without explicit
unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10
sec'.
*/
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val),
"^(@?[ \\t]+)?("
/* Textual time units and their abbreviations: */
"(([-+]?[ \\t]+)?"
"[0-9]+(\\.[0-9]*)?[ \\t]*"
"(millenniums|millennia|millennium|mil|mils|"
"centuries|century|cent|c|"
"decades|decade|dec|decs|"
"years|year|y|"
"months|month|mon|"
"weeks|week|w|"
"days|day|d|"
"hours|hour|hr|hrs|h|"
"minutes|minute|mins|min|m|"
"seconds|second|secs|sec|s))+|"
/* Textual time units plus (dd)* hh[:mm[:ss]] */
"((([-+]?[ \\t]+)?"
"[0-9]+(\\.[0-9]*)?[ \\t]*"
"(millenniums|millennia|millennium|mil|mils|"
"centuries|century|cent|c|"
"decades|decade|dec|decs|"
"years|year|y|"
"months|month|mon|"
"weeks|week|w|"
"days|day|d))+"
"([-+]?[ \\t]+"
"([0-9]+[ \\t]+)+" /* dd */
"(([0-9]{1,2}:){0,2}[0-9]{0,2})" /* hh:[mm:[ss]] */
")?))"
"([ \\t]+ago)?$",
1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
#ifdef HAVE_PQESCAPE
case PG_BYTEA:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
unsigned char *tmp;
size_t to_len;
smart_str s = {0};
#ifdef HAVE_PQESCAPE_BYTEA_CONN
tmp = PQescapeByteaConn(pg_link, (unsigned char *)Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
#else
tmp = PQescapeBytea(Z_STRVAL_PP(val), (unsigned char *)Z_STRLEN_PP(val), &to_len);
#endif
Z_TYPE_P(new_val) = IS_STRING;
Z_STRLEN_P(new_val) = to_len-1; /* PQescapeBytea's to_len includes additional '\0' */
Z_STRVAL_P(new_val) = emalloc(to_len);
memcpy(Z_STRVAL_P(new_val), tmp, to_len);
PQfreemem(tmp);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
smart_str_appendl(&s, Z_STRVAL_P(new_val), Z_STRLEN_P(new_val));
smart_str_0(&s);
efree(Z_STRVAL_P(new_val));
Z_STRVAL_P(new_val) = s.c;
Z_STRLEN_P(new_val) = s.len;
}
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
#endif
case PG_MACADDR:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9a-f]{2,2}:){5,5}[0-9a-f]{2,2}$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
/* bit */
case PG_BIT:
case PG_VARBIT:
/* geometric */
case PG_LINE:
case PG_LSEG:
case PG_POINT:
case PG_BOX:
case PG_PATH:
case PG_POLYGON:
case PG_CIRCLE:
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "PostgreSQL '%s' type (%s) is not supported", Z_STRVAL_PP(type), field);
err = 1;
break;
case PG_UNKNOWN:
default:
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or system data type '%s' for '%s'", Z_STRVAL_PP(type), field);
err = 1;
break;
} /* switch */
if (err) {
zval_dtor(new_val);
FREE_ZVAL(new_val);
break; /* break out for() */
}
/* If field is NULL and HAS DEFAULT, should be skipped */
if (!skip_field) {
char *escaped;
size_t field_len = strlen(field);
if (_php_pgsql_detect_identifier_escape(field, field_len) == SUCCESS) {
add_assoc_zval(result, field, new_val);
} else {
escaped = PGSQLescapeIdentifier(pg_link, field, field_len);
add_assoc_zval(result, escaped, new_val);
PGSQLfree(escaped);
}
}
} /* for */
zval_dtor(meta);
FREE_ZVAL(meta);
if (err) {
/* shouldn't destroy & free zval here */
return FAILURE;
}
return SUCCESS;
}
| Bypass | 0 | PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC)
{
HashPosition pos;
char *field = NULL;
uint field_len = -1;
ulong num_idx = -1;
zval *meta, **def, **type, **not_null, **has_default, **is_enum, **val, *new_val;
int key_type, err = 0, skip_field;
php_pgsql_data_type data_type;
assert(pg_link != NULL);
assert(Z_TYPE_P(values) == IS_ARRAY);
assert(Z_TYPE_P(result) == IS_ARRAY);
assert(!(opt & ~PGSQL_CONV_OPTS));
if (!table_name) {
return FAILURE;
}
MAKE_STD_ZVAL(meta);
array_init(meta);
/* table_name is escaped by php_pgsql_meta_data */
if (php_pgsql_meta_data(pg_link, table_name, meta TSRMLS_CC) == FAILURE) {
zval_dtor(meta);
FREE_ZVAL(meta);
return FAILURE;
}
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos);
zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&val, &pos) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos)) {
skip_field = 0;
new_val = NULL;
if ((key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &field, &field_len, &num_idx, 0, &pos)) == HASH_KEY_NON_EXISTANT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to get array key type");
err = 1;
}
if (!err && key_type == HASH_KEY_IS_LONG) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Accepts only string key for values");
err = 1;
}
if (!err && key_type == HASH_KEY_NON_EXISTANT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Accepts only string key for values");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_P(meta), field, field_len, (void **)&def) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid field name (%s) in values", field);
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "type", sizeof("type"), (void **)&type) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'type'");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "not null", sizeof("not null"), (void **)¬_null) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'not null'");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "has default", sizeof("has default"), (void **)&has_default) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'has default'");
err = 1;
}
if (!err && zend_hash_find(Z_ARRVAL_PP(def), "is enum", sizeof("is enum"), (void **)&is_enum) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected broken meta data. Missing 'is enum'");
err = 1;
}
if (!err && (Z_TYPE_PP(val) == IS_ARRAY ||
Z_TYPE_PP(val) == IS_OBJECT ||
Z_TYPE_PP(val) == IS_CONSTANT_ARRAY)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects scalar values as field values");
err = 1;
}
if (err) {
break; /* break out for() */
}
ALLOC_INIT_ZVAL(new_val);
if (Z_BVAL_PP(is_enum)) {
/* enums need to be treated like strings */
data_type = PG_TEXT;
}
else {
data_type = php_pgsql_get_data_type(Z_STRVAL_PP(type), Z_STRLEN_PP(type));
}
switch(data_type)
{
case PG_BOOL:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
if (!strcmp(Z_STRVAL_PP(val), "t") || !strcmp(Z_STRVAL_PP(val), "T") ||
!strcmp(Z_STRVAL_PP(val), "y") || !strcmp(Z_STRVAL_PP(val), "Y") ||
!strcmp(Z_STRVAL_PP(val), "true") || !strcmp(Z_STRVAL_PP(val), "True") ||
!strcmp(Z_STRVAL_PP(val), "yes") || !strcmp(Z_STRVAL_PP(val), "Yes") ||
!strcmp(Z_STRVAL_PP(val), "1")) {
ZVAL_STRING(new_val, "'t'", 1);
}
else if (!strcmp(Z_STRVAL_PP(val), "f") || !strcmp(Z_STRVAL_PP(val), "F") ||
!strcmp(Z_STRVAL_PP(val), "n") || !strcmp(Z_STRVAL_PP(val), "N") ||
!strcmp(Z_STRVAL_PP(val), "false") || !strcmp(Z_STRVAL_PP(val), "False") ||
!strcmp(Z_STRVAL_PP(val), "no") || !strcmp(Z_STRVAL_PP(val), "No") ||
!strcmp(Z_STRVAL_PP(val), "0")) {
ZVAL_STRING(new_val, "'f'", 1);
}
else {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Detected invalid value (%s) for PostgreSQL %s field (%s)", Z_STRVAL_PP(val), Z_STRVAL_PP(type), field);
err = 1;
}
}
break;
case IS_LONG:
case IS_BOOL:
if (Z_LVAL_PP(val)) {
ZVAL_STRING(new_val, "'t'", 1);
}
else {
ZVAL_STRING(new_val, "'f'", 1);
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects string, null, long or boolelan value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_OID:
case PG_INT2:
case PG_INT4:
case PG_INT8:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([+-]{0,1}[0-9]+)$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
}
}
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_long_ex(&new_val);
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for pgsql '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_NUMERIC:
case PG_MONEY:
case PG_FLOAT4:
case PG_FLOAT8:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([+-]{0,1}[0-9]+)|([+-]{0,1}[0-9]*[\\.][0-9]+)|([+-]{0,1}[0-9]+[\\.][0-9]*)$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
}
}
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_TEXT:
case PG_CHAR:
case PG_VARCHAR:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
if (opt & PGSQL_CONV_FORCE_NULL) {
ZVAL_STRING(new_val, "NULL", 1);
} else {
ZVAL_STRING(new_val, "''", 1);
}
}
else {
char *tmp;
Z_TYPE_P(new_val) = IS_STRING;
tmp = (char *)safe_emalloc(Z_STRLEN_PP(val), 2, 1);
Z_STRLEN_P(new_val) = (int)PQescapeStringConn(pg_link, tmp, Z_STRVAL_PP(val), Z_STRLEN_PP(val), NULL);
Z_STRVAL_P(new_val) = tmp;
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_UNIX_TIME:
case PG_UNIX_TIME_INTERVAL:
/* these are the actallay a integer */
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: Better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^[0-9]+$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
convert_to_long_ex(&new_val);
}
}
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_long_ex(&new_val);
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_CIDR:
case PG_INET:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: Better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{1,3}\\.){3}[0-9]{1,3}(/[0-9]{1,2}){0,1}$", 0 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_TIME_WITH_TIMEZONE:
case PG_TIMESTAMP:
case PG_TIMESTAMP_WITH_TIMEZONE:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1);
} else if (!strcasecmp(Z_STRVAL_PP(val), "now()")) {
ZVAL_STRINGL(new_val, "NOW()", sizeof("NOW()")-1, 1);
} else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,4}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
} else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_DATE:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_TIME:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* FIXME: better regex must be used */
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
case PG_INTERVAL:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
/* From the Postgres docs:
interval values can be written with the following syntax:
[@] quantity unit [quantity unit...] [direction]
Where: quantity is a number (possibly signed); unit is second, minute, hour,
day, week, month, year, decade, century, millennium, or abbreviations or
plurals of these units [note not *all* abbreviations] ; direction can be
ago or empty. The at sign (@) is optional noise.
...
Quantities of days, hours, minutes, and seconds can be specified without explicit
unit markings. For example, '1 12:59:10' is read the same as '1 day 12 hours 59 min 10
sec'.
*/
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val),
"^(@?[ \\t]+)?("
/* Textual time units and their abbreviations: */
"(([-+]?[ \\t]+)?"
"[0-9]+(\\.[0-9]*)?[ \\t]*"
"(millenniums|millennia|millennium|mil|mils|"
"centuries|century|cent|c|"
"decades|decade|dec|decs|"
"years|year|y|"
"months|month|mon|"
"weeks|week|w|"
"days|day|d|"
"hours|hour|hr|hrs|h|"
"minutes|minute|mins|min|m|"
"seconds|second|secs|sec|s))+|"
/* Textual time units plus (dd)* hh[:mm[:ss]] */
"((([-+]?[ \\t]+)?"
"[0-9]+(\\.[0-9]*)?[ \\t]*"
"(millenniums|millennia|millennium|mil|mils|"
"centuries|century|cent|c|"
"decades|decade|dec|decs|"
"years|year|y|"
"months|month|mon|"
"weeks|week|w|"
"days|day|d))+"
"([-+]?[ \\t]+"
"([0-9]+[ \\t]+)+" /* dd */
"(([0-9]{1,2}:){0,2}[0-9]{0,2})" /* hh:[mm:[ss]] */
")?))"
"([ \\t]+ago)?$",
1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
#ifdef HAVE_PQESCAPE
case PG_BYTEA:
switch (Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
unsigned char *tmp;
size_t to_len;
smart_str s = {0};
#ifdef HAVE_PQESCAPE_BYTEA_CONN
tmp = PQescapeByteaConn(pg_link, (unsigned char *)Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
#else
tmp = PQescapeBytea(Z_STRVAL_PP(val), (unsigned char *)Z_STRLEN_PP(val), &to_len);
#endif
Z_TYPE_P(new_val) = IS_STRING;
Z_STRLEN_P(new_val) = to_len-1; /* PQescapeBytea's to_len includes additional '\0' */
Z_STRVAL_P(new_val) = emalloc(to_len);
memcpy(Z_STRVAL_P(new_val), tmp, to_len);
PQfreemem(tmp);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
smart_str_appendl(&s, Z_STRVAL_P(new_val), Z_STRLEN_P(new_val));
smart_str_0(&s);
efree(Z_STRVAL_P(new_val));
Z_STRVAL_P(new_val) = s.c;
Z_STRLEN_P(new_val) = s.len;
}
break;
case IS_LONG:
ZVAL_LONG(new_val, Z_LVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_DOUBLE:
ZVAL_DOUBLE(new_val, Z_DVAL_PP(val));
convert_to_string_ex(&new_val);
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL, string, long or double value for PostgreSQL '%s' (%s)", Z_STRVAL_PP(type), field);
}
break;
#endif
case PG_MACADDR:
switch(Z_TYPE_PP(val)) {
case IS_STRING:
if (Z_STRLEN_PP(val) == 0) {
ZVAL_STRING(new_val, "NULL", 1);
}
else {
if (php_pgsql_convert_match(Z_STRVAL_PP(val), Z_STRLEN_PP(val), "^([0-9a-f]{2,2}:){5,5}[0-9a-f]{2,2}$", 1 TSRMLS_CC) == FAILURE) {
err = 1;
}
else {
ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1);
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
}
}
break;
case IS_NULL:
ZVAL_STRING(new_val, "NULL", 1);
break;
default:
err = 1;
}
PGSQL_CONV_CHECK_IGNORE();
if (err) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Expects NULL or string for PostgreSQL %s field (%s)", Z_STRVAL_PP(type), field);
}
break;
/* bit */
case PG_BIT:
case PG_VARBIT:
/* geometric */
case PG_LINE:
case PG_LSEG:
case PG_POINT:
case PG_BOX:
case PG_PATH:
case PG_POLYGON:
case PG_CIRCLE:
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "PostgreSQL '%s' type (%s) is not supported", Z_STRVAL_PP(type), field);
err = 1;
break;
case PG_UNKNOWN:
default:
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or system data type '%s' for '%s'", Z_STRVAL_PP(type), field);
err = 1;
break;
} /* switch */
if (err) {
zval_dtor(new_val);
FREE_ZVAL(new_val);
break; /* break out for() */
}
/* If field is NULL and HAS DEFAULT, should be skipped */
if (!skip_field) {
char *escaped;
size_t field_len = strlen(field);
if (_php_pgsql_detect_identifier_escape(field, field_len) == SUCCESS) {
add_assoc_zval(result, field, new_val);
} else {
escaped = PGSQLescapeIdentifier(pg_link, field, field_len);
add_assoc_zval(result, escaped, new_val);
PGSQLfree(escaped);
}
}
} /* for */
zval_dtor(meta);
FREE_ZVAL(meta);
if (err) {
/* shouldn't destroy & free zval here */
return FAILURE;
}
return SUCCESS;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,227 | static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , int icase TSRMLS_DC)
{
regex_t re;
regmatch_t *subs;
int regopt = REG_EXTENDED;
int regerr, ret = SUCCESS;
int i;
/* Check invalid chars for POSIX regex */
for (i = 0; i < str_len; i++) {
if (str[i] == '\n' ||
str[i] == '\r' ||
str[i] == '\0' ) {
return FAILURE;
}
}
if (icase) {
regopt |= REG_ICASE;
}
regerr = regcomp(&re, regex, regopt);
if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex");
regfree(&re);
return FAILURE;
}
subs = (regmatch_t *)ecalloc(sizeof(regmatch_t), re.re_nsub+1);
regerr = regexec(&re, str, re.re_nsub+1, subs, 0);
if (regerr == REG_NOMATCH) {
#ifdef PHP_DEBUG
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex);
#endif
ret = FAILURE;
}
else if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot exec regex");
ret = FAILURE;
}
regfree(&re);
efree(subs);
return ret;
}
| Bypass | 0 | static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , int icase TSRMLS_DC)
{
regex_t re;
regmatch_t *subs;
int regopt = REG_EXTENDED;
int regerr, ret = SUCCESS;
int i;
/* Check invalid chars for POSIX regex */
for (i = 0; i < str_len; i++) {
if (str[i] == '\n' ||
str[i] == '\r' ||
str[i] == '\0' ) {
return FAILURE;
}
}
if (icase) {
regopt |= REG_ICASE;
}
regerr = regcomp(&re, regex, regopt);
if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot compile regex");
regfree(&re);
return FAILURE;
}
subs = (regmatch_t *)ecalloc(sizeof(regmatch_t), re.re_nsub+1);
regerr = regexec(&re, str, re.re_nsub+1, subs, 0);
if (regerr == REG_NOMATCH) {
#ifdef PHP_DEBUG
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "'%s' does not match with '%s'", str, regex);
#endif
ret = FAILURE;
}
else if (regerr) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot exec regex");
ret = FAILURE;
}
regfree(&re);
efree(subs);
return ret;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,228 | PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array, ulong opt, char **sql TSRMLS_DC)
{
zval *ids_converted = NULL;
smart_str querystr = {0};
int ret = FAILURE;
assert(pg_link != NULL);
assert(table != NULL);
assert(Z_TYPE_P(ids_array) == IS_ARRAY);
assert(!(opt & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_EXEC|PGSQL_DML_STRING)));
if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
return FAILURE;
}
if (!(opt & PGSQL_DML_NO_CONV)) {
MAKE_STD_ZVAL(ids_converted);
array_init(ids_converted);
if (php_pgsql_convert(pg_link, table, ids_array, ids_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
ids_array = ids_converted;
}
smart_str_appends(&querystr, "DELETE FROM ");
build_tablename(&querystr, pg_link, table);
smart_str_appends(&querystr, " WHERE ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
smart_str_0(&querystr);
if ((opt & PGSQL_DML_EXEC) && do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) {
ret = SUCCESS;
} else if (opt & PGSQL_DML_STRING) {
ret = SUCCESS;
}
cleanup:
if (!(opt & PGSQL_DML_NO_CONV)) {
zval_dtor(ids_converted);
FREE_ZVAL(ids_converted);
}
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) {
*sql = querystr.c;
}
else {
smart_str_free(&querystr);
}
return ret;
}
| Bypass | 0 | PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids_array, ulong opt, char **sql TSRMLS_DC)
{
zval *ids_converted = NULL;
smart_str querystr = {0};
int ret = FAILURE;
assert(pg_link != NULL);
assert(table != NULL);
assert(Z_TYPE_P(ids_array) == IS_ARRAY);
assert(!(opt & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_EXEC|PGSQL_DML_STRING)));
if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
return FAILURE;
}
if (!(opt & PGSQL_DML_NO_CONV)) {
MAKE_STD_ZVAL(ids_converted);
array_init(ids_converted);
if (php_pgsql_convert(pg_link, table, ids_array, ids_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
ids_array = ids_converted;
}
smart_str_appends(&querystr, "DELETE FROM ");
build_tablename(&querystr, pg_link, table);
smart_str_appends(&querystr, " WHERE ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
smart_str_0(&querystr);
if ((opt & PGSQL_DML_EXEC) && do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) {
ret = SUCCESS;
} else if (opt & PGSQL_DML_STRING) {
ret = SUCCESS;
}
cleanup:
if (!(opt & PGSQL_DML_NO_CONV)) {
zval_dtor(ids_converted);
FREE_ZVAL(ids_converted);
}
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) {
*sql = querystr.c;
}
else {
smart_str_free(&querystr);
}
return ret;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,229 | static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *pgsql_link;
int id = -1;
PGconn *pgsql;
PGresult *pgsql_result;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r",
&pgsql_link) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (PQ_SETNONBLOCKING(pgsql, 1)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
switch(entry_type) {
case PHP_PG_ASYNC_IS_BUSY:
PQconsumeInput(pgsql);
Z_LVAL_P(return_value) = PQisBusy(pgsql);
Z_TYPE_P(return_value) = IS_LONG;
break;
case PHP_PG_ASYNC_REQUEST_CANCEL:
Z_LVAL_P(return_value) = PQrequestCancel(pgsql);
Z_TYPE_P(return_value) = IS_LONG;
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
break;
default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "PostgreSQL module error, please report this error");
break;
}
if (PQ_SETNONBLOCKING(pgsql, 0)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
}
convert_to_boolean_ex(&return_value);
}
| Bypass | 0 | static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *pgsql_link;
int id = -1;
PGconn *pgsql;
PGresult *pgsql_result;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r",
&pgsql_link) == FAILURE) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
if (PQ_SETNONBLOCKING(pgsql, 1)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
switch(entry_type) {
case PHP_PG_ASYNC_IS_BUSY:
PQconsumeInput(pgsql);
Z_LVAL_P(return_value) = PQisBusy(pgsql);
Z_TYPE_P(return_value) = IS_LONG;
break;
case PHP_PG_ASYNC_REQUEST_CANCEL:
Z_LVAL_P(return_value) = PQrequestCancel(pgsql);
Z_TYPE_P(return_value) = IS_LONG;
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
}
break;
default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "PostgreSQL module error, please report this error");
break;
}
if (PQ_SETNONBLOCKING(pgsql, 0)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
}
convert_to_boolean_ex(&return_value);
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,230 | static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, int into_object)
{
zval *result, *zrow = NULL;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
int i, num_fields, pgsql_row, use_row;
long row = -1;
char *field_name;
zval *ctor_params = NULL;
zend_class_entry *ce = NULL;
if (into_object) {
char *class_name = NULL;
int class_name_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z!sz", &result, &zrow, &class_name, &class_name_len, &ctor_params) == FAILURE) {
return;
}
if (!class_name) {
ce = zend_standard_class_def;
} else {
ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
if (!ce) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
return;
}
result_type = PGSQL_ASSOC;
} else {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z!l", &result, &zrow, &result_type) == FAILURE) {
return;
}
}
if (zrow == NULL) {
row = -1;
} else {
convert_to_long(zrow);
row = Z_LVAL_P(zrow);
if (row < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The row parameter must be greater or equal to zero");
RETURN_FALSE;
}
}
use_row = ZEND_NUM_ARGS() > 1 && row != -1;
if (!(result_type & PGSQL_BOTH)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid result type");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
pgsql_result = pg_result->result;
if (use_row) {
pgsql_row = row;
pg_result->row = pgsql_row;
if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to jump to row %ld on PostgreSQL result index %ld",
row, Z_LVAL_P(result));
RETURN_FALSE;
}
} else {
/* If 2nd param is NULL, use internal row counter to access next row */
pgsql_row = pg_result->row;
if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) {
RETURN_FALSE;
}
pg_result->row++;
}
array_init(return_value);
for (i = 0, num_fields = PQnfields(pgsql_result); i < num_fields; i++) {
if (PQgetisnull(pgsql_result, pgsql_row, i)) {
if (result_type & PGSQL_NUM) {
add_index_null(return_value, i);
}
if (result_type & PGSQL_ASSOC) {
field_name = PQfname(pgsql_result, i);
add_assoc_null(return_value, field_name);
}
} else {
char *element = PQgetvalue(pgsql_result, pgsql_row, i);
if (element) {
char *data;
int data_len;
int should_copy=0;
const uint element_len = strlen(element);
data = safe_estrndup(element, element_len);
data_len = element_len;
if (result_type & PGSQL_NUM) {
add_index_stringl(return_value, i, data, data_len, should_copy);
should_copy=1;
}
if (result_type & PGSQL_ASSOC) {
field_name = PQfname(pgsql_result, i);
add_assoc_stringl(return_value, field_name, data, data_len, should_copy);
}
}
}
}
if (into_object) {
zval dataset = *return_value;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
zval *retval_ptr;
object_and_properties_init(return_value, ce, NULL);
zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
if (ce->constructor) {
fci.size = sizeof(fci);
fci.function_table = &ce->function_table;
fci.function_name = NULL;
fci.symbol_table = NULL;
fci.object_ptr = return_value;
fci.retval_ptr_ptr = &retval_ptr;
if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
HashTable *ht = Z_ARRVAL_P(ctor_params);
Bucket *p;
fci.param_count = 0;
fci.params = safe_emalloc(sizeof(zval***), ht->nNumOfElements, 0);
p = ht->pListHead;
while (p != NULL) {
fci.params[fci.param_count++] = (zval**)p->pData;
p = p->pListNext;
}
} else {
/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that's not an array could be
* by mistake and the other way round is possible, too. The
* single value is an array. Also we'd have to make that one
* argument passed by reference.
*/
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
return;
}
} else {
fci.param_count = 0;
fci.params = NULL;
}
fci.no_separation = 1;
fcc.initialized = 1;
fcc.function_handler = ce->constructor;
fcc.calling_scope = EG(scope);
fcc.called_scope = Z_OBJCE_P(return_value);
fcc.object_ptr = return_value;
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name);
} else {
if (retval_ptr) {
zval_ptr_dtor(&retval_ptr);
}
}
if (fci.params) {
efree(fci.params);
}
} else if (ctor_params) {
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
}
}
}
| Bypass | 0 | static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, int into_object)
{
zval *result, *zrow = NULL;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
int i, num_fields, pgsql_row, use_row;
long row = -1;
char *field_name;
zval *ctor_params = NULL;
zend_class_entry *ce = NULL;
if (into_object) {
char *class_name = NULL;
int class_name_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z!sz", &result, &zrow, &class_name, &class_name_len, &ctor_params) == FAILURE) {
return;
}
if (!class_name) {
ce = zend_standard_class_def;
} else {
ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
if (!ce) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
return;
}
result_type = PGSQL_ASSOC;
} else {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z!l", &result, &zrow, &result_type) == FAILURE) {
return;
}
}
if (zrow == NULL) {
row = -1;
} else {
convert_to_long(zrow);
row = Z_LVAL_P(zrow);
if (row < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The row parameter must be greater or equal to zero");
RETURN_FALSE;
}
}
use_row = ZEND_NUM_ARGS() > 1 && row != -1;
if (!(result_type & PGSQL_BOTH)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid result type");
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
pgsql_result = pg_result->result;
if (use_row) {
pgsql_row = row;
pg_result->row = pgsql_row;
if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to jump to row %ld on PostgreSQL result index %ld",
row, Z_LVAL_P(result));
RETURN_FALSE;
}
} else {
/* If 2nd param is NULL, use internal row counter to access next row */
pgsql_row = pg_result->row;
if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) {
RETURN_FALSE;
}
pg_result->row++;
}
array_init(return_value);
for (i = 0, num_fields = PQnfields(pgsql_result); i < num_fields; i++) {
if (PQgetisnull(pgsql_result, pgsql_row, i)) {
if (result_type & PGSQL_NUM) {
add_index_null(return_value, i);
}
if (result_type & PGSQL_ASSOC) {
field_name = PQfname(pgsql_result, i);
add_assoc_null(return_value, field_name);
}
} else {
char *element = PQgetvalue(pgsql_result, pgsql_row, i);
if (element) {
char *data;
int data_len;
int should_copy=0;
const uint element_len = strlen(element);
data = safe_estrndup(element, element_len);
data_len = element_len;
if (result_type & PGSQL_NUM) {
add_index_stringl(return_value, i, data, data_len, should_copy);
should_copy=1;
}
if (result_type & PGSQL_ASSOC) {
field_name = PQfname(pgsql_result, i);
add_assoc_stringl(return_value, field_name, data, data_len, should_copy);
}
}
}
}
if (into_object) {
zval dataset = *return_value;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
zval *retval_ptr;
object_and_properties_init(return_value, ce, NULL);
zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
if (ce->constructor) {
fci.size = sizeof(fci);
fci.function_table = &ce->function_table;
fci.function_name = NULL;
fci.symbol_table = NULL;
fci.object_ptr = return_value;
fci.retval_ptr_ptr = &retval_ptr;
if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
HashTable *ht = Z_ARRVAL_P(ctor_params);
Bucket *p;
fci.param_count = 0;
fci.params = safe_emalloc(sizeof(zval***), ht->nNumOfElements, 0);
p = ht->pListHead;
while (p != NULL) {
fci.params[fci.param_count++] = (zval**)p->pData;
p = p->pListNext;
}
} else {
/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that's not an array could be
* by mistake and the other way round is possible, too. The
* single value is an array. Also we'd have to make that one
* argument passed by reference.
*/
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
return;
}
} else {
fci.param_count = 0;
fci.params = NULL;
}
fci.no_separation = 1;
fcc.initialized = 1;
fcc.function_handler = ce->constructor;
fcc.calling_scope = EG(scope);
fcc.called_scope = Z_OBJCE_P(return_value);
fcc.object_ptr = return_value;
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name);
} else {
if (retval_ptr) {
zval_ptr_dtor(&retval_ptr);
}
}
if (fci.params) {
efree(fci.params);
}
} else if (ctor_params) {
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
}
}
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,231 | static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC)
{
PGresult *res;
int leftover = 0;
if (PQ_SETNONBLOCKING(pgsql, 1)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE,"Cannot set connection to nonblocking mode");
return -1;
}
while ((res = PQgetResult(pgsql))) {
PQclear(res);
leftover++;
}
PQ_SETNONBLOCKING(pgsql, 0);
return leftover;
}
| Bypass | 0 | static int php_pgsql_flush_query(PGconn *pgsql TSRMLS_DC)
{
PGresult *res;
int leftover = 0;
if (PQ_SETNONBLOCKING(pgsql, 1)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE,"Cannot set connection to nonblocking mode");
return -1;
}
while ((res = PQgetResult(pgsql))) {
PQclear(res);
leftover++;
}
PQ_SETNONBLOCKING(pgsql, 0);
return leftover;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,232 | static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *result;
long field;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
Oid oid;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result, &field) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
pgsql_result = pg_result->result;
if (field < 0 || field >= PQnfields(pgsql_result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset specified");
RETURN_FALSE;
}
switch (entry_type) {
case PHP_PG_FIELD_NAME:
Z_STRVAL_P(return_value) = PQfname(pgsql_result, field);
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_STRVAL_P(return_value) = estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value));
Z_TYPE_P(return_value) = IS_STRING;
break;
case PHP_PG_FIELD_SIZE:
Z_LVAL_P(return_value) = PQfsize(pgsql_result, field);
Z_TYPE_P(return_value) = IS_LONG;
break;
case PHP_PG_FIELD_TYPE:
Z_STRVAL_P(return_value) = get_field_name(pg_result->conn, PQftype(pgsql_result, field), &EG(regular_list) TSRMLS_CC);
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_TYPE_P(return_value) = IS_STRING;
break;
case PHP_PG_FIELD_TYPE_OID:
oid = PQftype(pgsql_result, field);
#if UINT_MAX > LONG_MAX
if (oid > LONG_MAX) {
smart_str s = {0};
smart_str_append_unsigned(&s, oid);
smart_str_0(&s);
Z_STRVAL_P(return_value) = s.c;
Z_STRLEN_P(return_value) = s.len;
Z_TYPE_P(return_value) = IS_STRING;
} else
#endif
{
Z_LVAL_P(return_value) = (long)oid;
Z_TYPE_P(return_value) = IS_LONG;
}
break;
default:
RETURN_FALSE;
}
}
| Bypass | 0 | static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *result;
long field;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
Oid oid;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result, &field) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
pgsql_result = pg_result->result;
if (field < 0 || field >= PQnfields(pgsql_result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset specified");
RETURN_FALSE;
}
switch (entry_type) {
case PHP_PG_FIELD_NAME:
Z_STRVAL_P(return_value) = PQfname(pgsql_result, field);
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_STRVAL_P(return_value) = estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value));
Z_TYPE_P(return_value) = IS_STRING;
break;
case PHP_PG_FIELD_SIZE:
Z_LVAL_P(return_value) = PQfsize(pgsql_result, field);
Z_TYPE_P(return_value) = IS_LONG;
break;
case PHP_PG_FIELD_TYPE:
Z_STRVAL_P(return_value) = get_field_name(pg_result->conn, PQftype(pgsql_result, field), &EG(regular_list) TSRMLS_CC);
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_TYPE_P(return_value) = IS_STRING;
break;
case PHP_PG_FIELD_TYPE_OID:
oid = PQftype(pgsql_result, field);
#if UINT_MAX > LONG_MAX
if (oid > LONG_MAX) {
smart_str s = {0};
smart_str_append_unsigned(&s, oid);
smart_str_0(&s);
Z_STRVAL_P(return_value) = s.c;
Z_STRLEN_P(return_value) = s.len;
Z_TYPE_P(return_value) = IS_STRING;
} else
#endif
{
Z_LVAL_P(return_value) = (long)oid;
Z_TYPE_P(return_value) = IS_LONG;
}
break;
default:
RETURN_FALSE;
}
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,233 | static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *pgsql_link = NULL;
int id = -1, argc = ZEND_NUM_ARGS();
PGconn *pgsql;
char *msgbuf;
if (zend_parse_parameters(argc TSRMLS_CC, "|r", &pgsql_link) == FAILURE) {
return;
}
if (argc == 0) {
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
}
if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
switch(entry_type) {
case PHP_PG_DBNAME:
Z_STRVAL_P(return_value) = PQdb(pgsql);
break;
case PHP_PG_ERROR_MESSAGE:
RETURN_STRING(PQErrorMessageTrim(pgsql, &msgbuf), 0);
return;
case PHP_PG_OPTIONS:
Z_STRVAL_P(return_value) = PQoptions(pgsql);
break;
case PHP_PG_PORT:
Z_STRVAL_P(return_value) = PQport(pgsql);
break;
case PHP_PG_TTY:
Z_STRVAL_P(return_value) = PQtty(pgsql);
break;
case PHP_PG_HOST:
Z_STRVAL_P(return_value) = PQhost(pgsql);
break;
case PHP_PG_VERSION:
array_init(return_value);
add_assoc_string(return_value, "client", PG_VERSION, 1);
#if HAVE_PQPROTOCOLVERSION
add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql));
#if HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3) {
add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version"), 1);
}
#endif
#endif
return;
default:
RETURN_FALSE;
}
if (Z_STRVAL_P(return_value)) {
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_STRVAL_P(return_value) = (char *) estrdup(Z_STRVAL_P(return_value));
} else {
Z_STRLEN_P(return_value) = 0;
Z_STRVAL_P(return_value) = (char *) estrdup("");
}
Z_TYPE_P(return_value) = IS_STRING;
}
| Bypass | 0 | static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *pgsql_link = NULL;
int id = -1, argc = ZEND_NUM_ARGS();
PGconn *pgsql;
char *msgbuf;
if (zend_parse_parameters(argc TSRMLS_CC, "|r", &pgsql_link) == FAILURE) {
return;
}
if (argc == 0) {
id = PGG(default_link);
CHECK_DEFAULT_LINK(id);
}
if (pgsql_link == NULL && id == -1) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
switch(entry_type) {
case PHP_PG_DBNAME:
Z_STRVAL_P(return_value) = PQdb(pgsql);
break;
case PHP_PG_ERROR_MESSAGE:
RETURN_STRING(PQErrorMessageTrim(pgsql, &msgbuf), 0);
return;
case PHP_PG_OPTIONS:
Z_STRVAL_P(return_value) = PQoptions(pgsql);
break;
case PHP_PG_PORT:
Z_STRVAL_P(return_value) = PQport(pgsql);
break;
case PHP_PG_TTY:
Z_STRVAL_P(return_value) = PQtty(pgsql);
break;
case PHP_PG_HOST:
Z_STRVAL_P(return_value) = PQhost(pgsql);
break;
case PHP_PG_VERSION:
array_init(return_value);
add_assoc_string(return_value, "client", PG_VERSION, 1);
#if HAVE_PQPROTOCOLVERSION
add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql));
#if HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3) {
add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version"), 1);
}
#endif
#endif
return;
default:
RETURN_FALSE;
}
if (Z_STRVAL_P(return_value)) {
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_STRVAL_P(return_value) = (char *) estrdup(Z_STRVAL_P(return_value));
} else {
Z_STRLEN_P(return_value) = 0;
Z_STRVAL_P(return_value) = (char *) estrdup("");
}
Z_TYPE_P(return_value) = IS_STRING;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,234 | static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *result;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
pgsql_result = pg_result->result;
switch (entry_type) {
case PHP_PG_NUM_ROWS:
Z_LVAL_P(return_value) = PQntuples(pgsql_result);
break;
case PHP_PG_NUM_FIELDS:
Z_LVAL_P(return_value) = PQnfields(pgsql_result);
break;
case PHP_PG_CMD_TUPLES:
#if HAVE_PQCMDTUPLES
Z_LVAL_P(return_value) = atoi(PQcmdTuples(pgsql_result));
#else
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported under this build");
Z_LVAL_P(return_value) = 0;
#endif
break;
default:
RETURN_FALSE;
}
Z_TYPE_P(return_value) = IS_LONG;
}
| Bypass | 0 | static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
zval *result;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
pgsql_result = pg_result->result;
switch (entry_type) {
case PHP_PG_NUM_ROWS:
Z_LVAL_P(return_value) = PQntuples(pgsql_result);
break;
case PHP_PG_NUM_FIELDS:
Z_LVAL_P(return_value) = PQnfields(pgsql_result);
break;
case PHP_PG_CMD_TUPLES:
#if HAVE_PQCMDTUPLES
Z_LVAL_P(return_value) = atoi(PQcmdTuples(pgsql_result));
#else
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported under this build");
Z_LVAL_P(return_value) = 0;
#endif
break;
default:
RETURN_FALSE;
}
Z_TYPE_P(return_value) = IS_LONG;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,235 | PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC)
{
PGresult *pg_result;
char *src, *tmp_name, *tmp_name2 = NULL;
char *escaped;
smart_str querystr = {0};
size_t new_len;
int i, num_rows;
zval *elem;
if (!*table_name) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified");
return FAILURE;
}
src = estrdup(table_name);
tmp_name = php_strtok_r(src, ".", &tmp_name2);
if (!tmp_name2 || !*tmp_name2) {
/* Default schema */
tmp_name2 = tmp_name;
tmp_name = "public";
}
smart_str_appends(&querystr,
"SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotnull, a.atthasdef, a.attndims, t.typtype = 'e' "
"FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n "
"WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;");
smart_str_0(&querystr);
efree(src);
pg_result = PQexec(pg_link, querystr.c);
if (PQresultStatus(pg_result) != PGRES_TUPLES_OK || (num_rows = PQntuples(pg_result)) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Table '%s' doesn't exists", table_name);
smart_str_free(&querystr);
PQclear(pg_result);
return FAILURE;
}
smart_str_free(&querystr);
for (i = 0; i < num_rows; i++) {
char *name;
MAKE_STD_ZVAL(elem);
array_init(elem);
add_assoc_long(elem, "num", atoi(PQgetvalue(pg_result,i,1)));
add_assoc_string(elem, "type", PQgetvalue(pg_result,i,2), 1);
add_assoc_long(elem, "len", atoi(PQgetvalue(pg_result,i,3)));
if (!strcmp(PQgetvalue(pg_result,i,4), "t")) {
add_assoc_bool(elem, "not null", 1);
}
else {
add_assoc_bool(elem, "not null", 0);
}
if (!strcmp(PQgetvalue(pg_result,i,5), "t")) {
add_assoc_bool(elem, "has default", 1);
}
else {
add_assoc_bool(elem, "has default", 0);
}
add_assoc_long(elem, "array dims", atoi(PQgetvalue(pg_result,i,6)));
if (!strcmp(PQgetvalue(pg_result,i,7), "t")) {
add_assoc_bool(elem, "is enum", 1);
}
else {
add_assoc_bool(elem, "is enum", 0);
}
name = PQgetvalue(pg_result,i,0);
add_assoc_zval(meta, name, elem);
}
PQclear(pg_result);
return SUCCESS;
}
| Bypass | 0 | PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC)
{
PGresult *pg_result;
char *src, *tmp_name, *tmp_name2 = NULL;
char *escaped;
smart_str querystr = {0};
size_t new_len;
int i, num_rows;
zval *elem;
if (!*table_name) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified");
return FAILURE;
}
src = estrdup(table_name);
tmp_name = php_strtok_r(src, ".", &tmp_name2);
if (!tmp_name2 || !*tmp_name2) {
/* Default schema */
tmp_name2 = tmp_name;
tmp_name = "public";
}
smart_str_appends(&querystr,
"SELECT a.attname, a.attnum, t.typname, a.attlen, a.attnotnull, a.atthasdef, a.attndims, t.typtype = 'e' "
"FROM pg_class as c, pg_attribute a, pg_type t, pg_namespace n "
"WHERE a.attnum > 0 AND a.attrelid = c.oid AND c.relname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name2), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name2, strlen(tmp_name2), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '");
escaped = (char *)safe_emalloc(strlen(tmp_name), 2, 1);
new_len = PQescapeStringConn(pg_link, escaped, tmp_name, strlen(tmp_name), NULL);
if (new_len) {
smart_str_appendl(&querystr, escaped, new_len);
}
efree(escaped);
smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;");
smart_str_0(&querystr);
efree(src);
pg_result = PQexec(pg_link, querystr.c);
if (PQresultStatus(pg_result) != PGRES_TUPLES_OK || (num_rows = PQntuples(pg_result)) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Table '%s' doesn't exists", table_name);
smart_str_free(&querystr);
PQclear(pg_result);
return FAILURE;
}
smart_str_free(&querystr);
for (i = 0; i < num_rows; i++) {
char *name;
MAKE_STD_ZVAL(elem);
array_init(elem);
add_assoc_long(elem, "num", atoi(PQgetvalue(pg_result,i,1)));
add_assoc_string(elem, "type", PQgetvalue(pg_result,i,2), 1);
add_assoc_long(elem, "len", atoi(PQgetvalue(pg_result,i,3)));
if (!strcmp(PQgetvalue(pg_result,i,4), "t")) {
add_assoc_bool(elem, "not null", 1);
}
else {
add_assoc_bool(elem, "not null", 0);
}
if (!strcmp(PQgetvalue(pg_result,i,5), "t")) {
add_assoc_bool(elem, "has default", 1);
}
else {
add_assoc_bool(elem, "has default", 0);
}
add_assoc_long(elem, "array dims", atoi(PQgetvalue(pg_result,i,6)));
if (!strcmp(PQgetvalue(pg_result,i,7), "t")) {
add_assoc_bool(elem, "is enum", 1);
}
else {
add_assoc_bool(elem, "is enum", 0);
}
name = PQgetvalue(pg_result,i,0);
add_assoc_zval(meta, name, elem);
}
PQclear(pg_result);
return SUCCESS;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,236 | PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC)
{
zval *row;
char *field_name;
size_t num_fields;
int pg_numrows, pg_row;
uint i;
assert(Z_TYPE_P(ret_array) == IS_ARRAY);
if ((pg_numrows = PQntuples(pg_result)) <= 0) {
return FAILURE;
}
for (pg_row = 0; pg_row < pg_numrows; pg_row++) {
MAKE_STD_ZVAL(row);
array_init(row);
add_index_zval(ret_array, pg_row, row);
for (i = 0, num_fields = PQnfields(pg_result); i < num_fields; i++) {
if (PQgetisnull(pg_result, pg_row, i)) {
field_name = PQfname(pg_result, i);
add_assoc_null(row, field_name);
} else {
char *element = PQgetvalue(pg_result, pg_row, i);
if (element) {
char *data;
size_t data_len;
const size_t element_len = strlen(element);
data = safe_estrndup(element, element_len);
data_len = element_len;
field_name = PQfname(pg_result, i);
add_assoc_stringl(row, field_name, data, data_len, 0);
}
}
}
}
return SUCCESS;
}
| Bypass | 0 | PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC)
{
zval *row;
char *field_name;
size_t num_fields;
int pg_numrows, pg_row;
uint i;
assert(Z_TYPE_P(ret_array) == IS_ARRAY);
if ((pg_numrows = PQntuples(pg_result)) <= 0) {
return FAILURE;
}
for (pg_row = 0; pg_row < pg_numrows; pg_row++) {
MAKE_STD_ZVAL(row);
array_init(row);
add_index_zval(ret_array, pg_row, row);
for (i = 0, num_fields = PQnfields(pg_result); i < num_fields; i++) {
if (PQgetisnull(pg_result, pg_row, i)) {
field_name = PQfname(pg_result, i);
add_assoc_null(row, field_name);
} else {
char *element = PQgetvalue(pg_result, pg_row, i);
if (element) {
char *data;
size_t data_len;
const size_t element_len = strlen(element);
data = safe_estrndup(element, element_len);
data_len = element_len;
field_name = PQfname(pg_result, i);
add_assoc_stringl(row, field_name, data, data_len, 0);
}
}
}
}
return SUCCESS;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,237 | PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids_array, zval *ret_array, ulong opt, char **sql TSRMLS_DC)
{
zval *ids_converted = NULL;
smart_str querystr = {0};
int ret = FAILURE;
PGresult *pg_result;
assert(pg_link != NULL);
assert(table != NULL);
assert(Z_TYPE_P(ids_array) == IS_ARRAY);
assert(Z_TYPE_P(ret_array) == IS_ARRAY);
assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING)));
if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
return FAILURE;
}
if (!(opt & PGSQL_DML_NO_CONV)) {
MAKE_STD_ZVAL(ids_converted);
array_init(ids_converted);
if (php_pgsql_convert(pg_link, table, ids_array, ids_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
ids_array = ids_converted;
}
smart_str_appends(&querystr, "SELECT * FROM ");
build_tablename(&querystr, pg_link, table);
smart_str_appends(&querystr, " WHERE ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
smart_str_0(&querystr);
pg_result = PQexec(pg_link, querystr.c);
if (PQresultStatus(pg_result) == PGRES_TUPLES_OK) {
ret = php_pgsql_result2array(pg_result, ret_array TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Failed to execute '%s'", querystr.c);
}
PQclear(pg_result);
cleanup:
if (!(opt & PGSQL_DML_NO_CONV)) {
zval_dtor(ids_converted);
FREE_ZVAL(ids_converted);
}
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) {
*sql = querystr.c;
}
else {
smart_str_free(&querystr);
}
return ret;
}
| Bypass | 0 | PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids_array, zval *ret_array, ulong opt, char **sql TSRMLS_DC)
{
zval *ids_converted = NULL;
smart_str querystr = {0};
int ret = FAILURE;
PGresult *pg_result;
assert(pg_link != NULL);
assert(table != NULL);
assert(Z_TYPE_P(ids_array) == IS_ARRAY);
assert(Z_TYPE_P(ret_array) == IS_ARRAY);
assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING)));
if (zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
return FAILURE;
}
if (!(opt & PGSQL_DML_NO_CONV)) {
MAKE_STD_ZVAL(ids_converted);
array_init(ids_converted);
if (php_pgsql_convert(pg_link, table, ids_array, ids_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
ids_array = ids_converted;
}
smart_str_appends(&querystr, "SELECT * FROM ");
build_tablename(&querystr, pg_link, table);
smart_str_appends(&querystr, " WHERE ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
smart_str_0(&querystr);
pg_result = PQexec(pg_link, querystr.c);
if (PQresultStatus(pg_result) == PGRES_TUPLES_OK) {
ret = php_pgsql_result2array(pg_result, ret_array TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Failed to execute '%s'", querystr.c);
}
PQclear(pg_result);
cleanup:
if (!(opt & PGSQL_DML_NO_CONV)) {
zval_dtor(ids_converted);
FREE_ZVAL(ids_converted);
}
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) {
*sql = querystr.c;
}
else {
smart_str_free(&querystr);
}
return ret;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,238 | static void php_pgsql_set_default_link(int id TSRMLS_DC)
{
zend_list_addref(id);
if (PGG(default_link) != -1) {
zend_list_delete(PGG(default_link));
}
PGG(default_link) = id;
}
| Bypass | 0 | static void php_pgsql_set_default_link(int id TSRMLS_DC)
{
zend_list_addref(id);
if (PGG(default_link) != -1) {
zend_list_delete(PGG(default_link));
}
PGG(default_link) = id;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,239 | static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen)
{
size_t buflen;
unsigned char *buffer,
*sp,
*bp;
unsigned int state = 0;
if (strtext == NULL)
return NULL;
buflen = strlen(strtext); /* will shrink, also we discover if
* strtext */
buffer = (unsigned char *) emalloc(buflen); /* isn't NULL terminated */
for (bp = buffer, sp = strtext; *sp != '\0'; bp++, sp++)
{
switch (state)
{
case 0:
if (*sp == '\\')
state = 1;
*bp = *sp;
break;
case 1:
if (*sp == '\'') /* state=5 */
{ /* replace \' with 39 */
bp--;
*bp = '\'';
buflen--;
state = 0;
}
else if (*sp == '\\') /* state=6 */
{ /* replace \\ with 92 */
bp--;
*bp = '\\';
buflen--;
state = 0;
}
else
{
if (isdigit(*sp))
state = 2;
else
state = 0;
*bp = *sp;
}
break;
case 2:
if (isdigit(*sp))
state = 3;
else
state = 0;
*bp = *sp;
break;
case 3:
if (isdigit(*sp)) /* state=4 */
{
unsigned char *start, *end, buf[4]; /* 000 + '\0' */
bp -= 3;
memcpy(buf, sp-2, 3);
buf[3] = '\0';
start = buf;
*bp = (unsigned char)strtoul(start, (char **)&end, 8);
buflen -= 3;
state = 0;
}
else
{
*bp = *sp;
state = 0;
}
break;
}
}
buffer = erealloc(buffer, buflen+1);
buffer[buflen] = '\0';
*retbuflen = buflen;
return buffer;
}
| Bypass | 0 | static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen)
{
size_t buflen;
unsigned char *buffer,
*sp,
*bp;
unsigned int state = 0;
if (strtext == NULL)
return NULL;
buflen = strlen(strtext); /* will shrink, also we discover if
* strtext */
buffer = (unsigned char *) emalloc(buflen); /* isn't NULL terminated */
for (bp = buffer, sp = strtext; *sp != '\0'; bp++, sp++)
{
switch (state)
{
case 0:
if (*sp == '\\')
state = 1;
*bp = *sp;
break;
case 1:
if (*sp == '\'') /* state=5 */
{ /* replace \' with 39 */
bp--;
*bp = '\'';
buflen--;
state = 0;
}
else if (*sp == '\\') /* state=6 */
{ /* replace \\ with 92 */
bp--;
*bp = '\\';
buflen--;
state = 0;
}
else
{
if (isdigit(*sp))
state = 2;
else
state = 0;
*bp = *sp;
}
break;
case 2:
if (isdigit(*sp))
state = 3;
else
state = 0;
*bp = *sp;
break;
case 3:
if (isdigit(*sp)) /* state=4 */
{
unsigned char *start, *end, buf[4]; /* 000 + '\0' */
bp -= 3;
memcpy(buf, sp-2, 3);
buf[3] = '\0';
start = buf;
*bp = (unsigned char)strtoul(start, (char **)&end, 8);
buflen -= 3;
state = 0;
}
else
{
*bp = *sp;
state = 0;
}
break;
}
}
buffer = erealloc(buffer, buflen+1);
buffer[buflen] = '\0';
*retbuflen = buflen;
return buffer;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,240 | PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array, zval *ids_array, ulong opt, char **sql TSRMLS_DC)
{
zval *var_converted = NULL, *ids_converted = NULL;
smart_str querystr = {0};
int ret = FAILURE;
assert(pg_link != NULL);
assert(table != NULL);
assert(Z_TYPE_P(var_array) == IS_ARRAY);
assert(Z_TYPE_P(ids_array) == IS_ARRAY);
assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING)));
if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0
|| zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
return FAILURE;
}
if (!(opt & PGSQL_DML_NO_CONV)) {
MAKE_STD_ZVAL(var_converted);
array_init(var_converted);
if (php_pgsql_convert(pg_link, table, var_array, var_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
var_array = var_converted;
MAKE_STD_ZVAL(ids_converted);
array_init(ids_converted);
if (php_pgsql_convert(pg_link, table, ids_array, ids_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
ids_array = ids_converted;
}
smart_str_appends(&querystr, "UPDATE ");
build_tablename(&querystr, pg_link, table);
smart_str_appends(&querystr, " SET ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(var_array), 0, ",", 1 TSRMLS_CC))
goto cleanup;
smart_str_appends(&querystr, " WHERE ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
smart_str_0(&querystr);
if ((opt & PGSQL_DML_EXEC) && do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) {
ret = SUCCESS;
} else if (opt & PGSQL_DML_STRING) {
ret = SUCCESS;
}
cleanup:
if (var_converted) {
zval_dtor(var_converted);
FREE_ZVAL(var_converted);
}
if (ids_converted) {
zval_dtor(ids_converted);
FREE_ZVAL(ids_converted);
}
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) {
*sql = querystr.c;
}
else {
smart_str_free(&querystr);
}
return ret;
}
| Bypass | 0 | PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *var_array, zval *ids_array, ulong opt, char **sql TSRMLS_DC)
{
zval *var_converted = NULL, *ids_converted = NULL;
smart_str querystr = {0};
int ret = FAILURE;
assert(pg_link != NULL);
assert(table != NULL);
assert(Z_TYPE_P(var_array) == IS_ARRAY);
assert(Z_TYPE_P(ids_array) == IS_ARRAY);
assert(!(opt & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING)));
if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0
|| zend_hash_num_elements(Z_ARRVAL_P(ids_array)) == 0) {
return FAILURE;
}
if (!(opt & PGSQL_DML_NO_CONV)) {
MAKE_STD_ZVAL(var_converted);
array_init(var_converted);
if (php_pgsql_convert(pg_link, table, var_array, var_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
var_array = var_converted;
MAKE_STD_ZVAL(ids_converted);
array_init(ids_converted);
if (php_pgsql_convert(pg_link, table, ids_array, ids_converted, (opt & PGSQL_CONV_OPTS) TSRMLS_CC) == FAILURE) {
goto cleanup;
}
ids_array = ids_converted;
}
smart_str_appends(&querystr, "UPDATE ");
build_tablename(&querystr, pg_link, table);
smart_str_appends(&querystr, " SET ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(var_array), 0, ",", 1 TSRMLS_CC))
goto cleanup;
smart_str_appends(&querystr, " WHERE ");
if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, " AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
smart_str_0(&querystr);
if ((opt & PGSQL_DML_EXEC) && do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) {
ret = SUCCESS;
} else if (opt & PGSQL_DML_STRING) {
ret = SUCCESS;
}
cleanup:
if (var_converted) {
zval_dtor(var_converted);
FREE_ZVAL(var_converted);
}
if (ids_converted) {
zval_dtor(ids_converted);
FREE_ZVAL(ids_converted);
}
if (ret == SUCCESS && (opt & PGSQL_DML_STRING)) {
*sql = querystr.c;
}
else {
smart_str_free(&querystr);
}
return ret;
}
| @@ -3014,7 +3014,7 @@ PHP_FUNCTION(pg_trace)
php_stream *stream;
id = PGG(default_link);
- if (zend_parse_parameters(argc TSRMLS_CC, "s|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "p|sr", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link) == FAILURE) {
return;
} | CWE-254 | null | null |
12,241 | PHP_FUNCTION(linkinfo)
{
char *link;
char *dirname;
int link_len, dir_len;
struct stat sb;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &link, &link_len) == FAILURE) {
return;
}
dirname = estrndup(link, link_len);
dir_len = php_dirname(dirname, link_len);
if (php_check_open_basedir(dirname TSRMLS_CC)) {
efree(dirname);
RETURN_FALSE;
}
ret = VCWD_LSTAT(link, &sb);
if (ret == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
efree(dirname);
RETURN_LONG(-1L);
}
efree(dirname);
RETURN_LONG((long) sb.st_dev);
}
| Bypass | 0 | PHP_FUNCTION(linkinfo)
{
char *link;
char *dirname;
int link_len, dir_len;
struct stat sb;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &link, &link_len) == FAILURE) {
return;
}
dirname = estrndup(link, link_len);
dir_len = php_dirname(dirname, link_len);
if (php_check_open_basedir(dirname TSRMLS_CC)) {
efree(dirname);
RETURN_FALSE;
}
ret = VCWD_LSTAT(link, &sb);
if (ret == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
efree(dirname);
RETURN_LONG(-1L);
}
efree(dirname);
RETURN_LONG((long) sb.st_dev);
}
| @@ -59,7 +59,7 @@ PHP_FUNCTION(readlink)
char buff[MAXPATHLEN];
int ret;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &link, &link_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &link, &link_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,242 | PHP_FUNCTION(link)
{
char *topath, *frompath;
int topath_len, frompath_len;
int ret;
char source_p[MAXPATHLEN];
char dest_p[MAXPATHLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) {
return;
}
if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
RETURN_FALSE;
}
if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ||
php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) )
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to link to a URL");
RETURN_FALSE;
}
if (php_check_open_basedir(dest_p TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_check_open_basedir(source_p TSRMLS_CC)) {
RETURN_FALSE;
}
#ifndef ZTS
ret = link(topath, frompath);
#else
ret = link(dest_p, source_p);
#endif
if (ret == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
RETURN_TRUE;
}
| Bypass | 0 | PHP_FUNCTION(link)
{
char *topath, *frompath;
int topath_len, frompath_len;
int ret;
char source_p[MAXPATHLEN];
char dest_p[MAXPATHLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) {
return;
}
if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
RETURN_FALSE;
}
if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ||
php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) )
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to link to a URL");
RETURN_FALSE;
}
if (php_check_open_basedir(dest_p TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_check_open_basedir(source_p TSRMLS_CC)) {
RETURN_FALSE;
}
#ifndef ZTS
ret = link(topath, frompath);
#else
ret = link(dest_p, source_p);
#endif
if (ret == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
RETURN_TRUE;
}
| @@ -59,7 +59,7 @@ PHP_FUNCTION(readlink)
char buff[MAXPATHLEN];
int ret;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &link, &link_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &link, &link_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,243 | PHP_FUNCTION(stream_socket_client)
{
char *host;
int host_len;
zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL;
double timeout = FG(default_socket_timeout);
php_timeout_ull conv;
struct timeval tv;
char *hashkey = NULL;
php_stream *stream = NULL;
int err;
long flags = PHP_STREAM_CLIENT_CONNECT;
char *errstr = NULL;
php_stream_context *context = NULL;
RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zzdlr", &host, &host_len, &zerrno, &zerrstr, &timeout, &flags, &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
if (flags & PHP_STREAM_CLIENT_PERSISTENT) {
spprintf(&hashkey, 0, "stream_socket_client__%s", host);
}
/* prepare the timeout value for use */
conv = (php_timeout_ull) (timeout * 1000000.0);
#ifdef PHP_WIN32
tv.tv_sec = (long)(conv / 1000000);
tv.tv_usec =(long)(conv % 1000000);
#else
tv.tv_sec = conv / 1000000;
tv.tv_usec = conv % 1000000;
#endif
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, 0);
}
if (zerrstr) {
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, "", 1);
}
stream = php_stream_xport_create(host, host_len, REPORT_ERRORS,
STREAM_XPORT_CLIENT | (flags & PHP_STREAM_CLIENT_CONNECT ? STREAM_XPORT_CONNECT : 0) |
(flags & PHP_STREAM_CLIENT_ASYNC_CONNECT ? STREAM_XPORT_CONNECT_ASYNC : 0),
hashkey, &tv, context, &errstr, &err);
if (stream == NULL) {
/* host might contain binary characters */
char *quoted_host = php_addslashes(host, host_len, NULL, 0 TSRMLS_CC);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host, errstr == NULL ? "Unknown error" : errstr);
efree(quoted_host);
}
if (hashkey) {
efree(hashkey);
}
if (stream == NULL) {
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, err);
}
if (zerrstr && errstr) {
/* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, errstr, 0);
} else if (errstr) {
efree(errstr);
}
RETURN_FALSE;
}
if (errstr) {
efree(errstr);
}
php_stream_to_zval(stream, return_value);
}
| Bypass | 0 | PHP_FUNCTION(stream_socket_client)
{
char *host;
int host_len;
zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL;
double timeout = FG(default_socket_timeout);
php_timeout_ull conv;
struct timeval tv;
char *hashkey = NULL;
php_stream *stream = NULL;
int err;
long flags = PHP_STREAM_CLIENT_CONNECT;
char *errstr = NULL;
php_stream_context *context = NULL;
RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zzdlr", &host, &host_len, &zerrno, &zerrstr, &timeout, &flags, &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
if (flags & PHP_STREAM_CLIENT_PERSISTENT) {
spprintf(&hashkey, 0, "stream_socket_client__%s", host);
}
/* prepare the timeout value for use */
conv = (php_timeout_ull) (timeout * 1000000.0);
#ifdef PHP_WIN32
tv.tv_sec = (long)(conv / 1000000);
tv.tv_usec =(long)(conv % 1000000);
#else
tv.tv_sec = conv / 1000000;
tv.tv_usec = conv % 1000000;
#endif
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, 0);
}
if (zerrstr) {
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, "", 1);
}
stream = php_stream_xport_create(host, host_len, REPORT_ERRORS,
STREAM_XPORT_CLIENT | (flags & PHP_STREAM_CLIENT_CONNECT ? STREAM_XPORT_CONNECT : 0) |
(flags & PHP_STREAM_CLIENT_ASYNC_CONNECT ? STREAM_XPORT_CONNECT_ASYNC : 0),
hashkey, &tv, context, &errstr, &err);
if (stream == NULL) {
/* host might contain binary characters */
char *quoted_host = php_addslashes(host, host_len, NULL, 0 TSRMLS_CC);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host, errstr == NULL ? "Unknown error" : errstr);
efree(quoted_host);
}
if (hashkey) {
efree(hashkey);
}
if (stream == NULL) {
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, err);
}
if (zerrstr && errstr) {
/* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, errstr, 0);
} else if (errstr) {
efree(errstr);
}
RETURN_FALSE;
}
if (errstr) {
efree(errstr);
}
php_stream_to_zval(stream, return_value);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,244 | PHP_FUNCTION(stream_socket_server)
{
char *host;
int host_len;
zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL;
php_stream *stream = NULL;
int err = 0;
long flags = STREAM_XPORT_BIND | STREAM_XPORT_LISTEN;
char *errstr = NULL;
php_stream_context *context = NULL;
RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zzlr", &host, &host_len, &zerrno, &zerrstr, &flags, &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
if (context) {
zend_list_addref(context->rsrc_id);
}
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, 0);
}
if (zerrstr) {
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, "", 1);
}
stream = php_stream_xport_create(host, host_len, REPORT_ERRORS,
STREAM_XPORT_SERVER | flags,
NULL, NULL, context, &errstr, &err);
if (stream == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr);
}
if (stream == NULL) {
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, err);
}
if (zerrstr && errstr) {
/* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, errstr, 0);
} else if (errstr) {
efree(errstr);
}
RETURN_FALSE;
}
if (errstr) {
efree(errstr);
}
php_stream_to_zval(stream, return_value);
}
| Bypass | 0 | PHP_FUNCTION(stream_socket_server)
{
char *host;
int host_len;
zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL;
php_stream *stream = NULL;
int err = 0;
long flags = STREAM_XPORT_BIND | STREAM_XPORT_LISTEN;
char *errstr = NULL;
php_stream_context *context = NULL;
RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zzlr", &host, &host_len, &zerrno, &zerrstr, &flags, &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
if (context) {
zend_list_addref(context->rsrc_id);
}
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, 0);
}
if (zerrstr) {
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, "", 1);
}
stream = php_stream_xport_create(host, host_len, REPORT_ERRORS,
STREAM_XPORT_SERVER | flags,
NULL, NULL, context, &errstr, &err);
if (stream == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr);
}
if (stream == NULL) {
if (zerrno) {
zval_dtor(zerrno);
ZVAL_LONG(zerrno, err);
}
if (zerrstr && errstr) {
/* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
ZVAL_STRING(zerrstr, errstr, 0);
} else if (errstr) {
efree(errstr);
}
RETURN_FALSE;
}
if (errstr) {
efree(errstr);
}
php_stream_to_zval(stream, return_value);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,245 | PHP_FUNCTION(stream_socket_accept)
{
double timeout = FG(default_socket_timeout);
zval *zpeername = NULL;
char *peername = NULL;
int peername_len;
php_timeout_ull conv;
struct timeval tv;
php_stream *stream = NULL, *clistream = NULL;
zval *zstream;
char *errstr = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|dz", &zstream, &timeout, &zpeername) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
/* prepare the timeout value for use */
conv = (php_timeout_ull) (timeout * 1000000.0);
#ifdef PHP_WIN32
tv.tv_sec = (long)(conv / 1000000);
tv.tv_usec = (long)(conv % 1000000);
#else
tv.tv_sec = conv / 1000000;
tv.tv_usec = conv % 1000000;
#endif
if (zpeername) {
zval_dtor(zpeername);
ZVAL_NULL(zpeername);
}
if (0 == php_stream_xport_accept(stream, &clistream,
zpeername ? &peername : NULL,
zpeername ? &peername_len : NULL,
NULL, NULL,
&tv, &errstr
TSRMLS_CC) && clistream) {
if (peername) {
ZVAL_STRINGL(zpeername, peername, peername_len, 0);
}
php_stream_to_zval(clistream, return_value);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "accept failed: %s", errstr ? errstr : "Unknown error");
RETVAL_FALSE;
}
if (errstr) {
efree(errstr);
}
}
| Bypass | 0 | PHP_FUNCTION(stream_socket_accept)
{
double timeout = FG(default_socket_timeout);
zval *zpeername = NULL;
char *peername = NULL;
int peername_len;
php_timeout_ull conv;
struct timeval tv;
php_stream *stream = NULL, *clistream = NULL;
zval *zstream;
char *errstr = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|dz", &zstream, &timeout, &zpeername) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
/* prepare the timeout value for use */
conv = (php_timeout_ull) (timeout * 1000000.0);
#ifdef PHP_WIN32
tv.tv_sec = (long)(conv / 1000000);
tv.tv_usec = (long)(conv % 1000000);
#else
tv.tv_sec = conv / 1000000;
tv.tv_usec = conv % 1000000;
#endif
if (zpeername) {
zval_dtor(zpeername);
ZVAL_NULL(zpeername);
}
if (0 == php_stream_xport_accept(stream, &clistream,
zpeername ? &peername : NULL,
zpeername ? &peername_len : NULL,
NULL, NULL,
&tv, &errstr
TSRMLS_CC) && clistream) {
if (peername) {
ZVAL_STRINGL(zpeername, peername, peername_len, 0);
}
php_stream_to_zval(clistream, return_value);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "accept failed: %s", errstr ? errstr : "Unknown error");
RETVAL_FALSE;
}
if (errstr) {
efree(errstr);
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,246 | PHP_FUNCTION(stream_socket_sendto)
{
php_stream *stream;
zval *zstream;
long flags = 0;
char *data, *target_addr = NULL;
int datalen, target_addr_len = 0;
php_sockaddr_storage sa;
socklen_t sl = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ls", &zstream, &data, &datalen, &flags, &target_addr, &target_addr_len) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if (target_addr_len) {
/* parse the address */
if (FAILURE == php_network_parse_network_address_with_port(target_addr, target_addr_len, (struct sockaddr*)&sa, &sl TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse `%s' into a valid network address", target_addr);
RETURN_FALSE;
}
}
RETURN_LONG(php_stream_xport_sendto(stream, data, datalen, flags, target_addr ? &sa : NULL, sl TSRMLS_CC));
}
| Bypass | 0 | PHP_FUNCTION(stream_socket_sendto)
{
php_stream *stream;
zval *zstream;
long flags = 0;
char *data, *target_addr = NULL;
int datalen, target_addr_len = 0;
php_sockaddr_storage sa;
socklen_t sl = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ls", &zstream, &data, &datalen, &flags, &target_addr, &target_addr_len) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if (target_addr_len) {
/* parse the address */
if (FAILURE == php_network_parse_network_address_with_port(target_addr, target_addr_len, (struct sockaddr*)&sa, &sl TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse `%s' into a valid network address", target_addr);
RETURN_FALSE;
}
}
RETURN_LONG(php_stream_xport_sendto(stream, data, datalen, flags, target_addr ? &sa : NULL, sl TSRMLS_CC));
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,247 | PHP_FUNCTION(stream_socket_recvfrom)
{
php_stream *stream;
zval *zstream, *zremote = NULL;
char *remote_addr = NULL;
int remote_addr_len;
long to_read = 0;
char *read_buf;
long flags = 0;
int recvd;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|lz", &zstream, &to_read, &flags, &zremote) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if (zremote) {
zval_dtor(zremote);
ZVAL_NULL(zremote);
}
if (to_read <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
}
read_buf = safe_emalloc(1, to_read, 1);
recvd = php_stream_xport_recvfrom(stream, read_buf, to_read, flags, NULL, NULL,
zremote ? &remote_addr : NULL,
zremote ? &remote_addr_len : NULL
TSRMLS_CC);
if (recvd >= 0) {
if (zremote) {
ZVAL_STRINGL(zremote, remote_addr, remote_addr_len, 0);
}
read_buf[recvd] = '\0';
RETURN_STRINGL(read_buf, recvd, 0);
}
efree(read_buf);
RETURN_FALSE;
}
| Bypass | 0 | PHP_FUNCTION(stream_socket_recvfrom)
{
php_stream *stream;
zval *zstream, *zremote = NULL;
char *remote_addr = NULL;
int remote_addr_len;
long to_read = 0;
char *read_buf;
long flags = 0;
int recvd;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|lz", &zstream, &to_read, &flags, &zremote) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if (zremote) {
zval_dtor(zremote);
ZVAL_NULL(zremote);
}
if (to_read <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
}
read_buf = safe_emalloc(1, to_read, 1);
recvd = php_stream_xport_recvfrom(stream, read_buf, to_read, flags, NULL, NULL,
zremote ? &remote_addr : NULL,
zremote ? &remote_addr_len : NULL
TSRMLS_CC);
if (recvd >= 0) {
if (zremote) {
ZVAL_STRINGL(zremote, remote_addr, remote_addr_len, 0);
}
read_buf[recvd] = '\0';
RETURN_STRINGL(read_buf, recvd, 0);
}
efree(read_buf);
RETURN_FALSE;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,248 | PHP_FUNCTION(stream_get_contents)
{
php_stream *stream;
zval *zsrc;
long maxlen = PHP_STREAM_COPY_ALL,
desiredpos = -1L;
long len;
char *contents = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zsrc, &maxlen, &desiredpos) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zsrc);
if (desiredpos >= 0) {
int seek_res = 0;
off_t position;
position = php_stream_tell(stream);
if (position >= 0 && desiredpos > position) {
/* use SEEK_CUR to allow emulation in streams that don't support seeking */
seek_res = php_stream_seek(stream, desiredpos - position, SEEK_CUR);
} else if (desiredpos < position) {
/* desired position before position or error on tell */
seek_res = php_stream_seek(stream, desiredpos, SEEK_SET);
}
if (seek_res != 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Failed to seek to position %ld in the stream", desiredpos);
RETURN_FALSE;
}
}
len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);
if (contents) {
if (len > INT_MAX) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "content truncated from %ld to %d bytes", len, INT_MAX);
len = INT_MAX;
}
RETVAL_STRINGL(contents, len, 0);
} else {
RETVAL_EMPTY_STRING();
}
}
| Bypass | 0 | PHP_FUNCTION(stream_get_contents)
{
php_stream *stream;
zval *zsrc;
long maxlen = PHP_STREAM_COPY_ALL,
desiredpos = -1L;
long len;
char *contents = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zsrc, &maxlen, &desiredpos) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zsrc);
if (desiredpos >= 0) {
int seek_res = 0;
off_t position;
position = php_stream_tell(stream);
if (position >= 0 && desiredpos > position) {
/* use SEEK_CUR to allow emulation in streams that don't support seeking */
seek_res = php_stream_seek(stream, desiredpos - position, SEEK_CUR);
} else if (desiredpos < position) {
/* desired position before position or error on tell */
seek_res = php_stream_seek(stream, desiredpos, SEEK_SET);
}
if (seek_res != 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Failed to seek to position %ld in the stream", desiredpos);
RETURN_FALSE;
}
}
len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);
if (contents) {
if (len > INT_MAX) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "content truncated from %ld to %d bytes", len, INT_MAX);
len = INT_MAX;
}
RETVAL_STRINGL(contents, len, 0);
} else {
RETVAL_EMPTY_STRING();
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,249 | PHP_FUNCTION(stream_copy_to_stream)
{
php_stream *src, *dest;
zval *zsrc, *zdest;
long maxlen = PHP_STREAM_COPY_ALL, pos = 0;
size_t len;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|ll", &zsrc, &zdest, &maxlen, &pos) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(src, &zsrc);
php_stream_from_zval(dest, &zdest);
if (pos > 0 && php_stream_seek(src, pos, SEEK_SET) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
RETURN_FALSE;
}
ret = php_stream_copy_to_stream_ex(src, dest, maxlen, &len);
if (ret != SUCCESS) {
RETURN_FALSE;
}
RETURN_LONG(len);
}
| Bypass | 0 | PHP_FUNCTION(stream_copy_to_stream)
{
php_stream *src, *dest;
zval *zsrc, *zdest;
long maxlen = PHP_STREAM_COPY_ALL, pos = 0;
size_t len;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|ll", &zsrc, &zdest, &maxlen, &pos) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(src, &zsrc);
php_stream_from_zval(dest, &zdest);
if (pos > 0 && php_stream_seek(src, pos, SEEK_SET) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
RETURN_FALSE;
}
ret = php_stream_copy_to_stream_ex(src, dest, maxlen, &len);
if (ret != SUCCESS) {
RETURN_FALSE;
}
RETURN_LONG(len);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,250 | PHP_FUNCTION(stream_get_transports)
{
HashTable *stream_xport_hash;
char *stream_xport;
uint stream_xport_len;
ulong num_key;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((stream_xport_hash = php_stream_xport_get_hash())) {
HashPosition pos;
array_init(return_value);
zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
while (zend_hash_get_current_key_ex(stream_xport_hash,
&stream_xport, &stream_xport_len,
&num_key, 0, &pos) == HASH_KEY_IS_STRING) {
add_next_index_stringl(return_value, stream_xport, stream_xport_len - 1, 1);
zend_hash_move_forward_ex(stream_xport_hash, &pos);
}
} else {
RETURN_FALSE;
}
}
| Bypass | 0 | PHP_FUNCTION(stream_get_transports)
{
HashTable *stream_xport_hash;
char *stream_xport;
uint stream_xport_len;
ulong num_key;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if ((stream_xport_hash = php_stream_xport_get_hash())) {
HashPosition pos;
array_init(return_value);
zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
while (zend_hash_get_current_key_ex(stream_xport_hash,
&stream_xport, &stream_xport_len,
&num_key, 0, &pos) == HASH_KEY_IS_STRING) {
add_next_index_stringl(return_value, stream_xport, stream_xport_len - 1, 1);
zend_hash_move_forward_ex(stream_xport_hash, &pos);
}
} else {
RETURN_FALSE;
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,251 | PHP_FUNCTION(stream_select)
{
zval *r_array, *w_array, *e_array, **sec = NULL;
struct timeval tv;
struct timeval *tv_p = NULL;
fd_set rfds, wfds, efds;
php_socket_t max_fd = 0;
int retval, sets = 0;
long usec = 0;
int set_count, max_set_count = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!Z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE)
return;
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&efds);
if (r_array != NULL) {
set_count = stream_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC);
if (set_count > max_set_count)
max_set_count = set_count;
sets += set_count;
}
if (w_array != NULL) {
set_count = stream_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC);
if (set_count > max_set_count)
max_set_count = set_count;
sets += set_count;
}
if (e_array != NULL) {
set_count = stream_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC);
if (set_count > max_set_count)
max_set_count = set_count;
sets += set_count;
}
if (!sets) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No stream arrays were passed");
RETURN_FALSE;
}
PHP_SAFE_MAX_FD(max_fd, max_set_count);
/* If seconds is not set to null, build the timeval, else we wait indefinitely */
if (sec != NULL) {
convert_to_long_ex(sec);
if (Z_LVAL_PP(sec) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The seconds parameter must be greater than 0");
RETURN_FALSE;
} else if (usec < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The microseconds parameter must be greater than 0");
RETURN_FALSE;
}
/* Solaris + BSD do not like microsecond values which are >= 1 sec */
if (usec > 999999) {
tv.tv_sec = Z_LVAL_PP(sec) + (usec / 1000000);
tv.tv_usec = usec % 1000000;
} else {
tv.tv_sec = Z_LVAL_PP(sec);
tv.tv_usec = usec;
}
tv_p = &tv;
}
/* slight hack to support buffered data; if there is data sitting in the
* read buffer of any of the streams in the read array, let's pretend
* that we selected, but return only the readable sockets */
if (r_array != NULL) {
retval = stream_array_emulate_read_fd_set(r_array TSRMLS_CC);
if (retval > 0) {
if (w_array != NULL) {
zend_hash_clean(Z_ARRVAL_P(w_array));
}
if (e_array != NULL) {
zend_hash_clean(Z_ARRVAL_P(e_array));
}
RETURN_LONG(retval);
}
}
retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p);
if (retval == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to select [%d]: %s (max_fd=%d)",
errno, strerror(errno), max_fd);
RETURN_FALSE;
}
if (r_array != NULL) stream_array_from_fd_set(r_array, &rfds TSRMLS_CC);
if (w_array != NULL) stream_array_from_fd_set(w_array, &wfds TSRMLS_CC);
if (e_array != NULL) stream_array_from_fd_set(e_array, &efds TSRMLS_CC);
RETURN_LONG(retval);
}
| Bypass | 0 | PHP_FUNCTION(stream_select)
{
zval *r_array, *w_array, *e_array, **sec = NULL;
struct timeval tv;
struct timeval *tv_p = NULL;
fd_set rfds, wfds, efds;
php_socket_t max_fd = 0;
int retval, sets = 0;
long usec = 0;
int set_count, max_set_count = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!Z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE)
return;
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&efds);
if (r_array != NULL) {
set_count = stream_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC);
if (set_count > max_set_count)
max_set_count = set_count;
sets += set_count;
}
if (w_array != NULL) {
set_count = stream_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC);
if (set_count > max_set_count)
max_set_count = set_count;
sets += set_count;
}
if (e_array != NULL) {
set_count = stream_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC);
if (set_count > max_set_count)
max_set_count = set_count;
sets += set_count;
}
if (!sets) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No stream arrays were passed");
RETURN_FALSE;
}
PHP_SAFE_MAX_FD(max_fd, max_set_count);
/* If seconds is not set to null, build the timeval, else we wait indefinitely */
if (sec != NULL) {
convert_to_long_ex(sec);
if (Z_LVAL_PP(sec) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The seconds parameter must be greater than 0");
RETURN_FALSE;
} else if (usec < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The microseconds parameter must be greater than 0");
RETURN_FALSE;
}
/* Solaris + BSD do not like microsecond values which are >= 1 sec */
if (usec > 999999) {
tv.tv_sec = Z_LVAL_PP(sec) + (usec / 1000000);
tv.tv_usec = usec % 1000000;
} else {
tv.tv_sec = Z_LVAL_PP(sec);
tv.tv_usec = usec;
}
tv_p = &tv;
}
/* slight hack to support buffered data; if there is data sitting in the
* read buffer of any of the streams in the read array, let's pretend
* that we selected, but return only the readable sockets */
if (r_array != NULL) {
retval = stream_array_emulate_read_fd_set(r_array TSRMLS_CC);
if (retval > 0) {
if (w_array != NULL) {
zend_hash_clean(Z_ARRVAL_P(w_array));
}
if (e_array != NULL) {
zend_hash_clean(Z_ARRVAL_P(e_array));
}
RETURN_LONG(retval);
}
}
retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p);
if (retval == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to select [%d]: %s (max_fd=%d)",
errno, strerror(errno), max_fd);
RETURN_FALSE;
}
if (r_array != NULL) stream_array_from_fd_set(r_array, &rfds TSRMLS_CC);
if (w_array != NULL) stream_array_from_fd_set(w_array, &wfds TSRMLS_CC);
if (e_array != NULL) stream_array_from_fd_set(e_array, &efds TSRMLS_CC);
RETURN_LONG(retval);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,252 | PHP_FUNCTION(stream_context_get_options)
{
zval *zcontext;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
RETURN_ZVAL(context->options, 1, 0);
}
| Bypass | 0 | PHP_FUNCTION(stream_context_get_options)
{
zval *zcontext;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
RETURN_ZVAL(context->options, 1, 0);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,253 | PHP_FUNCTION(stream_context_set_option)
{
zval *options = NULL, *zcontext = NULL, *zvalue = NULL;
php_stream_context *context;
char *wrappername, *optionname;
int wrapperlen, optionlen;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"rssz", &zcontext, &wrappername, &wrapperlen,
&optionname, &optionlen, &zvalue) == FAILURE) {
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"ra", &zcontext, &options) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "called with wrong number or type of parameters; please RTM");
RETURN_FALSE;
}
}
/* figure out where the context is coming from exactly */
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
if (options) {
/* handle the array syntax */
RETVAL_BOOL(parse_context_options(context, options TSRMLS_CC) == SUCCESS);
} else {
php_stream_context_set_option(context, wrappername, optionname, zvalue);
RETVAL_TRUE;
}
}
| Bypass | 0 | PHP_FUNCTION(stream_context_set_option)
{
zval *options = NULL, *zcontext = NULL, *zvalue = NULL;
php_stream_context *context;
char *wrappername, *optionname;
int wrapperlen, optionlen;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"rssz", &zcontext, &wrappername, &wrapperlen,
&optionname, &optionlen, &zvalue) == FAILURE) {
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"ra", &zcontext, &options) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "called with wrong number or type of parameters; please RTM");
RETURN_FALSE;
}
}
/* figure out where the context is coming from exactly */
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
if (options) {
/* handle the array syntax */
RETVAL_BOOL(parse_context_options(context, options TSRMLS_CC) == SUCCESS);
} else {
php_stream_context_set_option(context, wrappername, optionname, zvalue);
RETVAL_TRUE;
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,254 | PHP_FUNCTION(stream_context_set_params)
{
zval *params, *zcontext;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zcontext, ¶ms) == FAILURE) {
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
RETVAL_BOOL(parse_context_params(context, params TSRMLS_CC) == SUCCESS);
}
| Bypass | 0 | PHP_FUNCTION(stream_context_set_params)
{
zval *params, *zcontext;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zcontext, ¶ms) == FAILURE) {
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
RETVAL_BOOL(parse_context_params(context, params TSRMLS_CC) == SUCCESS);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,255 | PHP_FUNCTION(stream_context_get_params)
{
zval *zcontext, *options;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
array_init(return_value);
if (context->notifier && context->notifier->ptr && context->notifier->func == user_space_stream_notifier) {
add_assoc_zval_ex(return_value, ZEND_STRS("notification"), context->notifier->ptr);
Z_ADDREF_P(context->notifier->ptr);
}
ALLOC_INIT_ZVAL(options);
ZVAL_ZVAL(options, context->options, 1, 0);
add_assoc_zval_ex(return_value, ZEND_STRS("options"), options);
}
| Bypass | 0 | PHP_FUNCTION(stream_context_get_params)
{
zval *zcontext, *options;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) {
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
if (!context) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
RETURN_FALSE;
}
array_init(return_value);
if (context->notifier && context->notifier->ptr && context->notifier->func == user_space_stream_notifier) {
add_assoc_zval_ex(return_value, ZEND_STRS("notification"), context->notifier->ptr);
Z_ADDREF_P(context->notifier->ptr);
}
ALLOC_INIT_ZVAL(options);
ZVAL_ZVAL(options, context->options, 1, 0);
add_assoc_zval_ex(return_value, ZEND_STRS("options"), options);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,256 | PHP_FUNCTION(stream_context_get_default)
{
zval *params = NULL;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", ¶ms) == FAILURE) {
RETURN_FALSE;
}
if (FG(default_context) == NULL) {
FG(default_context) = php_stream_context_alloc(TSRMLS_C);
}
context = FG(default_context);
if (params) {
parse_context_options(context, params TSRMLS_CC);
}
php_stream_context_to_zval(context, return_value);
}
| Bypass | 0 | PHP_FUNCTION(stream_context_get_default)
{
zval *params = NULL;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", ¶ms) == FAILURE) {
RETURN_FALSE;
}
if (FG(default_context) == NULL) {
FG(default_context) = php_stream_context_alloc(TSRMLS_C);
}
context = FG(default_context);
if (params) {
parse_context_options(context, params TSRMLS_CC);
}
php_stream_context_to_zval(context, return_value);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,257 | PHP_FUNCTION(stream_context_set_default)
{
zval *options = NULL;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &options) == FAILURE) {
return;
}
if (FG(default_context) == NULL) {
FG(default_context) = php_stream_context_alloc(TSRMLS_C);
}
context = FG(default_context);
parse_context_options(context, options TSRMLS_CC);
php_stream_context_to_zval(context, return_value);
}
| Bypass | 0 | PHP_FUNCTION(stream_context_set_default)
{
zval *options = NULL;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &options) == FAILURE) {
return;
}
if (FG(default_context) == NULL) {
FG(default_context) = php_stream_context_alloc(TSRMLS_C);
}
context = FG(default_context);
parse_context_options(context, options TSRMLS_CC);
php_stream_context_to_zval(context, return_value);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,258 | PHP_FUNCTION(stream_context_create)
{
zval *options = NULL, *params = NULL;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!a!", &options, ¶ms) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_alloc(TSRMLS_C);
if (options) {
parse_context_options(context, options TSRMLS_CC);
}
if (params) {
parse_context_params(context, params TSRMLS_CC);
}
RETURN_RESOURCE(context->rsrc_id);
}
| Bypass | 0 | PHP_FUNCTION(stream_context_create)
{
zval *options = NULL, *params = NULL;
php_stream_context *context;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!a!", &options, ¶ms) == FAILURE) {
RETURN_FALSE;
}
context = php_stream_context_alloc(TSRMLS_C);
if (options) {
parse_context_options(context, options TSRMLS_CC);
}
if (params) {
parse_context_params(context, params TSRMLS_CC);
}
RETURN_RESOURCE(context->rsrc_id);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,259 | PHP_FUNCTION(stream_filter_prepend)
{
apply_filter_to_stream(0, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| Bypass | 0 | PHP_FUNCTION(stream_filter_prepend)
{
apply_filter_to_stream(0, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,260 | PHP_FUNCTION(stream_filter_append)
{
apply_filter_to_stream(1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| Bypass | 0 | PHP_FUNCTION(stream_filter_append)
{
apply_filter_to_stream(1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,261 | PHP_FUNCTION(stream_get_line)
{
char *str = NULL;
int str_len = 0;
long max_length;
zval *zstream;
char *buf;
size_t buf_size;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|s", &zstream, &max_length, &str, &str_len) == FAILURE) {
RETURN_FALSE;
}
if (max_length < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The maximum allowed length must be greater than or equal to zero");
RETURN_FALSE;
}
if (!max_length) {
max_length = PHP_SOCK_CHUNK_SIZE;
}
php_stream_from_zval(stream, &zstream);
if ((buf = php_stream_get_record(stream, max_length, &buf_size, str, str_len TSRMLS_CC))) {
RETURN_STRINGL(buf, buf_size, 0);
} else {
RETURN_FALSE;
}
}
| Bypass | 0 | PHP_FUNCTION(stream_get_line)
{
char *str = NULL;
int str_len = 0;
long max_length;
zval *zstream;
char *buf;
size_t buf_size;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|s", &zstream, &max_length, &str, &str_len) == FAILURE) {
RETURN_FALSE;
}
if (max_length < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The maximum allowed length must be greater than or equal to zero");
RETURN_FALSE;
}
if (!max_length) {
max_length = PHP_SOCK_CHUNK_SIZE;
}
php_stream_from_zval(stream, &zstream);
if ((buf = php_stream_get_record(stream, max_length, &buf_size, str, str_len TSRMLS_CC))) {
RETURN_STRINGL(buf, buf_size, 0);
} else {
RETURN_FALSE;
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,262 | PHP_FUNCTION(stream_set_blocking)
{
zval *arg1;
int block;
long arg2;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
return;
}
php_stream_from_zval(stream, &arg1);
block = arg2;
if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1) {
RETURN_FALSE;
}
RETURN_TRUE;
}
| Bypass | 0 | PHP_FUNCTION(stream_set_blocking)
{
zval *arg1;
int block;
long arg2;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
return;
}
php_stream_from_zval(stream, &arg1);
block = arg2;
if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1) {
RETURN_FALSE;
}
RETURN_TRUE;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,263 | PHP_FUNCTION(stream_set_timeout)
{
zval *socket;
long seconds, microseconds = 0;
struct timeval t;
php_stream *stream;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rl|l", &socket, &seconds, µseconds) == FAILURE) {
return;
}
php_stream_from_zval(stream, &socket);
t.tv_sec = seconds;
if (argc == 3) {
t.tv_usec = microseconds % 1000000;
t.tv_sec += microseconds / 1000000;
} else {
t.tv_usec = 0;
}
if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t)) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| Bypass | 0 | PHP_FUNCTION(stream_set_timeout)
{
zval *socket;
long seconds, microseconds = 0;
struct timeval t;
php_stream *stream;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rl|l", &socket, &seconds, µseconds) == FAILURE) {
return;
}
php_stream_from_zval(stream, &socket);
t.tv_sec = seconds;
if (argc == 3) {
t.tv_usec = microseconds % 1000000;
t.tv_sec += microseconds / 1000000;
} else {
t.tv_usec = 0;
}
if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t)) {
RETURN_TRUE;
}
RETURN_FALSE;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,264 | PHP_FUNCTION(stream_set_write_buffer)
{
zval *arg1;
int ret;
long arg2;
size_t buff;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &arg1);
buff = arg2;
/* if buff is 0 then set to non-buffered */
if (buff == 0) {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
} else {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buff);
}
RETURN_LONG(ret == 0 ? 0 : EOF);
}
| Bypass | 0 | PHP_FUNCTION(stream_set_write_buffer)
{
zval *arg1;
int ret;
long arg2;
size_t buff;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &arg1);
buff = arg2;
/* if buff is 0 then set to non-buffered */
if (buff == 0) {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
} else {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buff);
}
RETURN_LONG(ret == 0 ? 0 : EOF);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,265 | PHP_FUNCTION(stream_set_chunk_size)
{
int ret;
long csize;
zval *zstream;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zstream, &csize) == FAILURE) {
RETURN_FALSE;
}
if (csize <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size must be a positive integer, given %ld", csize);
RETURN_FALSE;
}
/* stream.chunk_size is actually a size_t, but php_stream_set_option
* can only use an int to accept the new value and return the old one.
* In any case, values larger than INT_MAX for a chunk size make no sense.
*/
if (csize > INT_MAX) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size cannot be larger than %d", INT_MAX);
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_SET_CHUNK_SIZE, (int)csize, NULL);
RETURN_LONG(ret > 0 ? (long)ret : (long)EOF);
}
| Bypass | 0 | PHP_FUNCTION(stream_set_chunk_size)
{
int ret;
long csize;
zval *zstream;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zstream, &csize) == FAILURE) {
RETURN_FALSE;
}
if (csize <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size must be a positive integer, given %ld", csize);
RETURN_FALSE;
}
/* stream.chunk_size is actually a size_t, but php_stream_set_option
* can only use an int to accept the new value and return the old one.
* In any case, values larger than INT_MAX for a chunk size make no sense.
*/
if (csize > INT_MAX) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size cannot be larger than %d", INT_MAX);
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_SET_CHUNK_SIZE, (int)csize, NULL);
RETURN_LONG(ret > 0 ? (long)ret : (long)EOF);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,266 | PHP_FUNCTION(stream_set_read_buffer)
{
zval *arg1;
int ret;
long arg2;
size_t buff;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &arg1);
buff = arg2;
/* if buff is 0 then set to non-buffered */
if (buff == 0) {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
} else {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_FULL, &buff);
}
RETURN_LONG(ret == 0 ? 0 : EOF);
}
| Bypass | 0 | PHP_FUNCTION(stream_set_read_buffer)
{
zval *arg1;
int ret;
long arg2;
size_t buff;
php_stream *stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &arg1);
buff = arg2;
/* if buff is 0 then set to non-buffered */
if (buff == 0) {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
} else {
ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_FULL, &buff);
}
RETURN_LONG(ret == 0 ? 0 : EOF);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,267 | PHP_FUNCTION(stream_socket_enable_crypto)
{
long cryptokind = 0;
zval *zstream, *zsessstream = NULL;
php_stream *stream, *sessstream = NULL;
zend_bool enable;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if (ZEND_NUM_ARGS() >= 3) {
if (zsessstream) {
php_stream_from_zval(sessstream, &zsessstream);
}
if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) {
RETURN_FALSE;
}
} else if (enable) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type");
RETURN_FALSE;
}
ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC);
switch (ret) {
case -1:
RETURN_FALSE;
case 0:
RETURN_LONG(0);
default:
RETURN_TRUE;
}
}
| Bypass | 0 | PHP_FUNCTION(stream_socket_enable_crypto)
{
long cryptokind = 0;
zval *zstream, *zsessstream = NULL;
php_stream *stream, *sessstream = NULL;
zend_bool enable;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if (ZEND_NUM_ARGS() >= 3) {
if (zsessstream) {
php_stream_from_zval(sessstream, &zsessstream);
}
if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) {
RETURN_FALSE;
}
} else if (enable) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type");
RETURN_FALSE;
}
ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC);
switch (ret) {
case -1:
RETURN_FALSE;
case 0:
RETURN_LONG(0);
default:
RETURN_TRUE;
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,268 | PHP_FUNCTION(stream_is_local)
{
zval **zstream;
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &zstream) == FAILURE) {
RETURN_FALSE;
}
if (Z_TYPE_PP(zstream) == IS_RESOURCE) {
php_stream_from_zval(stream, zstream);
if (stream == NULL) {
RETURN_FALSE;
}
wrapper = stream->wrapper;
} else {
convert_to_string_ex(zstream);
wrapper = php_stream_locate_url_wrapper(Z_STRVAL_PP(zstream), NULL, 0 TSRMLS_CC);
}
if (!wrapper) {
RETURN_FALSE;
}
RETURN_BOOL(wrapper->is_url==0);
}
| Bypass | 0 | PHP_FUNCTION(stream_is_local)
{
zval **zstream;
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &zstream) == FAILURE) {
RETURN_FALSE;
}
if (Z_TYPE_PP(zstream) == IS_RESOURCE) {
php_stream_from_zval(stream, zstream);
if (stream == NULL) {
RETURN_FALSE;
}
wrapper = stream->wrapper;
} else {
convert_to_string_ex(zstream);
wrapper = php_stream_locate_url_wrapper(Z_STRVAL_PP(zstream), NULL, 0 TSRMLS_CC);
}
if (!wrapper) {
RETURN_FALSE;
}
RETURN_BOOL(wrapper->is_url==0);
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,269 | PHP_FUNCTION(stream_supports_lock)
{
php_stream *stream;
zval *zsrc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsrc) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zsrc);
if (!php_stream_supports_lock(stream)) {
RETURN_FALSE;
}
RETURN_TRUE;
}
| Bypass | 0 | PHP_FUNCTION(stream_supports_lock)
{
php_stream *stream;
zval *zsrc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsrc) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zsrc);
if (!php_stream_supports_lock(stream)) {
RETURN_FALSE;
}
RETURN_TRUE;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,270 | static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS)
{
zval *zstream;
php_stream *stream;
char *filtername;
int filternamelen;
long read_write = 0;
zval *filterparams = NULL;
php_stream_filter *filter = NULL;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|lz", &zstream,
&filtername, &filternamelen, &read_write, &filterparams) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if ((read_write & PHP_STREAM_FILTER_ALL) == 0) {
/* Chain not specified.
* Examine stream->mode to determine which filters are needed
* There's no harm in attaching a filter to an unused chain,
* but why waste the memory and clock cycles?
*/
if (strchr(stream->mode, 'r') || strchr(stream->mode, '+')) {
read_write |= PHP_STREAM_FILTER_READ;
}
if (strchr(stream->mode, 'w') || strchr(stream->mode, '+') || strchr(stream->mode, 'a')) {
read_write |= PHP_STREAM_FILTER_WRITE;
}
}
if (read_write & PHP_STREAM_FILTER_READ) {
filter = php_stream_filter_create(filtername, filterparams, php_stream_is_persistent(stream) TSRMLS_CC);
if (filter == NULL) {
RETURN_FALSE;
}
if (append) {
ret = php_stream_filter_append_ex(&stream->readfilters, filter TSRMLS_CC);
} else {
ret = php_stream_filter_prepend_ex(&stream->readfilters, filter TSRMLS_CC);
}
if (ret != SUCCESS) {
php_stream_filter_remove(filter, 1 TSRMLS_CC);
RETURN_FALSE;
}
}
if (read_write & PHP_STREAM_FILTER_WRITE) {
filter = php_stream_filter_create(filtername, filterparams, php_stream_is_persistent(stream) TSRMLS_CC);
if (filter == NULL) {
RETURN_FALSE;
}
if (append) {
ret = php_stream_filter_append_ex(&stream->writefilters, filter TSRMLS_CC);
} else {
ret = php_stream_filter_prepend_ex(&stream->writefilters, filter TSRMLS_CC);
}
if (ret != SUCCESS) {
php_stream_filter_remove(filter, 1 TSRMLS_CC);
RETURN_FALSE;
}
}
if (filter) {
RETURN_RESOURCE(filter->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, filter, php_file_le_stream_filter()));
} else {
RETURN_FALSE;
}
}
| Bypass | 0 | static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS)
{
zval *zstream;
php_stream *stream;
char *filtername;
int filternamelen;
long read_write = 0;
zval *filterparams = NULL;
php_stream_filter *filter = NULL;
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|lz", &zstream,
&filtername, &filternamelen, &read_write, &filterparams) == FAILURE) {
RETURN_FALSE;
}
php_stream_from_zval(stream, &zstream);
if ((read_write & PHP_STREAM_FILTER_ALL) == 0) {
/* Chain not specified.
* Examine stream->mode to determine which filters are needed
* There's no harm in attaching a filter to an unused chain,
* but why waste the memory and clock cycles?
*/
if (strchr(stream->mode, 'r') || strchr(stream->mode, '+')) {
read_write |= PHP_STREAM_FILTER_READ;
}
if (strchr(stream->mode, 'w') || strchr(stream->mode, '+') || strchr(stream->mode, 'a')) {
read_write |= PHP_STREAM_FILTER_WRITE;
}
}
if (read_write & PHP_STREAM_FILTER_READ) {
filter = php_stream_filter_create(filtername, filterparams, php_stream_is_persistent(stream) TSRMLS_CC);
if (filter == NULL) {
RETURN_FALSE;
}
if (append) {
ret = php_stream_filter_append_ex(&stream->readfilters, filter TSRMLS_CC);
} else {
ret = php_stream_filter_prepend_ex(&stream->readfilters, filter TSRMLS_CC);
}
if (ret != SUCCESS) {
php_stream_filter_remove(filter, 1 TSRMLS_CC);
RETURN_FALSE;
}
}
if (read_write & PHP_STREAM_FILTER_WRITE) {
filter = php_stream_filter_create(filtername, filterparams, php_stream_is_persistent(stream) TSRMLS_CC);
if (filter == NULL) {
RETURN_FALSE;
}
if (append) {
ret = php_stream_filter_append_ex(&stream->writefilters, filter TSRMLS_CC);
} else {
ret = php_stream_filter_prepend_ex(&stream->writefilters, filter TSRMLS_CC);
}
if (ret != SUCCESS) {
php_stream_filter_remove(filter, 1 TSRMLS_CC);
RETURN_FALSE;
}
}
if (filter) {
RETURN_RESOURCE(filter->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, filter, php_file_le_stream_filter()));
} else {
RETURN_FALSE;
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,271 | static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC)
{
php_stream_context *context = NULL;
context = zend_fetch_resource(&contextresource TSRMLS_CC, -1, NULL, NULL, 1, php_le_stream_context(TSRMLS_C));
if (context == NULL) {
php_stream *stream;
stream = zend_fetch_resource(&contextresource TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream);
if (stream) {
context = stream->context;
if (context == NULL) {
/* Only way this happens is if file is opened with NO_DEFAULT_CONTEXT
param, but then something is called which requires a context.
Don't give them the default one though since they already said they
didn't want it. */
context = stream->context = php_stream_context_alloc(TSRMLS_C);
}
}
}
return context;
}
| Bypass | 0 | static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC)
{
php_stream_context *context = NULL;
context = zend_fetch_resource(&contextresource TSRMLS_CC, -1, NULL, NULL, 1, php_le_stream_context(TSRMLS_C));
if (context == NULL) {
php_stream *stream;
stream = zend_fetch_resource(&contextresource TSRMLS_CC, -1, NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream);
if (stream) {
context = stream->context;
if (context == NULL) {
/* Only way this happens is if file is opened with NO_DEFAULT_CONTEXT
param, but then something is called which requires a context.
Don't give them the default one though since they already said they
didn't want it. */
context = stream->context = php_stream_context_alloc(TSRMLS_C);
}
}
}
return context;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,272 | static int parse_context_options(php_stream_context *context, zval *options TSRMLS_DC)
{
HashPosition pos, opos;
zval **wval, **oval;
char *wkey, *okey;
uint wkey_len, okey_len;
int ret = SUCCESS;
ulong num_key;
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(options), &pos);
while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(options), (void**)&wval, &pos)) {
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &wkey_len, &num_key, 0, &pos)
&& Z_TYPE_PP(wval) == IS_ARRAY) {
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(wval), &opos);
while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(wval), (void**)&oval, &opos)) {
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), &okey, &okey_len, &num_key, 0, &opos)) {
php_stream_context_set_option(context, wkey, okey, *oval);
}
zend_hash_move_forward_ex(Z_ARRVAL_PP(wval), &opos);
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value");
}
zend_hash_move_forward_ex(Z_ARRVAL_P(options), &pos);
}
return ret;
}
| Bypass | 0 | static int parse_context_options(php_stream_context *context, zval *options TSRMLS_DC)
{
HashPosition pos, opos;
zval **wval, **oval;
char *wkey, *okey;
uint wkey_len, okey_len;
int ret = SUCCESS;
ulong num_key;
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(options), &pos);
while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(options), (void**)&wval, &pos)) {
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &wkey_len, &num_key, 0, &pos)
&& Z_TYPE_PP(wval) == IS_ARRAY) {
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(wval), &opos);
while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(wval), (void**)&oval, &opos)) {
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), &okey, &okey_len, &num_key, 0, &opos)) {
php_stream_context_set_option(context, wkey, okey, *oval);
}
zend_hash_move_forward_ex(Z_ARRVAL_PP(wval), &opos);
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value");
}
zend_hash_move_forward_ex(Z_ARRVAL_P(options), &pos);
}
return ret;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,273 | static int parse_context_params(php_stream_context *context, zval *params TSRMLS_DC)
{
int ret = SUCCESS;
zval **tmp;
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "notification", sizeof("notification"), (void**)&tmp)) {
if (context->notifier) {
php_stream_notification_free(context->notifier);
context->notifier = NULL;
}
context->notifier = php_stream_notification_alloc();
context->notifier->func = user_space_stream_notifier;
context->notifier->ptr = *tmp;
Z_ADDREF_P(*tmp);
context->notifier->dtor = user_space_stream_notifier_dtor;
}
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) {
if (Z_TYPE_PP(tmp) == IS_ARRAY) {
parse_context_options(context, *tmp TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
}
}
return ret;
}
| Bypass | 0 | static int parse_context_params(php_stream_context *context, zval *params TSRMLS_DC)
{
int ret = SUCCESS;
zval **tmp;
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "notification", sizeof("notification"), (void**)&tmp)) {
if (context->notifier) {
php_stream_notification_free(context->notifier);
context->notifier = NULL;
}
context->notifier = php_stream_notification_alloc();
context->notifier->func = user_space_stream_notifier;
context->notifier->ptr = *tmp;
Z_ADDREF_P(*tmp);
context->notifier->dtor = user_space_stream_notifier_dtor;
}
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) {
if (Z_TYPE_PP(tmp) == IS_ARRAY) {
parse_context_options(context, *tmp TSRMLS_CC);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
}
}
return ret;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,274 | static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
{
zval **elem, **dest_elem;
php_stream *stream;
HashTable *new_hash;
int ret = 0;
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
}
ALLOC_HASHTABLE(new_hash);
zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
zend_hash_has_more_elements(Z_ARRVAL_P(stream_array)) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
int type;
char *key;
uint key_len;
ulong num_ind;
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
int tmp_fd;
type = zend_hash_get_current_key_ex(Z_ARRVAL_P(stream_array),
&key, &key_len, &num_ind, 0, NULL);
if (type == HASH_KEY_NON_EXISTANT ||
zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == FAILURE) {
continue; /* should not happen */
}
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
}
/* get the fd
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
* when casting. It is only used here so that the buffered data warning
* is not displayed.
*/
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && tmp_fd != -1) {
php_socket_t this_fd = (php_socket_t)tmp_fd;
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
if (type == HASH_KEY_IS_LONG) {
zend_hash_index_update(new_hash, num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);
} else { /* HASH_KEY_IS_STRING */
zend_hash_update(new_hash, key, key_len, (void *)elem, sizeof(zval *), (void **)&dest_elem);
}
if (dest_elem) {
zval_add_ref(dest_elem);
}
ret++;
continue;
}
}
}
/* destroy old array and add new one */
zend_hash_destroy(Z_ARRVAL_P(stream_array));
efree(Z_ARRVAL_P(stream_array));
zend_hash_internal_pointer_reset(new_hash);
Z_ARRVAL_P(stream_array) = new_hash;
return ret;
}
| Bypass | 0 | static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
{
zval **elem, **dest_elem;
php_stream *stream;
HashTable *new_hash;
int ret = 0;
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
}
ALLOC_HASHTABLE(new_hash);
zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
zend_hash_has_more_elements(Z_ARRVAL_P(stream_array)) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
int type;
char *key;
uint key_len;
ulong num_ind;
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
int tmp_fd;
type = zend_hash_get_current_key_ex(Z_ARRVAL_P(stream_array),
&key, &key_len, &num_ind, 0, NULL);
if (type == HASH_KEY_NON_EXISTANT ||
zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == FAILURE) {
continue; /* should not happen */
}
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
}
/* get the fd
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
* when casting. It is only used here so that the buffered data warning
* is not displayed.
*/
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && tmp_fd != -1) {
php_socket_t this_fd = (php_socket_t)tmp_fd;
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
if (type == HASH_KEY_IS_LONG) {
zend_hash_index_update(new_hash, num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);
} else { /* HASH_KEY_IS_STRING */
zend_hash_update(new_hash, key, key_len, (void *)elem, sizeof(zval *), (void **)&dest_elem);
}
if (dest_elem) {
zval_add_ref(dest_elem);
}
ret++;
continue;
}
}
}
/* destroy old array and add new one */
zend_hash_destroy(Z_ARRVAL_P(stream_array));
efree(Z_ARRVAL_P(stream_array));
zend_hash_internal_pointer_reset(new_hash);
Z_ARRVAL_P(stream_array) = new_hash;
return ret;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,275 | static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t *max_fd TSRMLS_DC)
{
zval **elem;
php_stream *stream;
int cnt = 0;
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
}
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
int tmp_fd;
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
}
/* get the fd.
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
* when casting. It is only used here so that the buffered data warning
* is not displayed.
* */
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && tmp_fd != -1) {
php_socket_t this_fd = (php_socket_t)tmp_fd;
PHP_SAFE_FD_SET(this_fd, fds);
if (this_fd > *max_fd) {
*max_fd = this_fd;
}
cnt++;
}
}
return cnt ? 1 : 0;
}
| Bypass | 0 | static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t *max_fd TSRMLS_DC)
{
zval **elem;
php_stream *stream;
int cnt = 0;
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
}
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
int tmp_fd;
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
}
/* get the fd.
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
* when casting. It is only used here so that the buffered data warning
* is not displayed.
* */
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && tmp_fd != -1) {
php_socket_t this_fd = (php_socket_t)tmp_fd;
PHP_SAFE_FD_SET(this_fd, fds);
if (this_fd > *max_fd) {
*max_fd = this_fd;
}
cnt++;
}
}
return cnt ? 1 : 0;
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,276 | static void user_space_stream_notifier(php_stream_context *context, int notifycode, int severity,
char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC)
{
zval *callback = (zval*)context->notifier->ptr;
zval *retval = NULL;
zval zvs[6];
zval *ps[6];
zval **ptps[6];
int i;
for (i = 0; i < 6; i++) {
INIT_ZVAL(zvs[i]);
ps[i] = &zvs[i];
ptps[i] = &ps[i];
MAKE_STD_ZVAL(ps[i]);
}
ZVAL_LONG(ps[0], notifycode);
ZVAL_LONG(ps[1], severity);
if (xmsg) {
ZVAL_STRING(ps[2], xmsg, 1);
} else {
ZVAL_NULL(ps[2]);
}
ZVAL_LONG(ps[3], xcode);
ZVAL_LONG(ps[4], bytes_sofar);
ZVAL_LONG(ps[5], bytes_max);
if (FAILURE == call_user_function_ex(EG(function_table), NULL, callback, &retval, 6, ptps, 0, NULL TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to call user notifier");
}
for (i = 0; i < 6; i++) {
zval_ptr_dtor(&ps[i]);
}
if (retval) {
zval_ptr_dtor(&retval);
}
}
| Bypass | 0 | static void user_space_stream_notifier(php_stream_context *context, int notifycode, int severity,
char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC)
{
zval *callback = (zval*)context->notifier->ptr;
zval *retval = NULL;
zval zvs[6];
zval *ps[6];
zval **ptps[6];
int i;
for (i = 0; i < 6; i++) {
INIT_ZVAL(zvs[i]);
ps[i] = &zvs[i];
ptps[i] = &ps[i];
MAKE_STD_ZVAL(ps[i]);
}
ZVAL_LONG(ps[0], notifycode);
ZVAL_LONG(ps[1], severity);
if (xmsg) {
ZVAL_STRING(ps[2], xmsg, 1);
} else {
ZVAL_NULL(ps[2]);
}
ZVAL_LONG(ps[3], xcode);
ZVAL_LONG(ps[4], bytes_sofar);
ZVAL_LONG(ps[5], bytes_max);
if (FAILURE == call_user_function_ex(EG(function_table), NULL, callback, &retval, 6, ptps, 0, NULL TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to call user notifier");
}
for (i = 0; i < 6; i++) {
zval_ptr_dtor(&ps[i]);
}
if (retval) {
zval_ptr_dtor(&retval);
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,277 | static void user_space_stream_notifier_dtor(php_stream_notifier *notifier)
{
if (notifier && notifier->ptr) {
zval_ptr_dtor((zval **)&(notifier->ptr));
notifier->ptr = NULL;
}
}
| Bypass | 0 | static void user_space_stream_notifier_dtor(php_stream_notifier *notifier)
{
if (notifier && notifier->ptr) {
zval_ptr_dtor((zval **)&(notifier->ptr));
notifier->ptr = NULL;
}
}
| @@ -1549,7 +1549,7 @@ PHP_FUNCTION(stream_resolve_include_path)
char *filename, *resolved_path;
int filename_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,278 | static PHP_FUNCTION(xmlwriter_set_indent)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
int retval;
zend_bool indent;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &indent) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &pind, &indent) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterSetIndent(ptr, indent);
if (retval == 0) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_set_indent)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
int retval;
zend_bool indent;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &indent) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &pind, &indent) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterSetIndent(ptr, indent);
if (retval == 0) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,279 | static PHP_FUNCTION(xmlwriter_set_indent_string)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterSetIndentString, NULL);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_set_indent_string)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterSetIndentString, NULL);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,280 | static PHP_FUNCTION(xmlwriter_end_attribute)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndAttribute);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_end_attribute)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndAttribute);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,281 | static PHP_FUNCTION(xmlwriter_start_attribute_ns)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *prefix, *uri;
int name_len, prefix_len, uri_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss!",
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss!", &pind,
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Attribute Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterStartAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_start_attribute_ns)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *prefix, *uri;
int name_len, prefix_len, uri_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss!",
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss!", &pind,
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Attribute Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterStartAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,282 | static PHP_FUNCTION(xmlwriter_write_attribute)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *content;
int name_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind,
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Attribute Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWriteAttribute(ptr, (xmlChar *)name, (xmlChar *)content);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_attribute)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *content;
int name_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind,
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Attribute Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWriteAttribute(ptr, (xmlChar *)name, (xmlChar *)content);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,283 | static PHP_FUNCTION(xmlwriter_write_attribute_ns)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *prefix, *uri, *content;
int name_len, prefix_len, uri_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss!s",
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss!s", &pind,
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Attribute Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWriteAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_attribute_ns)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *prefix, *uri, *content;
int name_len, prefix_len, uri_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss!s",
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss!s", &pind,
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Attribute Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWriteAttributeNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)content);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,284 | static PHP_FUNCTION(xmlwriter_start_element)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartElement, "Invalid Element Name");
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_start_element)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterStartElement, "Invalid Element Name");
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,285 | static PHP_FUNCTION(xmlwriter_start_element_ns)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *prefix, *uri;
int name_len, prefix_len, uri_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss!",
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!ss!", &pind,
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Element Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterStartElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_start_element_ns)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *prefix, *uri;
int name_len, prefix_len, uri_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss!",
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!ss!", &pind,
&prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Element Name");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterStartElementNS(ptr, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,286 | static PHP_FUNCTION(xmlwriter_end_element)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndElement);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_end_element)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndElement);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,287 | static PHP_FUNCTION(xmlwriter_full_end_element)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterFullEndElement);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_full_end_element)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterFullEndElement);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,288 | static PHP_FUNCTION(xmlwriter_write_element)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *content = NULL;
int name_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!",
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!", &pind,
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Element Name");
ptr = intern->ptr;
if (ptr) {
if (!content) {
retval = xmlTextWriterStartElement(ptr, (xmlChar *)name);
if (retval == -1) {
RETURN_FALSE;
}
xmlTextWriterEndElement(ptr);
if (retval == -1) {
RETURN_FALSE;
}
} else {
retval = xmlTextWriterWriteElement(ptr, (xmlChar *)name, (xmlChar *)content);
}
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_element)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *content = NULL;
int name_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!",
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!", &pind,
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid Element Name");
ptr = intern->ptr;
if (ptr) {
if (!content) {
retval = xmlTextWriterStartElement(ptr, (xmlChar *)name);
if (retval == -1) {
RETURN_FALSE;
}
xmlTextWriterEndElement(ptr);
if (retval == -1) {
RETURN_FALSE;
}
} else {
retval = xmlTextWriterWriteElement(ptr, (xmlChar *)name, (xmlChar *)content);
}
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,289 | static PHP_FUNCTION(xmlwriter_write_pi)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *content;
int name_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind,
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid PI Target");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWritePI(ptr, (xmlChar *)name, (xmlChar *)content);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_pi)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *content;
int name_len, content_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind,
&name, &name_len, &content, &content_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
XMLW_NAME_CHK("Invalid PI Target");
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWritePI(ptr, (xmlChar *)name, (xmlChar *)content);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,290 | static PHP_FUNCTION(xmlwriter_end_cdata)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndCDATA);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_end_cdata)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndCDATA);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,291 | static PHP_FUNCTION(xmlwriter_write_cdata)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteCDATA, NULL);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_cdata)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteCDATA, NULL);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,292 | static PHP_FUNCTION(xmlwriter_write_raw)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteRaw, NULL);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_raw)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteRaw, NULL);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,293 | static PHP_FUNCTION(xmlwriter_text)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteString, NULL);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_text)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteString, NULL);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,294 | static PHP_FUNCTION(xmlwriter_start_comment)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
int retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterStartComment(ptr);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_start_comment)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
int retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pind) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterStartComment(ptr);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,295 | static PHP_FUNCTION(xmlwriter_end_comment)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndComment);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_end_comment)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndComment);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,296 | static PHP_FUNCTION(xmlwriter_write_comment)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteComment, NULL);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_comment)
{
php_xmlwriter_string_arg(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterWriteComment, NULL);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,297 | static PHP_FUNCTION(xmlwriter_end_document)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDocument);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_end_document)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDocument);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,298 | static PHP_FUNCTION(xmlwriter_end_dtd)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTD);
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_end_dtd)
{
php_xmlwriter_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, xmlTextWriterEndDTD);
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
12,299 | static PHP_FUNCTION(xmlwriter_write_dtd)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *pubid = NULL, *sysid = NULL, *subset = NULL;
int name_len, pubid_len, sysid_len, subset_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!s!s!", &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len, &subset, &subset_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!s!s!", &pind, &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len, &subset, &subset_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWriteDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)subset);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| Bypass | 0 | static PHP_FUNCTION(xmlwriter_write_dtd)
{
zval *pind;
xmlwriter_object *intern;
xmlTextWriterPtr ptr;
char *name, *pubid = NULL, *sysid = NULL, *subset = NULL;
int name_len, pubid_len, sysid_len, subset_len, retval;
#ifdef ZEND_ENGINE_2
zval *this = getThis();
if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!s!s!", &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len, &subset, &subset_len) == FAILURE) {
return;
}
XMLWRITER_FROM_OBJECT(intern, this);
} else
#endif
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!s!s!", &pind, &name, &name_len, &pubid, &pubid_len, &sysid, &sysid_len, &subset, &subset_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(intern,xmlwriter_object *, &pind, -1, "XMLWriter", le_xmlwriter);
}
ptr = intern->ptr;
if (ptr) {
retval = xmlTextWriterWriteDTD(ptr, (xmlChar *)name, (xmlChar *)pubid, (xmlChar *)sysid, (xmlChar *)subset);
if (retval != -1) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
| @@ -1738,7 +1738,7 @@ static PHP_FUNCTION(xmlwriter_write_dtd_entity)
/* }}} */
#endif
-/* {{{ proto resource xmlwriter_open_uri(resource xmlwriter, string source)
+/* {{{ proto resource xmlwriter_open_uri(string source)
Create new xmlwriter using source uri for output */
static PHP_FUNCTION(xmlwriter_open_uri)
{
@@ -1759,7 +1759,7 @@ static PHP_FUNCTION(xmlwriter_open_uri)
void *ioctx;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &source, &source_len) == FAILURE) {
return;
} | CWE-254 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.