Skip to content
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

Merged
merged 3 commits into from
Nov 6, 2023
Merged

Conversation

eliottness
Copy link
Contributor

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

@eliottness eliottness changed the base branch from main to 2.0 November 2, 2023 16:13
@eliottness eliottness changed the title Another copy bites the dust Remove unnecessary string copies Nov 2, 2023
cgo_ref_pool.go Outdated
goArray[len(str)] = 0 // Null termination byte for C strings

return sliceToUintptr(goArray)
nullTerminated := str + "\x00"
Copy link
Collaborator

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 🙏

Copy link
Contributor Author

@eliottness eliottness Nov 3, 2023

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented the function

Base automatically changed from 2.0 to main November 3, 2023 15:05
@eliottness eliottness force-pushed the another-copy-bites-the-dust branch from 09f9504 to 813bd5d Compare November 3, 2023 15:11
@eliottness eliottness merged commit 33f1007 into main Nov 6, 2023
61 checks passed
@eliottness eliottness deleted the another-copy-bites-the-dust branch November 6, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants