Skip to Content.
Sympa Menu

freetds - Re: [freetds] help

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] help
  • Date: Tue, 8 Jul 2008 15:19:08 -0400

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[512];
> PDBPROCESS dbproc;
> PLOGINREC login;
> int ncols, x;
>
> dberrhandle(err_handler);
> dbmsghandle(msg_handler);
>
> dbinit();
> 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
DB-Library functions".

When I run your program verbatim (except that

DBSETLUSER(login, "domain\username")
needs to be
DBSETLUSER(login, "domain\\username")

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
to dbcmd().

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
called.)

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.

HTH.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page