Oracle TNS 314 Protocol Analysis-5, Error Return

* Error message return process (take SQL errors for example)

Client

 

 

 

Server

1

-------

Data Piggyback(11) Cursor Close All(69)

Or 03 5e

----->

Specific statements

2

<-----

Marker(0C)

-------

Return to Marker

3

<-----

Marker(0C)

-------

Return to Marker

4

-------

Marker(0C)

----->

Request Marker

5

<-----

Data Error(17)  02

-------

error message

The packages involved in the error request are Marker packages (PacketType 0x0C) and Data Error (DataType 0x06 DataID 0x17 CallID 0x02) packages

After an error request is sent, the server returns two Markers (2,3), and the client actively retrieves the error information through a Marker (4) request (5)

Marker package is not a data package, his dataflag is 0C, so the header is

0x00,0x0b,0x00,0x00,0x0c,0x00,0x00,0x00

Currently it seems that the Marker package length is fixed to 0b

After 8 bytes of header fixing are removed, the remaining three bytes are Marker's specifics

First Marker Returned

01 00 01 or 01 00 03

Attention

    Marker Type: Data Marker - 1 Data Bytes (0x01)

    Marker Data Byte: 0x00

Marker Data Byte: 0x03 or 0x01

Second Marker Returned

01 00 02

Attention

    Marker Type: Data Marker - 1 Data Bytes (0x01)

    Marker Data Byte: 0x00

Marker Data Byte: 0x02

Request Marker

01 00 02

Attention

    Marker Type: Data Marker - 1 Data Bytes (0x01)

    Marker Data Byte: 0x00

Marker Data Byte: 0x02

Error message return

This package varies from client to client depending on the server and is not generic

64bitOCIclient to 12c error return

This package is a Data package, DataID=17 CALLID=02

Contains two parts, the first part has a fixed length of 155 bytes, representing internal error information, and the second part is an error string with a long length of bytes, related to language and encoding settings

​                                    .....

64bitOCIclient to 11g error return

 

This package is a Data package, DataID=04 CALLID=05

Contains two parts, the first part has a fixed length of 68 bytes, indicating internal error information, and the second part has the same length as the 12c version as the error string with a prefix length, which is related to language and encoding settings

Note that as with 12c, the error code for the green part should be the same as the error code in the blue string in order to display the information in the string, otherwise the default information will be displayed

TNS312 Version Error Return

If you change the version to 312, the error returned will be different.

This package is a Data package, DataID=17 CALLID=02

The error code of the green part must be the same as the error code in the blue string in order to display the information in the string, otherwise the default information will be displayed

* Code Samples

Function: If the prohibition condition is met at the receiving command, the return permission is insufficient, as shown in the figure.

 

First, two marker s are returned at the receive command if the prohibition condition is met

 

if(command:match("forbidden")) then
                    --set a flag indicate error happen
                    ngx.ctx.responseError=true
                    print("forbidden matched...")
                    --return marker1
                    reqsock:send(string.char(0x00,0x0b,0x00,0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x01))
                    --return marker2
                    reqsock:send(string.char(0x00,0x0b,0x00,0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x02))
                    goto continue
                end

When an agent receives a marker, it returns a specific error and needs to be judged based on various conditions

 

        
        --process req marker, if flag true then return error
        if(data:byte(3)==12 and ngx.ctx.responseError) then
            print("return error message")
            --11g
            if(tnsVersion==314 and oracleVersion.major==11) then
                reqsock:send(string.char(           
0x00, 0x75, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x28, 0x4f, 0x52, 0x41,
0x2d, 0x30, 0x30, 0x39, 0x34, 0x32, 0x3a, 0x20,
0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6f, 0x72,
0x20, 0x76, 0x69, 0x65, 0x77, 0x20, 0x64, 0x6f,
0x65, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x65,
0x78, 0x69, 0x73, 0x74, 0x0a))
            end
            --12c
            if(tnsVersion==314 and oracleVersion.major==12) then
                reqsock:send(string.char(
0x00, 0xb4, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x17, 0x02, 0x04, 0x00, 0x04, 0x33,
0x35, 0x38, 0x34, 0x04, 0x01, 0x00, 0x00, 0x00,
0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07,
0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x40, 0xbb, 0x3d, 0x24, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 

Tags: Oracle encoding SQL

Posted on Sun, 10 May 2020 11:43:31 -0700 by sergeidave