Skip to content

Commit 10be0c9

Browse files
Fixed bug which could cause a redirect loop with improperly configured
listener redirects.
1 parent 83d2e98 commit 10be0c9

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Thin Mode Changes
1818
#) Fixed bug which caused a cursor leak if an error was thrown while
1919
processing the execution of a query.
2020
#) Fixed bugs in the implementation of the statement cache.
21+
#) Fixed bug which could cause a redirect loop with improperly configured
22+
listener redirects.
2123
#) Eliminated unneeded round trip when using token authentication to connect
2224
to the database.
2325

src/oracledb/impl/thin/constants.pxi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ DEF TNS_PACKET_TYPE_CONTROL = 14
4040
DEF TNS_PACKET_TYPE_REDIRECT = 5
4141

4242
# packet flags
43+
DEF TNS_PACKET_FLAG_REDIRECT = 0x04
4344
DEF TNS_PACKET_FLAG_TLS_RENEG = 0x08
4445

4546
# data flags

src/oracledb/impl/thin/messages.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ cdef class ConnectMessage(Message):
17461746
if buf._caps.supports_oob:
17471747
service_options |= TNS_GSO_CAN_RECV_ATTENTION
17481748
connect_flags_2 |= TNS_CHECK_OOB
1749-
buf.start_request(TNS_PACKET_TYPE_CONNECT)
1749+
buf.start_request(TNS_PACKET_TYPE_CONNECT, self.packet_flags)
17501750
buf.write_uint16(TNS_VERSION_DESIRED)
17511751
buf.write_uint16(TNS_VERSION_MINIMUM)
17521752
buf.write_uint16(service_options)

src/oracledb/impl/thin/packet.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ cdef class WriteBuffer(Buffer):
587587

588588
cdef:
589589
uint8_t _packet_type
590+
uint8_t _packet_flags
590591
Capabilities _caps
591592
object _socket
592593
uint8_t _seq_num
@@ -610,7 +611,7 @@ cdef class WriteBuffer(Buffer):
610611
self.write_uint16(size)
611612
self.write_uint16(0)
612613
self.write_uint8(self._packet_type)
613-
self.write_uint8(0)
614+
self.write_uint8(self._packet_flags)
614615
self.write_uint16(0)
615616
self._pos = size
616617
if DEBUG_PACKETS:
@@ -650,7 +651,8 @@ cdef class WriteBuffer(Buffer):
650651
"""
651652
return self._max_size - PACKET_HEADER_SIZE - 2
652653

653-
cdef void start_request(self, uint8_t packet_type, uint16_t data_flags=0):
654+
cdef void start_request(self, uint8_t packet_type, uint8_t packet_flags=0,
655+
uint16_t data_flags=0):
654656
"""
655657
Indicates that a request from the client is starting. The packet type
656658
is retained just in case a request spans multiple packets. The packet
@@ -659,6 +661,7 @@ cdef class WriteBuffer(Buffer):
659661
"""
660662
self._packet_sent = False
661663
self._packet_type = packet_type
664+
self._packet_flags = packet_flags
662665
self._pos = PACKET_HEADER_SIZE
663666
if packet_type == TNS_PACKET_TYPE_DATA:
664667
self.write_uint16(data_flags)

src/oracledb/impl/thin/protocol.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ cdef class Protocol:
133133
"""
134134
cdef:
135135
ConnectMessage connect_message = None
136+
uint8_t packet_type, packet_flags = 0
136137
object ssl_context, connect_info
137138
ConnectParamsImpl temp_params
138139
str host, redirect_data
139140
Address temp_address
140-
uint8_t packet_type
141141
int port, pos
142142

143143
# store whether OOB processing is possible or not
@@ -163,6 +163,7 @@ cdef class Protocol:
163163
connect_message.connect_string_bytes = connect_string.encode()
164164
connect_message.connect_string_len = \
165165
<uint16_t> len(connect_message.connect_string_bytes)
166+
connect_message.packet_flags = packet_flags
166167

167168
# process connection message
168169
self._process_message(connect_message)
@@ -180,6 +181,7 @@ cdef class Protocol:
180181
connect_string = redirect_data[pos + 1:]
181182
self._connect_tcp(params, description, address, host, port)
182183
connect_message = None
184+
packet_flags = TNS_PACKET_FLAG_REDIRECT
183185
elif connect_message.packet_type == TNS_PACKET_TYPE_ACCEPT:
184186
break
185187

@@ -293,7 +295,7 @@ cdef class Protocol:
293295
"""
294296
Send the final close packet to the server and close the socket.
295297
"""
296-
buf.start_request(TNS_PACKET_TYPE_DATA, TNS_DATA_FLAGS_EOF)
298+
buf.start_request(TNS_PACKET_TYPE_DATA, 0, TNS_DATA_FLAGS_EOF)
297299
buf.end_request()
298300
self._socket.shutdown(socket.SHUT_RDWR)
299301
self._socket.close()

0 commit comments

Comments
 (0)