Skip to content

Commit 0afaa71

Browse files
authored
backpatch changes from GHSA-r38f-c4h4-hqq2 security advisory for CVE-2022-31197 (#2607)
* backpatch changes from GHSA-r38f-c4h4-hqq2 security advisory for CVE-2022-31197 * add missing file
1 parent 7714d03 commit 0afaa71

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ kotlin.parallel.tasks.in.project=true
1414
# This is version for PgJdbc itself
1515
# Note: it should not include "-SNAPSHOT" as it is automatically added by build.gradle.kts
1616
# Release version can be generated by using -Prelease or -Prc=<int> arguments
17-
pgjdbc.version=42.3.6
17+
pgjdbc.version=42.3.7
1818

1919
# The options below configures the use of local clone (e.g. testing development versions)
2020
# You can pass un-comment it, or pass option -PlocalReleasePlugins, or -PlocalReleasePlugins=<path>

pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ public void refreshRow() throws SQLException {
14181418
if (i > 1) {
14191419
selectSQL.append(", ");
14201420
}
1421-
selectSQL.append(pgmd.getBaseColumnName(i));
1421+
Utils.escapeIdentifier(selectSQL, pgmd.getBaseColumnName(i));
14221422
}
14231423
selectSQL.append(" from ").append(onlyTable).append(tableName).append(" where ");
14241424

@@ -1428,7 +1428,8 @@ public void refreshRow() throws SQLException {
14281428
for (int i = 0; i < numKeys; i++) {
14291429

14301430
PrimaryKey primaryKey = primaryKeys.get(i);
1431-
selectSQL.append(primaryKey.name).append(" = ?");
1431+
Utils.escapeIdentifier(selectSQL, primaryKey.name);
1432+
selectSQL.append(" = ?");
14321433

14331434
if (i < numKeys - 1) {
14341435
selectSQL.append(" and ");

pgjdbc/src/test/java/org/postgresql/test/jdbc2/Jdbc2TestSuite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
ReplaceProcessingTest.class,
119119
ResultSetMetaDataTest.class,
120120
ResultSetTest.class,
121+
ResultSetRefreshTest.class,
121122
ReturningParserTest.class,
122123
SearchPathLookupTest.class,
123124
ServerCursorTest.class,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2022, PostgreSQL Global Development Group
3+
* See the LICENSE file in the project root for more information.
4+
*/
5+
6+
package org.postgresql.test.jdbc2;
7+
8+
import static org.junit.Assert.assertTrue;
9+
10+
import org.postgresql.test.TestUtil;
11+
12+
import org.junit.Test;
13+
14+
import java.sql.ResultSet;
15+
import java.sql.SQLException;
16+
import java.sql.Statement;
17+
18+
public class ResultSetRefreshTest extends BaseTest4 {
19+
@Test
20+
public void testWithDataColumnThatRequiresEscaping() throws Exception {
21+
TestUtil.dropTable(con, "refresh_row_bad_ident");
22+
TestUtil.execute(con, "CREATE TABLE refresh_row_bad_ident (id int PRIMARY KEY, \"1 FROM refresh_row_bad_ident; SELECT 2; SELECT *\" int)");
23+
TestUtil.execute(con, "INSERT INTO refresh_row_bad_ident (id) VALUES (1), (2), (3)");
24+
25+
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
26+
ResultSet rs = stmt.executeQuery("SELECT * FROM refresh_row_bad_ident");
27+
assertTrue(rs.next());
28+
try {
29+
rs.refreshRow();
30+
} catch (SQLException ex) {
31+
throw new RuntimeException("ResultSet.refreshRow() did not handle escaping data column identifiers", ex);
32+
}
33+
rs.close();
34+
stmt.close();
35+
}
36+
37+
@Test
38+
public void testWithKeyColumnThatRequiresEscaping() throws Exception {
39+
TestUtil.dropTable(con, "refresh_row_bad_ident");
40+
TestUtil.execute(con, "CREATE TABLE refresh_row_bad_ident (\"my key\" int PRIMARY KEY)");
41+
TestUtil.execute(con, "INSERT INTO refresh_row_bad_ident VALUES (1), (2), (3)");
42+
43+
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
44+
ResultSet rs = stmt.executeQuery("SELECT * FROM refresh_row_bad_ident");
45+
assertTrue(rs.next());
46+
try {
47+
rs.refreshRow();
48+
} catch (SQLException ex) {
49+
throw new RuntimeException("ResultSet.refreshRow() did not handle escaping key column identifiers", ex);
50+
}
51+
rs.close();
52+
stmt.close();
53+
}
54+
}

0 commit comments

Comments
 (0)