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

types: improve comparison reliability of binary strings #168

Merged
merged 1 commit into from
Aug 22, 2023

Conversation

jow-
Copy link
Owner

@jow- jow- commented Aug 22, 2023

The existing ucv_compare() implementation utilized strcmp() to compare two ucode string values, which may lead to incorrect results for strings containing null bytes as the comparison prematurely aborts when encountering the first null.

Rework the string comparison logic to use memcmp() for comparing both ucv strings with each other in order to ensure that expressions such as "" == "\u0000" lead to the expected false result.

Ref: openwrt/luci#6530

@jow- jow- force-pushed the fix-binary-string-compare branch from cf24b5c to 1480ec5 Compare August 22, 2023 08:30
The existing `ucv_compare()` implementation utilized `strcmp()` to compare
two ucode string values, which may lead to incorrect results for strings
containing null bytes as the comparison prematurely aborts when encountering
the first null.

Rework the string comparison logic to use `memcmp()` for comparing both ucv
strings with each other in order to ensure that expressions such as
`"" == "\u0000"` lead to the expected `false` result.

Ref: openwrt/luci#6530
Signed-off-by: Jo-Philipp Wich <[email protected]>
@jow- jow- force-pushed the fix-binary-string-compare branch from 1480ec5 to 8f852ea Compare August 22, 2023 08:34
@jow- jow- merged commit ce39326 into master Aug 22, 2023
6 checks passed
@jow- jow- deleted the fix-binary-string-compare branch August 22, 2023 09:54
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.

1 participant