Skip to content

Commit af74fe4

Browse files
authored
Fix login timeout segmentation faults (#497)
1 parent c1c9864 commit af74fe4

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## (unreleased)
22

33
* Fix compilation errors for Amazon Linux 1. Fixes #495.
4+
* Fix segfault for login timeouts
45

56
## 2.1.4
67

ext/tiny_tds/client.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ int tinytds_err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, c
9696
but we don't ever want to automatically retry. Instead have the app
9797
decide what to do.
9898
*/
99-
if (userdata->timing_out) {
99+
if (userdata && userdata->timing_out) {
100100
return INT_CANCEL;
101101
}
102-
else {
102+
// userdata will not be set if hitting timeout during login so check for it first
103+
if (userdata) {
103104
userdata->timing_out = 1;
104-
return_value = INT_TIMEOUT;
105105
}
106+
return_value = INT_TIMEOUT;
106107
cancel = 1;
107108
break;
108109

test/client_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ class ClientTest < TinyTds::TestCase
176176
end
177177
end
178178

179+
it 'raises TinyTds exception with login timeout' do
180+
skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
181+
begin
182+
action = lambda do
183+
Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
184+
new_connection login_timeout: 1, port: 1234
185+
end
186+
end
187+
assert_raise_tinytds_error(action) do |e|
188+
assert_equal 20003, e.db_error_number
189+
assert_equal 6, e.severity
190+
assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
191+
end
192+
ensure
193+
assert_new_connections_work
194+
end
195+
end
196+
179197
it 'raises TinyTds exception with wrong :username' do
180198
skip if ENV['CI'] && sqlserver_azure? # Some issue with db_error_number.
181199
options = connection_options :username => 'willnotwork'

0 commit comments

Comments
 (0)