-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-24rp-q3w6-vc56
* SQL Injection via line comment generation for 42_2_x * fix: Add parentheses around NULL parameter values in simple query mode --------- Co-authored-by: Sehrope Sarkuni <sehrope@jackdb.com>
- Loading branch information
1 parent
91b8c2c
commit b9b3777
Showing
3 changed files
with
149 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
pgjdbc/src/test/java/org/postgresql/jdbc/ParameterInjectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2024, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.jdbc; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.postgresql.test.TestUtil; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
|
||
public class ParameterInjectionTest { | ||
@Test | ||
public void negateParameter() throws Exception { | ||
try (Connection conn = TestUtil.openDB()) { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT -?"); | ||
|
||
stmt.setInt(1, 1); | ||
try (ResultSet rs = stmt.executeQuery()) { | ||
assertTrue(rs.next()); | ||
assertEquals(1, rs.getMetaData().getColumnCount(), "number of result columns must match"); | ||
int value = rs.getInt(1); | ||
assertEquals(-1, value, "Input value 1"); | ||
} | ||
|
||
stmt.setInt(1, -1); | ||
try (ResultSet rs = stmt.executeQuery()) { | ||
assertTrue(rs.next()); | ||
assertEquals(1, rs.getMetaData().getColumnCount(), "number of result columns must match"); | ||
int value = rs.getInt(1); | ||
assertEquals(1, value, "Input value -1"); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void negateParameterWithContinuation() throws Exception { | ||
try (Connection conn = TestUtil.openDB()) { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT -?, ?"); | ||
|
||
stmt.setInt(1, 1); | ||
stmt.setString(2, "\nWHERE false --"); | ||
try (ResultSet rs = stmt.executeQuery()) { | ||
assertTrue(rs.next(), "ResultSet should contain a row"); | ||
assertEquals(2, rs.getMetaData().getColumnCount(), "rs.getMetaData().getColumnCount("); | ||
int value = rs.getInt(1); | ||
assertEquals(-1, value); | ||
} | ||
|
||
stmt.setInt(1, -1); | ||
stmt.setString(2, "\nWHERE false --"); | ||
try (ResultSet rs = stmt.executeQuery()) { | ||
assertTrue(rs.next(), "ResultSet should contain a row"); | ||
assertEquals(2, rs.getMetaData().getColumnCount(), "rs.getMetaData().getColumnCount("); | ||
int value = rs.getInt(1); | ||
assertEquals(1, value); | ||
} | ||
} | ||
} | ||
} |