-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary string copies #38
Conversation
cgo_ref_pool.go
Outdated
goArray[len(str)] = 0 // Null termination byte for C strings | ||
|
||
return sliceToUintptr(goArray) | ||
nullTerminated := str + "\x00" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can lead to a copy whereas libddwaf can manage non-null terminated strings via ddwaf_object_stringl()
.
So I suggest we avoid this concatenation, by for example removing the existence of AllocCString
(which has an unclear name with the 0-copy approach) and revisit this API to make it possible to avoid the concatenation here 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today, AllocCString
is not used for string WAF objects, it is only used to allocated strings for the obfuscator config. AllocWafString
is used for all cases concerning the WAF objects, which indeed does not use null-terminated strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented the function
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
09f9504
to
813bd5d
Compare
Signed-off-by: Eliott Bouhana <[email protected]>
Since we upgraded the WAF to a version higher than 1.11, the input passed in are all read-only on the WAF side. Since this is the case we can remove unnecessary copies on our side