Skip to content

Commit 3265344

Browse files
authored
fix: stop passing empty strings as null string ptrs (#99)
Empty strings would be passed as null waf string objects, which the WAF doesn't handle in all cases. While we wait for a WAF update to properly handle this, we set the waf object value for empty go strings to a null terminated empty C string representation. This is band-aid solution that should get discarded once the WAF handles nullptr strings in all expected cases.
1 parent 0561ed1 commit 3265344

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cgo_ref_pool.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ type cgoRefPool struct {
2727
arrayRefs [][]bindings.WafObject
2828
}
2929

30+
// This is used when passing empty Go strings to the WAF in order to avoid passing null string pointers,
31+
// which are not handled by the WAF in all cases.
32+
// FIXME: to be removed when the WAF handles null ptr strings in all expected places
33+
var emptyWAFStringValue = unsafe.NativeStringUnwrap("\x00").Data
34+
3035
func (refPool *cgoRefPool) append(newRefs cgoRefPool) {
3136
refPool.stringRefs = append(refPool.stringRefs, newRefs.stringRefs...)
3237
refPool.arrayRefs = append(refPool.arrayRefs, newRefs.arrayRefs...)
@@ -51,7 +56,8 @@ func (refPool *cgoRefPool) AllocWafString(obj *bindings.WafObject, str string) {
5156

5257
if len(str) == 0 {
5358
obj.NbEntries = 0
54-
obj.Value = 0
59+
// FIXME: use obj.Value = 0 when the WAF handles null string ptr in all expected places
60+
obj.Value = emptyWAFStringValue
5561
return
5662
}
5763

0 commit comments

Comments
 (0)