Skip to content

Commit 2cc4e69

Browse files
committed
Fixed Bug #69667 segfault in php_pgsql_meta_data
Incomplete fix for #68741
1 parent 58e5e00 commit 2cc4e69

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

ext/pgsql/pg_insert_002.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
PostgreSQL pg_select() - basic test using schema
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
8+
include('config.inc');
9+
10+
$conn = pg_connect($conn_str);
11+
12+
foreach (array('', '.', '..') as $table) {
13+
var_dump(pg_insert($conn, '', array('id' => 1, 'id2' => 1)));
14+
}
15+
?>
16+
Done
17+
--EXPECTF--
18+
19+
Warning: pg_insert(): The table name must be specified in %s on line %d
20+
bool(false)
21+
22+
Warning: pg_insert(): The table name must be specified in %s on line %d
23+
bool(false)
24+
25+
Warning: pg_insert(): The table name must be specified in %s on line %d
26+
bool(false)
27+
Done

ext/pgsql/pgsql.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,7 +5120,11 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
51205120

51215121
src = estrdup(table_name);
51225122
tmp_name = php_strtok_r(src, ".", &tmp_name2);
5123-
5123+
if (!tmp_name) {
5124+
efree(src);
5125+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified");
5126+
return FAILURE;
5127+
}
51245128
if (!tmp_name2 || !*tmp_name2) {
51255129
/* Default schema */
51265130
tmp_name2 = tmp_name;
@@ -6130,7 +6134,8 @@ static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, ulong opt T
61306134

61316135
static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const char *table)
61326136
{
6133-
char *table_copy, *escaped, *token, *tmp;
6137+
char *table_copy, *escaped, *tmp;
6138+
const char *token;
61346139
size_t len;
61356140

61366141
/* schame.table should be "schame"."table" */

0 commit comments

Comments
 (0)