Skip to content

Commit e327070

Browse files
committed
Review
Also realized this doesn't test the value error code path in build_assignment_string() because the same error condition seems to fail early
1 parent ae1001a commit e327070

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

ext/pgsql/pgsql.c

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,28 +2321,28 @@ PHP_FUNCTION(pg_lo_create)
23212321

23222322
if (oid) {
23232323
switch (Z_TYPE_P(oid)) {
2324-
case IS_STRING:
2325-
{
2326-
/* TODO: Use zend_is_numeric_string/subroutine? */
2327-
char *end_ptr;
2328-
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10);
2329-
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) {
2330-
/* wrong integer format */
2331-
zend_value_error("Invalid OID value passed");
2332-
RETURN_THROWS();
2324+
case IS_STRING:
2325+
{
2326+
/* TODO: Use subroutine? */
2327+
char *end_ptr;
2328+
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10);
2329+
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) {
2330+
/* wrong integer format */
2331+
zend_value_error("Invalid OID value passed");
2332+
RETURN_THROWS();
2333+
}
23332334
}
2334-
}
2335-
break;
2336-
case IS_LONG:
2337-
if (Z_LVAL_P(oid) < (zend_long)InvalidOid) {
2338-
zend_value_error("Invalid OID value passed");
2335+
break;
2336+
case IS_LONG:
2337+
if (Z_LVAL_P(oid) < (zend_long)InvalidOid) {
2338+
zend_value_error("Invalid OID value passed");
2339+
RETURN_THROWS();
2340+
}
2341+
wanted_oid = (Oid)Z_LVAL_P(oid);
2342+
break;
2343+
default:
2344+
zend_type_error("OID value must be of type string|int, %s given", zend_zval_type_name(oid));
23392345
RETURN_THROWS();
2340-
}
2341-
wanted_oid = (Oid)Z_LVAL_P(oid);
2342-
break;
2343-
default:
2344-
zend_type_error("OID value must be of type string|int, %s given", zend_zval_type_name(oid));
2345-
RETURN_THROWS();
23462346
}
23472347
if ((pgsql_oid = lo_create(pgsql, wanted_oid)) == InvalidOid) {
23482348
php_error_docref(NULL, E_WARNING, "Unable to create PostgreSQL large object");
@@ -2376,7 +2376,7 @@ PHP_FUNCTION(pg_lo_unlink)
23762376
/* accept string type since Oid type is unsigned int */
23772377
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc,
23782378
"rs", &pgsql_link, &oid_string, &oid_strlen) == SUCCESS) {
2379-
/* TODO: Use zend_is_numeric_string/subroutine? */
2379+
/* TODO: Use subroutine? */
23802380
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
23812381
if ((oid_string+oid_strlen) != end_ptr) {
23822382
/* wrong integer format */
@@ -2396,7 +2396,7 @@ PHP_FUNCTION(pg_lo_unlink)
23962396
}
23972397
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc,
23982398
"s", &oid_string, &oid_strlen) == SUCCESS) {
2399-
/* TODO: Use zend_is_numeric_string/subroutine? */
2399+
/* TODO: subroutine? */
24002400
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
24012401
if ((oid_string+oid_strlen) != end_ptr) {
24022402
/* wrong integer format */
@@ -2451,7 +2451,7 @@ PHP_FUNCTION(pg_lo_open)
24512451
/* accept string type since Oid is unsigned int */
24522452
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc,
24532453
"rss", &pgsql_link, &oid_string, &oid_strlen, &mode_string, &mode_strlen) == SUCCESS) {
2454-
/* TODO: Use zend_is_numeric_string/subroutine? */
2454+
/* TODO: Use subroutine? */
24552455
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
24562456
if ((oid_string+oid_strlen) != end_ptr) {
24572457
/* wrong integer format */
@@ -2471,7 +2471,7 @@ PHP_FUNCTION(pg_lo_open)
24712471
}
24722472
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc,
24732473
"ss", &oid_string, &oid_strlen, &mode_string, &mode_strlen) == SUCCESS) {
2474-
/* TODO: Use zend_is_numeric_string/subroutine? */
2474+
/* TODO: Use subroutine? */
24752475
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
24762476
if ((oid_string+oid_strlen) != end_ptr) {
24772477
/* wrong integer format */
@@ -2531,7 +2531,6 @@ PHP_FUNCTION(pg_lo_open)
25312531
if ((pgsql_lofd = lo_open(pgsql, oid, pgsql_mode)) == -1) {
25322532
if (lo_unlink(pgsql, oid) == -1) {
25332533
efree(pgsql_lofp);
2534-
/* TODO: Throw error? */
25352534
php_error_docref(NULL, E_WARNING, "Something is really messed up! Your database is badly corrupted in a way NOT related to PHP");
25362535
RETURN_FALSE;
25372536
}
@@ -2722,28 +2721,28 @@ PHP_FUNCTION(pg_lo_import)
27222721
if (oid) {
27232722
Oid wanted_oid;
27242723
switch (Z_TYPE_P(oid)) {
2725-
case IS_STRING:
2726-
{
2727-
/* TODO: Use zend_is_numeric_string/subroutine? */
2728-
char *end_ptr;
2729-
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10);
2730-
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) {
2731-
/* wrong integer format */
2732-
zend_value_error("Invalid OID value passed");
2733-
RETURN_THROWS();
2724+
case IS_STRING:
2725+
{
2726+
/* TODO: Use subroutine? */
2727+
char *end_ptr;
2728+
wanted_oid = (Oid)strtoul(Z_STRVAL_P(oid), &end_ptr, 10);
2729+
if ((Z_STRVAL_P(oid)+Z_STRLEN_P(oid)) != end_ptr) {
2730+
/* wrong integer format */
2731+
zend_value_error("Invalid OID value passed");
2732+
RETURN_THROWS();
2733+
}
27342734
}
2735-
}
2736-
break;
2737-
case IS_LONG:
2738-
if (Z_LVAL_P(oid) < (zend_long)InvalidOid) {
2739-
zend_value_error("Invalid OID value passed");
2735+
break;
2736+
case IS_LONG:
2737+
if (Z_LVAL_P(oid) < (zend_long)InvalidOid) {
2738+
zend_value_error("Invalid OID value passed");
2739+
RETURN_THROWS();
2740+
}
2741+
wanted_oid = (Oid)Z_LVAL_P(oid);
2742+
break;
2743+
default:
2744+
zend_type_error("OID value must be of type string|int, %s given", zend_zval_type_name(oid));
27402745
RETURN_THROWS();
2741-
}
2742-
wanted_oid = (Oid)Z_LVAL_P(oid);
2743-
break;
2744-
default:
2745-
zend_type_error("OID value must be of type string|int, %s given", zend_zval_type_name(oid));
2746-
RETURN_THROWS();
27472746
}
27482747

27492748
returned_oid = lo_import_with_oid(pgsql, file_in, wanted_oid);
@@ -2789,7 +2788,7 @@ PHP_FUNCTION(pg_lo_export)
27892788
}
27902789
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc,
27912790
"rsp", &pgsql_link, &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) {
2792-
/* TODO: Use zend_is_numeric_string/subroutine? */
2791+
/* TODO: Use subroutine? */
27932792
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
27942793
if ((oid_string+oid_strlen) != end_ptr) {
27952794
/* wrong integer format */
@@ -2810,7 +2809,7 @@ PHP_FUNCTION(pg_lo_export)
28102809
}
28112810
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc,
28122811
"sp", &oid_string, &oid_strlen, &file_out, &name_len) == SUCCESS) {
2813-
/* TODO: Use zend_is_numeric_string/subroutine? */
2812+
/* TODO: Use subroutine? */
28142813
oid = (Oid)strtoul(oid_string, &end_ptr, 10);
28152814
if ((oid_string+oid_strlen) != end_ptr) {
28162815
/* wrong integer format */
@@ -5373,7 +5372,7 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var
53735372

53745373
ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) {
53755374
if (fld == NULL) {
5376-
zend_value_error("Array of values must be an associative array of string keys");
5375+
zend_value_error("Array of values must be an associative array with string keys");
53775376
goto cleanup;
53785377
}
53795378
if (opt & PGSQL_DML_ESCAPE) {
@@ -5546,7 +5545,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
55465545

55475546
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, fld, val) {
55485547
if (fld == NULL) {
5549-
zend_value_error("Array of values must be an associated array of string keys");
5548+
zend_value_error("Array of values must be an associative array with string keys");
55505549
return -1;
55515550
}
55525551
if (opt & PGSQL_DML_ESCAPE) {

0 commit comments

Comments
 (0)