Skip to content

fix: leftover contact-id atoi/stoi - #1

Open
tonycoder-hub wants to merge 1 commit into
openharmony:masterfrom
tonycoder-hub:leftover-contact-id-atoi
Open

fix: leftover contact-id atoi/stoi#1
tonycoder-hub wants to merge 1 commit into
openharmony:masterfrom
tonycoder-hub:leftover-contact-id-atoi

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Summary

GetContactByValue parses untrusted ValuesBucket string contact ids with std::stoi, and Split / ReContactMerge parse DataShare whereArgs with atoi. Overflow is undefined behavior in atoi and can throw in stoi; junk and partial tokens become 0, so split/merge can hit the wrong raw contact.

Parse via std::from_chars (ParseContactIdInt). Valid integers keep the same result (including 0/-1 and INT_MAX/INT_MIN); reject overflow/partial/non-digits, log with HILOG_ERROR, and fail the operation instead of using 0.

Test plan

  • Host+ASan/UBSan: /workspace/leftover-hosttest/parse_contact_id_int_host_test — valid 42/0/01/INT_MAX/INT_MIN/-1 parse; overflow (2147483648, 9999999999999999999), empty, mixed (1abc), whitespace, +1, and 0x10 rejected with no sanitizer reports. Predicate helper rejects junk ids.

Signed-off-by: Tony Coder 407243179@qq.com

DataShare whereArgs and ValuesBucket string contact ids were parsed with
atoi/stoi. Overflow is undefined (atoi) or can throw (stoi); junk and
partial tokens become 0, so split/merge can hit the wrong raw contact.

Parse via std::from_chars (ParseContactIdInt). Valid integers keep the
same result; reject empty/overflow/partial/non-digits.

Signed-off-by: Tony Coder <407243179@qq.com>
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