Skip to content

Commit 08feac8

Browse files
authored
fix: handle null(/xfb) field correctly (#239)
1 parent e604005 commit 08feac8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

agent/protocol/mysql/utils.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func processLengthEncodedInt(s string, offset *int) (int64, bool) {
136136
// If it is 0xfc, it is followed by a 2-byte integer.
137137
// If it is 0xfd, it is followed by a 3-byte integer.
138138
// If it is 0xfe, it is followed by a 8-byte integer.
139+
const kResultsetRowNullPrefix = '\xfb'
139140
const kLencIntPrefix2b byte = 0xfc
140141
const kLencIntPrefix3b byte = 0xfd
141142
const kLencIntPrefix8b byte = 0xfe
@@ -157,6 +158,9 @@ func processLengthEncodedInt(s string, offset *int) (int64, bool) {
157158
}
158159
var result int64
159160
switch s[0] {
161+
case kResultsetRowNullPrefix:
162+
*offset = *offset + 1
163+
return 0, true
160164
case kLencIntPrefix2b:
161165
s = s[1:]
162166
if ok := checkLengthFunc(s, 2); !ok {
@@ -193,7 +197,11 @@ func DissectStringParam(s string, offset *int, param *string) bool {
193197
if !ok || len(s) < *offset+int(param_length) {
194198
return false
195199
}
196-
*param = s[*offset : *offset+int(param_length)]
200+
if param_length == 0 {
201+
*param = "NULL"
202+
} else {
203+
*param = s[*offset : *offset+int(param_length)]
204+
}
197205
*offset = *offset + int(param_length)
198206
return true
199207
}

0 commit comments

Comments
 (0)