Обсуждение: Possible bug in ServerErrorMessage.java

Поиск
Список
Период
Сортировка

Possible bug in ServerErrorMessage.java

От
Fedechicco
Дата:
Hi everbody,

I'm trying to use the postgre jdbc driver with little success.
I keep getting this incomprehensible error message:

org.postgresql.util.PSQLException: Something unusual has occured to
cause the driver to fail. Please report this exception.
    at org.postgresql.Driver.connect(Driver.java:280)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:169)
    at com.moxoff.meshrepository.SQLConnector.getConnection(SQLConnector.java:40)
    at com.moxoff.meshrepository.MeshRepository.<init>(MeshRepository.java:23)
    at com.moxoff.meshrepository.Main.main(Main.java:80)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
    at org.postgresql.util.ServerErrorMessage.<init>(ServerErrorMessage.java:48)
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:273)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:95)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:386)
    at org.postgresql.Driver.connect(Driver.java:260)
    ... 5 more

From what I've seen the line 48 and the following are:

while (l_chars[l_pos] != '\0' && l_pos < l_length)
{
         l_pos++;
}

which IMO should be changed in:
while (l_pos < l_length && l_chars[l_pos] != '\0')

cheers,
Fedechicco

Re: Possible bug in ServerErrorMessage.java

От
Dave Cramer
Дата:
Can you send a repeatable test case ?

What version of the driver are you using and what version of the server ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Thu, Apr 26, 2012 at 7:34 AM, Fedechicco <fedechicco@gmail.com> wrote:
> Hi everbody,
>
> I'm trying to use the postgre jdbc driver with little success.
> I keep getting this incomprehensible error message:
>
> org.postgresql.util.PSQLException: Something unusual has occured to
> cause the driver to fail. Please report this exception.
>        at org.postgresql.Driver.connect(Driver.java:280)
>        at java.sql.DriverManager.getConnection(DriverManager.java:620)
>        at java.sql.DriverManager.getConnection(DriverManager.java:169)
>        at com.moxoff.meshrepository.SQLConnector.getConnection(SQLConnector.java:40)
>        at com.moxoff.meshrepository.MeshRepository.<init>(MeshRepository.java:23)
>        at com.moxoff.meshrepository.Main.main(Main.java:80)
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
>        at org.postgresql.util.ServerErrorMessage.<init>(ServerErrorMessage.java:48)
>        at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:273)
>        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:95)
>        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
>        at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124)
>        at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
>        at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
>        at org.postgresql.Driver.makeConnection(Driver.java:386)
>        at org.postgresql.Driver.connect(Driver.java:260)
>        ... 5 more
>
> From what I've seen the line 48 and the following are:
>
> while (l_chars[l_pos] != '\0' && l_pos < l_length)
> {
>         l_pos++;
> }
>
> which IMO should be changed in:
> while (l_pos < l_length && l_chars[l_pos] != '\0')
>
> cheers,
> Fedechicco
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc

Re: Possible bug in ServerErrorMessage.java

От
Maciek Sakrejda
Дата:
> From what I've seen the line 48 and the following are:
>
> while (l_chars[l_pos] != '\0' && l_pos < l_length)
> {
>         l_pos++;
> }
>
> which IMO should be changed in:
> while (l_pos < l_length && l_chars[l_pos] != '\0')

This seems to be the code in question, to decode the wire ErrorResponse message:

https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/util/ServerErrorMessage.java#L32

Although what you suggested would be more defensive coding, if you
look at the message specification [1], I believe the current code
*should* process any well-formed ErrorResponse message correctly. As
Dave asked, is this consistently reproducible? Also, are you in a
position to make the change you suggested, rebuild the driver, and
retry it yourself? If so, do you get a different message?

[1]: http://www.postgresql.org/docs/9.1/static/protocol-message-formats.html
---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

Re: Possible bug in ServerErrorMessage.java

От
Fedechicco
Дата:
I used the package postgresql-9.1-902.jdbc4.jar downloaded from the
official site and the version 8.3-603 downloaded through the Ubuntu
repository.
The postgresql i'm using is the 9.1.3.

I can hardly send you a repeatable test, since it is obviously a
problem with my postgre settings (aka I probably did something wrong
while setting the database up).
Anyway, IMO, the exception thrown by that piece of code is misleading,
since an out of bound exception is thrown while building another
exception that should signal another more useful error (which would
have probably told me what was my real problem).

I don't have the permission of my boss to work in first person on the
bug fix, i just felt it was useful to report it.

I would point out anyway that the second part of this boolean
condition (l_pos < l_length) is completely useless:

while(l_chars[l_pos] != '\0' && l_pos < l_length)

since it would evaluate false when and only when an out of bound
exception has already been thrown by the first part (l_chars[l_pos] !=
'\0').

Regards,
Fedechicco

2012/4/27 Maciek Sakrejda <msakrejda@truviso.com>:
>> From what I've seen the line 48 and the following are:
>>
>> while (l_chars[l_pos] != '\0' && l_pos < l_length)
>> {
>>         l_pos++;
>> }
>>
>> which IMO should be changed in:
>> while (l_pos < l_length && l_chars[l_pos] != '\0')
>
> This seems to be the code in question, to decode the wire ErrorResponse message:
>
> https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/util/ServerErrorMessage.java#L32
>
> Although what you suggested would be more defensive coding, if you
> look at the message specification [1], I believe the current code
> *should* process any well-formed ErrorResponse message correctly. As
> Dave asked, is this consistently reproducible? Also, are you in a
> position to make the change you suggested, rebuild the driver, and
> retry it yourself? If so, do you get a different message?
>
> [1]: http://www.postgresql.org/docs/9.1/static/protocol-message-formats.html
> ---
> Maciek Sakrejda | System Architect | Truviso
>
> 1065 E. Hillsdale Blvd., Suite 215
> Foster City, CA 94404
> (650) 242-3500 Main
> www.truviso.com

Re: Possible bug in ServerErrorMessage.java

От
"ml-tb"
Дата:
Am Freitag, 27. April 2012 schrieb Maciek Sakrejda:
> > From what I've seen the line 48 and the following are:
> >
> > while (l_chars[l_pos] != '\0' && l_pos < l_length)
> > {
> >
> >         l_pos++;
> >
> > }
> >
> > which IMO should be changed in:
> > while (l_pos < l_length && l_chars[l_pos] != '\0')
>
> This seems to be the code in question, to decode the wire
> ErrorResponse message:
>
> https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/util/Serv
> erErrorMessage.java#L32
>
> Although what you suggested would be more defensive coding,
Sorry for correct you at this point: The suggested code ist not more
defensive but the only correct way for a save (unsyncronised) array
access.

Bye Thomas

Re: Possible bug in ServerErrorMessage.java

От
Maciek Sakrejda
Дата:
>> Although what you suggested would be more defensive coding,
> Sorry for correct you at this point: The suggested code ist not more
> defensive but the only correct way for a save (unsyncronised) array
> access.

...for arbitrary data, which is *not* what the message is designed to parse.
---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

Re: Possible bug in ServerErrorMessage.java

От
Maciek Sakrejda
Дата:
More constructively, I don't think that this is Fedechicco's root
problem. If we make this change (and we probably should) he'll just
see another error. I'd like to try to figure out what that is, so that
in case it's another driver issue, we can address it at the same time.
---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

Re: Possible bug in ServerErrorMessage.java

От
Dave Cramer
Дата:
On Fri, Apr 27, 2012 at 9:27 AM, Maciek Sakrejda <msakrejda@truviso.com> wrote:
> More constructively, I don't think that this is Fedechicco's root
> problem. If we make this change (and we probably should) he'll just
> see another error. I'd like to try to figure out what that is, so that
> in case it's another driver issue, we can address it at the same time.

Agreed, I was going to commit a change today

But I would like to see the root of the problem as well.


Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

Re: Possible bug in ServerErrorMessage.java

От
Fedechicco
Дата:
I frankly believe that the root problem is mine and it is not
dependant from the jdbc driver, so I don't think you guys should worry
about it.
I have no experience whatsoever with postgre, and this is probably the
root problem, i'll figure it out myself.

Thanks for the bugfix, best regards,

Fedechicco

2012/4/27 Dave Cramer <pg@fastcrypt.com>:
> On Fri, Apr 27, 2012 at 9:27 AM, Maciek Sakrejda <msakrejda@truviso.com> wrote:
>> More constructively, I don't think that this is Fedechicco's root
>> problem. If we make this change (and we probably should) he'll just
>> see another error. I'd like to try to figure out what that is, so that
>> in case it's another driver issue, we can address it at the same time.
>
> Agreed, I was going to commit a change today
>
> But I would like to see the root of the problem as well.
>
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc