James K. Lowden
jklowden at freetds.org
Tue Jul 8 15:19:08 EDT 2008
Thomas Stover wrote:
> OK everything was working fine. Then over the weekend something happened
> somewhere, and now I can't get a connection to our ms sql 2000 server
> even with a simple test program. I was using 0.63-3.2.ubuntu x86_64.
> (why was ubuntu so out of date?) So I removed that package, and built
> 0.82 from source. I get a segfault trying to difference a NULL pointer.
> Here is my test program and valgrind output. Any ideas? I did look at
> that line in dblib.c, and it looks like you might need to check for
> NULL. Or is that the point - it should never be NULL?
> int main(void)
> unsigned char temp;
> PDBPROCESS dbproc;
> PLOGINREC login;
> int ncols, x;
> login = dblogin();
You must call dbinit() before installing your handlers. The documentation
is very clear that dbinit() is to be called "before calling any other
When I run your program verbatim (except that
needs to be
because \u is an undefined escape in C) I get a segfault, as you do.
After moving dbinit() up four lines, I get this:
DB-Library Error 20109: NULL DBPROCESS pointer passed to DB-Library
sOperating System Error 0: Undefined error: 0
I get that message because dbopen() returned NULL, which was then passed
Your program "works" with 0.62 because the error handling and error
checking was primitive back in those days. In 0.82, every db-lib function
checks its inputs and emits appropriate error messages.
As you're not checking return codes, I think it's likely you're actually
just missing the errors. (I don't know the effect of installing handlers
before dbinit() in 0.62. I wouldn't be surprised if they just don't get
Thanks for posting. It's an interesting error, because on general
principles I believe it should be impossible to induce a segmentation
error using a library.
More information about the FreeTDS