This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_0_313 in repository libpostgresql-jdbc-java.
commit 8ad9c49deb271508e8b003cc23ed57ed6b46a440 Author: Kris Jurka <[email protected]> Date: Thu Sep 29 22:12:16 2005 +0000 Add checks to prevent ResultSet.updateXXX methods from throwing an ArrayIndexOutOfBoundsException. We should only throw SQLExceptions from here. --- org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 34 +++++++--------------- .../test/jdbc2/UpdateableResultTest.java | 22 +++++++++++++- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java index 8bc379d..8aba6d6 100644 --- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java +++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java @@ -3,7 +3,7 @@ * Copyright (c) 2003-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.71.2.3 2005/05/08 23:52:00 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.71.2.4 2005/06/08 01:48:14 oliver Exp $ * *------------------------------------------------------------------------- */ @@ -1034,8 +1034,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateBoolean(int columnIndex, boolean x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating boolean " + fields[columnIndex - 1].getColumnName(connection) + "=" + x); updateValue(columnIndex, new Boolean(x)); } @@ -1100,8 +1098,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateDouble(int columnIndex, double x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating double " + fields[columnIndex - 1].getColumnName(connection) + "=" + x); updateValue(columnIndex, new Double(x)); } @@ -1109,8 +1105,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateFloat(int columnIndex, float x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating float " + fields[columnIndex - 1].getColumnName(connection) + "=" + x); updateValue(columnIndex, new Float(x)); } @@ -1118,8 +1112,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateInt(int columnIndex, int x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating int " + fields[columnIndex - 1].getColumnName(connection) + "=" + x); updateValue(columnIndex, new Integer(x)); } @@ -1127,8 +1119,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateLong(int columnIndex, long x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating long " + fields[columnIndex - 1].getColumnName(connection) + "=" + x); updateValue(columnIndex, new Long(x)); } @@ -1136,6 +1126,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateNull(int columnIndex) throws SQLException { + checkColumnIndex(columnIndex); String columnTypeName = connection.getPGType(fields[columnIndex - 1].getOID()); updateValue(columnIndex, new NullObject(columnTypeName)); } @@ -1144,8 +1135,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateObject(int columnIndex, Object x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating object " + fields[columnIndex - 1].getColumnName(connection) + " = " + x); updateValue(columnIndex, x); } @@ -1336,8 +1325,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateShort(int columnIndex, short x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("in update Short " + fields[columnIndex - 1].getColumnName(connection) + " = " + x); updateValue(columnIndex, new Short(x)); } @@ -1345,8 +1332,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateString(int columnIndex, String x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("in update String " + fields[columnIndex - 1].getColumnName(connection) + " = " + x); updateValue(columnIndex, x); } @@ -1354,8 +1339,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateTime(int columnIndex, Time x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("in update Time " + fields[columnIndex - 1].getColumnName(connection) + " = " + x); updateValue(columnIndex, x); } @@ -1363,8 +1346,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg public synchronized void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - if ( Driver.logDebug ) - Driver.debug("updating Timestamp " + fields[columnIndex - 1].getColumnName(connection) + " = " + x); updateValue(columnIndex, x); } @@ -2457,14 +2438,18 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg throw new PSQLException(GT.tr("This ResultSet is closed."), PSQLState.CONNECTION_DOES_NOT_EXIST); } + protected void checkColumnIndex(int column) throws SQLException + { + if ( column < 1 || column > fields.length ) + throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(column), new Integer(fields.length)}), PSQLState.INVALID_PARAMETER_VALUE ); + } + protected void checkResultSet( int column ) throws SQLException { checkClosed(); if ( this_row == null ) throw new PSQLException(GT.tr("ResultSet not positioned properly, perhaps you need to call next."), PSQLState.INVALID_CURSOR_STATE); - if ( column < 1 || column > fields.length ) - throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(column), new Integer(fields.length)}), PSQLState.INVALID_PARAMETER_VALUE ); } //----------------- Formatting Methods ------------------- @@ -2686,6 +2671,9 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg throw new PSQLException(GT.tr("Cannot update the ResultSet because it is either before the start or after the end of the results."), PSQLState.INVALID_CURSOR_STATE); } + + checkColumnIndex(columnIndex); + doingUpdates = !onInsertRow; if (value == null) updateNull(columnIndex); diff --git a/org/postgresql/test/jdbc2/UpdateableResultTest.java b/org/postgresql/test/jdbc2/UpdateableResultTest.java index 78f1a18..4e47a76 100644 --- a/org/postgresql/test/jdbc2/UpdateableResultTest.java +++ b/org/postgresql/test/jdbc2/UpdateableResultTest.java @@ -3,7 +3,7 @@ * Copyright (c) 2001-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v 1.19 2005/01/27 22:07:40 oliver Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v 1.19.2.1 2005/03/23 19:48:18 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -397,4 +397,24 @@ public class UpdateableResultTest extends TestCase fail("expected an exception when calling moveToInsertRow() on a read-only resultset"); } catch (SQLException e) {} } + + public void testBadColumnIndexes() throws Exception + { + Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_UPDATABLE); + ResultSet rs = st.executeQuery( "select * from updateable"); + rs.moveToInsertRow(); + try { + rs.updateInt(0,1); + fail("Should have thrown an exception on bad column index."); + } catch (SQLException sqle) { } + try { + rs.updateString(1000,"hi"); + fail("Should have thrown an exception on bad column index."); + } catch (SQLException sqle) { } + try { + rs.updateNull(1000); + fail("Should have thrown an exception on bad column index."); + } catch (SQLException sqle) { } + } } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

