Skip to Content.
Sympa Menu

freetds - Re: sigsegv in tds_submit_query

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: mark <snowdog AT zserve.com>
  • To: "TDS Development Group" <freetds AT franklin.metalab.unc.edu>
  • Subject: Re: sigsegv in tds_submit_query
  • Date: Tue, 10 Sep 2002 17:25:15 -0700




I should mention that the queries work for a while, then, out of the blue and
without any obvious provocation, it bails.
The application is a server that is capable of handling thousands of clients.
The code below is single-threaded. However,
I intend for it to be single-threaded and have mutexes outside these calls
protecting them. Anyway, each client does
different things to the database like this function, but sooner or later, the
tds_submit_query bails. It works, then after
a while it bails. (sorry for being redundant, I'm just trying to be clear).

I'll add another fucntion that has this problem:

bool isValidUsernamePassword (string & username, string & password, bool &
isExpired)
{
//new_connection ();
string query = "select rtrim (username), rtrim (password), datediff
(day,expires,getdate()) as isExpired from account where username = '" +
username + "' and password = '" + password + "'";
string dusername, dpassword;
cout << query << endl;
cout << "tds_socket->s = " << tds_socket->s << endl;
//this is always valid (usually 7)
isExpired = false;
int rc;
int i;
TDSCOLINFO *col;
int ctype;
CONV_RESULT dres;

char * pquery = (char *)query.c_str ();
if (!pquery)
{
cout << "ahh, so that's the problem." << endl;

// this never happens, by the way.
}



rc = tds_submit_query (tds_socket, (char *)query.c_str ());
if (rc != TDS_SUCCEED)
{
cerr << "query did not succeed" << endl;
return false;
}

rc = tds_process_result_tokens (tds_socket);
if (rc != TDS_SUCCEED)
{
return false;
}

while (rc==TDS_SUCCEED)
{
if (tds_socket->res_info)
{
for (i=0; i<tds_socket->res_info->num_cols; i++)
{
//cout << tds_socket->res_info->columns[i]->column_name << "\t";
}
//cout << endl;
}
while ((rc=tds_process_row_tokens(tds_socket))==TDS_SUCCEED)
{
if (!tds_socket->res_info)
{
continue;
}
for (i=0; i<tds_socket->res_info->num_cols; i++)
{
col = tds_socket->res_info->columns[i];
ctype = tds_get_conversion_type(col->column_type, col->column_size);

if(tds_convert(tds_socket->tds_ctx,
ctype,
(TDS_CHAR
*)&tds_socket->res_info->current_row[col->column_offset],
col->column_size,
SYBVARCHAR,
1024*1024,
&dres) == TDS_FAIL
)
{
continue;
}
switch (i)
{
case 0:
{
//cout << "username = " << dres.c << endl;
dusername = dres.c;
break;
}
case 1:
{
//cout << "password = " << dres.c << endl;
dpassword = dres.c;
break;
}
case 2:
{
//cout << "isExpired = " << dres.c << endl;
int expired = atoi (dres.c);
if (expired > 0)
{
isExpired = true;
}
else
{
isExpired = false;
}
break;
}
}
free (dres.c);
}
//cout << endl;
}
rc = tds_process_result_tokens (tds_socket);
}

if (cmp_nocase (username, dusername) != 0 || cmp_nocase (password,
dpassword) != 0)
{
return false;
}
return true;
}


On Tuesday 10 September 2002 04:59 pm, you wrote:
> On Tuesday 10 September 2002 12:17 pm, Brian Bruns wrote:
> > What calls are you making prior to tds_submit_query to set things up?
>
> TDSLOGIN * tds_login = NULL;
> TDSSOCKET * tds_socket = NULL;
> TDSCONTEXT * context = NULL;
>
>
> string host;
> string user;
> string pass;
> string server;
>
> void set_host (string & _host) { host = _host; }
> void set_user (string & _user) { user = _user; }
> void set_pass (string & _pass) { pass = _pass; }
> void set_server (string & _server) { server = _server; }
>
>
>
> void new_connection ()
> {
> tds_login = tds_alloc_login ();
> cout << "attempting to connect to " << server << endl;
> tds_set_host (tds_login, (char *)host.c_str ());
> tds_set_user (tds_login, (char *)user.c_str ());
> tds_set_passwd (tds_login, (char *)pass.c_str ());
> tds_set_version (tds_login, 7,0);
> tds_set_port (tds_login, 1433);
> tds_set_app (tds_login, "imd");
> tds_set_timeouts (tds_login, 0, 0, 0);
> tds_set_library (tds_login, "TDS-Library");
> tds_set_charset (tds_login, "iso_1");
> tds_set_language (tds_login, "us_english");
> tds_set_packet (tds_login, 512);
> tds_set_server (tds_login, (char *)server.c_str ());
>
>
> context = tds_alloc_context ();
> if (context->locale && !context->locale->date_fmt)
> {
> context->locale->date_fmt = strdup ("%b %e %Y %l:%M%p");
> }
> context->msg_handler = _handle_message;
> context->err_handler = _handle_message;
>
> tds_socket = tds_connect(tds_login, context, NULL);
>
> if (!tds_socket)
> {
> cerr << "unable to connect to " << server << endl;
> }
>
> do_query (tds_socket, "use thedb");
> }
>
> > > On Monday 09 September 2002 06:12 pm, James K. Lowden wrote:
> > > > On Mon, 9 Sep 2002 12:36:56 -0700, "mark" <snowdog AT zserve.com> wrote:
> > > > > I'm getting sigsegv's in tds_submit_query (CVS HEAD updated this
> > > > > morning).
> > > > >
> > > > > Just wondering if its possible that the connection is getting
> > > > > ruined somehow either by the database closing it or what. Is there
> > > > > any way I can test a TDSSOCKET object to make sure that it won't
> > > > > cause tds_* functions to sigsegv?
> > > >
> > > > Has anyone reproduced this? tsql works for me.
> > > >
> > > > Mark, what's the client architecture, and can you provide a
> > > > backtrace?
> > > >
> > > > --jkl
> > >
> > > I'm using Kylix 3, so the backtrace is kinda weird.
> > >
> > > libpthread.pthread_mutex_lock + 0x17
> > > libc.free + 0xa3
> > > tds_free_column + 0x24
> > > imd.tds_free_results + 0x85
> > > tds_free_all_results + 0x15
> > > imd.tds_submit_query + 0x6d
> > >
> > > All this is running on gentoo linux gcc 2.95x connecting to MS SQL
> > > Server= 2000=20
> > > on Windows 2000.
> > >
> > > here's an ldd on my program:
> > > mark@mark imd $ ldd imd
> > > libdl.so.2 =3D> /lib/libdl.so.2 (0x4002b000)
> > > libm.so.6 =3D> /lib/libm.so.6 (0x4002f000)
> > > libpthread.so.0 =3D> /lib/libpthread.so.0 (0x40051000)
> > > libc.so.6 =3D> /lib/libc.so.6 (0x40067000)
> > > /lib/ld-linux.so.2 =3D> /lib/ld-linux.so.2 (0x40000000)
> > >
> > >
> > > I have verified that the parameters I'm passing to tds_submit_query are
> > > v= alid:
> > > The TDSSOCKET is correct. The query is also valid, that is it is quite
> > > sh= ort=20
> > > and null terminated. The TDSSOCKET, interestingly enough, gets hosed
> > > afte= r=20
> > > the sigsegv. All the data in the TDSSOCKET structure is altered=20
> > > significantly.
> > >
> > > =2E/configure --eneable-threadsafe --tdsver=3D7.0
> > >
> > > is how I configured it.
> > >
> > >
> > > Thanks,
> > >
> > > Mark
> >
> > ---
> > You are currently subscribed to freetds as: [snowdog AT zserve.com]
> > To unsubscribe, forward this message to
> > $subst('Email.Unsub')
>
> ---
> You are currently subscribed to freetds as: [snowdog AT zserve.com]
> To unsubscribe, forward this message to
> $subst('Email.Unsub')





Archive powered by MHonArc 2.6.24.

Top of Page