error handling

Geoff Winkless geoff at farmline.com
Mon Jan 24 07:36:52 EST 2000


Ok, here's a tricky one.

I've implemented a check in read.c:tds_read_packet for a negative return
from the read() function. This catches a disconnected socket correctly.

I thus decided to send an error to the error handler - but since that
expects a msg_info struct, (which we obviously don't get back from the
server, since the server is disconnected!) I build one on the fly...

So we have:

    if (len < 0) {

      /* now we need to pass a fake message back to the error handler. */
      tds->msg_info->msg_number = 10018; /* is there a define for this??? */
      tds->msg_info->message="The connection was closed";
      tds->msg_info->msg_state=0;
      tds->msg_info->msg_level=9;
      tds->msg_info->priv_msg_type = 0;
      tds->msg_info->server=NULL;
      tds->msg_info->proc_name=NULL;
      tds->msg_info->line_number = 0;
      if (tds->parent) {
        fprintf (stderr, "tds->parent is valid. Calling err_handler\n");
        g_tds_err_handler(tds->parent);
      } else {
        fprintf (stderr, "tds->parent is null\n");
        tds_free_msg(tds->msg_info);
      }


Now I'm using dblib so g_tds_err_handler gets set to
dblib_handle_err_message.

If I gdb-break my program at the point above, I can do the following:

(gdb) print dblib_handle_err_message
$2 = {int (void *)} 0x4001571c <dblib_handle_err_message>
(gdb) print g_tds_err_handler
$3 = (int (*)()) 0x4001571c <dblib_handle_err_message>

Now if I allow this call (g_tds_err_handler(tds->parent)) to continue the
program SIGSEGVs - it appears to be calling some random address in data
space.

However if I call dblib_handle_err_message (tds->parent) instead, the
program runs correctly.

Any thoughts?

Geoff




More information about the FreeTDS mailing list