Skip to Content.
Sympa Menu

freetds - Re: dberrhandler() and dbmsghandler()

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Steven J. Backus" <backus AT math.utah.edu>
  • To: "TDS Development Group" <freetds AT franklin.metalab.unc.edu>
  • Subject: Re: dberrhandler() and dbmsghandler()
  • Date: Fri, 6 Sep 2002 13:00:02 -0600 (MDT)


"Lowden, James K" <LowdenJK AT bernstein.com> writes:

> If you will post a simple test program evincing the problem when linked with
> the most recent snapshot, I will look at it. The current code in
> src/tds/token.c::tds_process_msg() looks clean, but maybe under some
> circumstances it fetches a corrupted servername?

Using the freetds in:

ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/freetds-current.tgz

And this program:

#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>
#include <stdio.h>

/* Forward declarations of the error handler and message handler. */
int err_handler();
int msg_handler();

FILE *ERR_CH;

int main(int argc, char *argv[])
{
LOGINREC *login; /* The login information */
DBPROCESS *dbproc;

if ((ERR_CH = fopen("TestTds.Err", "w")) == NULL) {
perror("TestTds.Err");
exit(1);
}

if (dbinit() == FAIL)
{
fprintf(stderr, "Database failure\n");
exit(1);
}

login = dblogin();
DBSETLUSER(login, "xxxxxx");
DBSETLPWD(login, "xxxxxxxxxxxxxxx");

dbproc = dbopen(login, NULL);

dberrhandle(err_handler);
dbmsghandle(msg_handler);

dbuse(dbproc, "ged");

printf("Do something here.\n");
}

int err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr,
char *dberrstr, char *oserrstr)
{
if ((dbproc == NULL) || (DBDEAD(dbproc)))
return(INT_EXIT);
else
{
fprintf (ERR_CH, "DB-Library error:\n\t%s\n", dberrstr);

if (oserr != DBNOERR)
fprintf (ERR_CH, "Operating-system error:\n\t%s\n", oserrstr);

return(INT_CANCEL);
}
}

int msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
int severity, char *msgtext, char *srvname, char *procname,
int line)
{
fprintf (ERR_CH, "Msg %ld, Level %d, State %d\n",
msgno, severity, msgstate);

if (strlen(srvname) > 0)
fprintf (ERR_CH, "Server '%s', ", srvname);
if (strlen(procname) > 0)
fprintf (ERR_CH, "Procedure '%s', ", procname);
if (line > 0)
fprintf (ERR_CH, "Line %d", line);

fprintf (ERR_CH, "\n\t%s\n", msgtext);

return(0);
}

It crashes, here's the bt:

(gdb) bt
#0 0xdfb7d489 in strlen () from /usr/lib/libc.so.1
#1 0x8049787 in msg_handler (dbproc=0x8067df0, msgno=5701, msgstate=1,
severity=10, msgtext=0x8068c78 "Changed database context to 'ged'.\n",
srvname=0x8067aa0 "episun7", procname=0x0, line=-541110272) at
testtds.c:69
#2 0x804cd9e in dblib_handle_info_message (tds_ctx=0x8066ab0, tds=0x8068f88,
msg=0x8069558) at dbutil.c:53
#3 0x804f7f7 in tds_process_msg (tds=0x8068f88, marker=229) at token.c:1289
#4 0x804dd6e in tds_process_default_tokens (tds=0x8068f88, marker=229)
at token.c:103
#5 0x804bf79 in dbsqlok (dbproc=0x8067df0) at dblib.c:1984
#6 0x804a363 in dbsqlexec (dbproc=0x8067df0) at dblib.c:617
#7 0x804a39f in dbuse (dbproc=0x8067df0, dbname=0x8058fdc "ged")
at dblib.c:627
#8 0x8049699 in main (argc=1, argv=0x804770c) at testtds.c:39

Thanks,
Steve




Archive powered by MHonArc 2.6.24.

Top of Page