Skip to content

Comments

Fix PG_ErrorInfo and ER_ReturnError when error message is larger than 65535 bytes#70

Merged
davecramer merged 1 commit intopostgresql-interfaces:mainfrom
r33s3n6:main
Nov 3, 2024
Merged

Fix PG_ErrorInfo and ER_ReturnError when error message is larger than 65535 bytes#70
davecramer merged 1 commit intopostgresql-interfaces:mainfrom
r33s3n6:main

Conversation

@r33s3n6
Copy link
Contributor

@r33s3n6 r33s3n6 commented Nov 2, 2024

Old driver truncated the server error message incorrectly.

old implementation

environ.c:147:

error->errorsize = (Int2) errsize;

When errsize is larger than 32767, the errorsize is wrong.

environ.c:204:

msglen = (SQLSMALLINT) strlen(msg);

msglen is truncated when msg is larger than 65535 bytes.

environ.c:224:

RecNumber = 2 + (error->errorpos - 1) / error->recsize;

errorpos is used but never set.

new implementaion

In PG_ErrorInfo, makes errsize, errpos UInt4.

typedef struct
{
        UInt4	status;
	UInt4	errsize;
        UInt4	errpos;
        UInt2	recsize;
        char    sqlstate[6];
        char    __error_message[44];
}       PG_ErrorInfo;

Fix ER_Construct and ER_Dup .
In ER_ReturnError, makes msglen, wrtlen, pcblen UInt4, and set errpos correctly.

UInt4		stapos, msglen, wrtlen, pcblen;
msglen = error->errsize;
error->errpos = stapos + wrtlen;

@davecramer
Copy link
Contributor

Interesting. Did you run into this in a real situation ?

@r33s3n6
Copy link
Contributor Author

r33s3n6 commented Nov 2, 2024

Yes, but I was not connecting to Postgres, but another database that gives a very long error message.

@davecramer davecramer merged commit e318ab9 into postgresql-interfaces:main Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants