Bug in tds_set_server when coming through ct_connect

"Peter C. Norton" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
I have this bug report from a user:

ct_connect is defined (in ctlib/ct.c) as:
CS_RETCODE
ct_connect(CS_CONNECTION * con, CS_CHAR * servername, CS_INT snamelen)
{
       ...
       } else if (snamelen == 0 || snamelen == CS_UNUSED) {
              server = NULL;
       ...
       tds_set_server(con->tds_login, server);
       ...

Note that 'snamelen' is explicitly and intentionally allowed to be 0,
in which case the 'servername' is ignored and we pass in server=NULL
to tds_set_server.
 
In
http://freetds.cvs.sourceforge.net/viewvc/freetds/freetds/src/tds/login.c?r1=1.178&r2=1.179&,
the code to default the server name based on the $TDSQUERY or $DSQUERY
environment variables is #if'ed out and replaced by
       assert(server);
 
The comment says
        // Doing this in tds_alloc_login instead
which, while true (in tds/mem.c), does not prevent the assert from failing.


So, can you please change it to something along the lines of

-    assert(server);
-    tds_dstr_copy(&tds_login->server_name, server);
+    if (server != NULL) {
+        tds_dstr_copy(&tds_login->server_name, server);
+    }



Thanks,

-Peter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.