Skip to content

Commit f93d24a

Browse files
committed
Fixed Bug #69667 segfault in php_pgsql_meta_data
Incomplete fix for #68741
1 parent 4ceb7b4 commit f93d24a

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
@@ -5103,7 +5103,11 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
51035103

51045104
src = estrdup(table_name);
51055105
tmp_name = php_strtok_r(src, ".", &tmp_name2);
5106-
5106+
if (!tmp_name) {
5107+
efree(src);
5108+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The table name must be specified");
5109+
return FAILURE;
5110+
}
51075111
if (!tmp_name2 || !*tmp_name2) {
51085112
/* Default schema */
51095113
tmp_name2 = tmp_name;
@@ -6111,7 +6115,8 @@ static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, ulong opt T
61116115

61126116
static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const char *table)
61136117
{
6114-
char *table_copy, *escaped, *token, *tmp;
6118+
char *table_copy, *escaped, *tmp;
6119+
const char *token;
61156120
size_t len;
61166121

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

0 commit comments

Comments
 (0)