tds-fdw / tds_fdw

A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Other
380 stars 102 forks source link

tds_err_handler function #83

Open lorenati opened 8 years ago

lorenati commented 8 years ago

I'm using tds_fdw in windows 7 x64, I think I have an issue with this function inside tds_err_handler

ereport(ERROR,
            (errcode(ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION),
            errmsg("DB-Library error: DB #: %i, DB Msg: %s, OS #: %i, OS Msg: %s, Level: %i",
            dberr, dberrstr, oserr, oserrstr, severity)
            )); 

I did a little debug and the function _dblib_handle_info_message located in dbutil.c calls this tds_err_handler function and puts NULL in the oserrstr variable. If I do something that can call this function, like calling a foreign table that doesn't exists (in sql server side) the postgres service crashes.

I modified the function like this:

ereport(ERROR,
            (errcode(ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION),
            errmsg("DB-Library error: DB #: %i, DB Msg: %s, OS #: %i, Level: %i",
            dberr, dberrstr, oserr, severity)
            ));

So I don't include the oserrstr variable and postgres just throws the error but the service is safe. I'm not sure how can this null value can cause the service crash, do you have any suggestions?

GeoffMontee commented 8 years ago

Thanks for the bug report!

Can you please see if this is fixed for you in the latest commit? https://github.com/tds-fdw/tds_fdw/commit/b770b2de5d343a7de31b10ac25ac424546180fd5

lorenati commented 8 years ago

Yes, with the latest commit the problem is fixed

Thank you

GeoffMontee commented 8 years ago

Awesome! I'm glad to hear that it's not crashing for you anymore.