-
Notifications
You must be signed in to change notification settings - Fork 38
SQL_C_BINARY data buffer uses NULL terminator, but realloc() may be missed #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ision to realloc.
|
I'm trying to compile the driver myself. Any feedback very welcome. So far I managed to scratch this together: # this is on a Kubuntu 25.04 with installation according
# to https://wiki.postgresql.org/wiki/Apt (modernized).
sudo apt-get install unixodbc odbcinst unixodbc-dev libpq-dev
# my PR version
git clone https://github.com/markmaker/psqlodbc.git
./bootstrap
# if somebody knows a better/automatic/more correct way to configure these paths, please speak up 🤠
./configure \
--with-unixodbc=/usr/include/x86_64-linux-gnu/unixODBC/ \
--with-libpq=/usr/include/postgresql \
--enable-pthreads \
CPPFLAGS="-DSQLCOLATTRIBUTE_SQLLEN"
make
sudo make installThen I copied the regular ...
[PostgreSQL Unicode Fixed]
Description=PostgreSQL ODBC driver (Unicode version)
Driver=/usr/local/lib/psqlodbcw.so
Setup=/usr/local/lib/libodbcpsqlS.so
Debug=0
CommLog=1
UsageCount=2Then I changed my driver connect to point to the new one...
... tested again and it seems the problem is gone! 🎈🎉 |
|
@davecramer, thank you for the fast merge. 🚀 How do we know when this went into the apt repo? How long do you suppose this takes? Sorry, I'm not very familiar with how these repos work 😅 _Mark |
|
probably not yet, let me send an email to the guys who do that stuff |
17.00.0007 version of the driver seems to have a bug in handling of insertions to blob columns, failing to insert (or query) values for certain column lengths. Will re-evaluate on the next driver version. A related change that may have caused this regression in the driver is postgresql-interfaces/psqlodbc#145
17.00.0007 version of the driver seems to have a bug in handling of insertions to blob columns, failing to insert (or query) values for certain column lengths. Will re-evaluate on the next driver version. A related change that may have caused this regression in the driver is postgresql-interfaces/psqlodbc#145
17.00.0007 version of the driver seems to have a bug in handling of insertions to blob columns, failing to insert (or query) values for certain column lengths. Will re-evaluate on the next driver version. A related change that may have caused this regression in the driver is postgresql-interfaces/psqlodbc#145
17.00.0007 version of the driver seems to have a bug in handling of insertions to blob columns, failing to insert (or query) values for certain column lengths. Will re-evaluate on the next driver version. A related change that may have caused this regression in the driver is postgresql-interfaces/psqlodbc#145
17.00.0007 version of the driver seems to have a bug in handling of insertions to blob columns, failing to insert (or query) values for certain column lengths. Will re-evaluate on the next driver version. A related change that may have caused this regression in the driver is postgresql-interfaces/psqlodbc#145
Problem
We get spurious heap corruption.
Diagnosis
After a steep learning curve in such matters, we finally found a way to pinpoint it using
valgrind(the key was using the redzone, so it would not immediately corrupt everything):It outputs these sections (snippets).
EDIT: installed Debug symbol, now we can even better pinpoint it:
Due to the sequence of ODBC calls, and the exact size of the buffer (3576), we knew it was the BYTEA column in our row:
Because we use bound buffers that are smaller than that, and we haven't yet come to the point of calling
SQLGetData(), we know this must be an internal buffer that already knows the size of the BYTEA data. Therefore it couldn't be one of our buffers being too small.It follows that this looks like the extra NULL terminator byte that so plagues the C world. And sure, the code says:
psqlodbc/convert.c
Lines 1058 to 1066 in 6e99e75
Proposed fix
It seems that immediately after this, the
len_for_wcs_termis not included in the comparison to assess the need ofrealloc(). If by chance the buffer was already exactlyneedbuflenbytes large, it would not be realloc'd.psqlodbc/convert.c
Lines 1067 to 1073 in 6e99e75
Therefore this PR intends to fix that.
We were unable to test this due to time constraints (this is currently impeding our rollout, we have our hands full 🤕!)Help in setting up a psqlodbc compilation and local installation and deployment is welcome.