freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
[freetds] [PATCH] Fix segfault when triggering a foreign key violation
- From: Alex Kiesel <alex.kiesel AT document-root.de>
- To: freetds AT lists.ibiblio.org
- Subject: [freetds] [PATCH] Fix segfault when triggering a foreign key violation
- Date: Sat, 10 Jan 2004 17:11:14 +0100
Hi,
I found that when inserting a row that triggers a foreign key violation
or duplicate row violation, freetds was unable to properly read all data
from the wire.
When such an aforementioned error is triggered the database sends a EED
token which gets processed by tds_process_msg(). When the status byte of
the EED message is set to 1, additional error data follows; freetds
fails to read this data from wire - which appears to let sqsh think it
must read data and thus causing it to segfault.
The attached patch fixes this bug; I'd be glad if it's not too late for
the release...
Greets from Karlsruhe,
-Alex
Index: src/tds/token.c =================================================================== RCS file: /home/cvs/mirror/freetds/freetds/src/tds/token.c,v retrieving revision 1.244 diff -u -r1.244 token.c --- src/tds/token.c 30 Dec 2003 14:45:03 -0000 1.244 +++ src/tds/token.c 10 Jan 2004 16:08:52 -0000 @@ -2319,6 +2319,7 @@ int rc; int len; int len_sqlstate; + int status; TDSMSGINFO msg_info; /* make sure message has been freed */ @@ -2360,9 +2361,10 @@ if (strcmp(msg_info.sql_state, "ZZZZZ") == 0) TDS_ZERO_FREE(msg_info.sql_state); + /* if status = 1, extended error data follows */ + status = tds_get_byte(tds); + /* junk status and transaction state */ - /* TODO if status == 1 clear cur_dyn and param_info ?? */ - tds_get_byte(tds); tds_get_smallint(tds); break; case TDS_INFO_TOKEN: @@ -2396,6 +2398,12 @@ * TDS_EED_TOKEN is not being called for me. */ if (msg_info.sql_state == NULL) msg_info.sql_state = tds_alloc_lookup_sqlstate(tds, msg_info.msg_number); + + + /* In case extended error data is sent, we just try to discard it */ + if (1 == status) { + tds_process_trailing_tokens(tds); + } /* call the msg_handler that was set by an upper layer * (dblib, ctlib or some other one). Call it with the pointer to
- [freetds] [PATCH] Fix segfault when triggering a foreign key violation, Alex Kiesel, 01/10/2004
Archive powered by MHonArc 2.6.24.