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

JSONFormattable incorrectly sets a string starting with digit as int #35870

Merged
merged 1 commit into from Jul 25, 2022

Conversation

soumyakoduri
Copy link
Contributor

@soumyakoduri soumyakoduri commented Jul 1, 2020

JSONFormattable::set calls JSONParser::parse() to check if the given string
is a valid JSON object, which internally uses json_spirit::read to determine
the string type and copy it into data.
This routine incorrectly sets data type to integer if the string starts with
digit and copies only the first set of numeric values of the string.

For eg:
radosgw-admin zone modify --rgw-zone=cloud-zone --rgw-zonegroup=default --tier-config=connection.access_key=312CNV15CC2ZN44IPB24A

Output:
"tier_config": {
"connection": {
"access_key": 312,
"secret": "W0X3NbPXNW1B7Ru79xuuUI53ftSKieEl2ouuHP8C"
}
},

As can be seen in above output only first set of digits of the input string are copied. The same issue exists for even real & bool types.

The right fix seems to be to check if the entire string is read before processing the data value set.

Fixes: https://tracker.ceph.com/issues/55212

@soumyakoduri soumyakoduri changed the title JSONFormattable incorrectly sets a string starting with digit as integer JSONFormattable incorrectly sets a string starting with digit as int Jul 1, 2020
@yehudasa
Copy link
Member

yehudasa commented Jul 1, 2020

@soumyakoduri the passed string can also be a json structure, removing the decode_json will break this, right?

Referring to bitcoin/bitcoin@181771b , I have made similar changes to fix json_spirit::read_string itself. Kindly review the changes.

@soumyakoduri
Copy link
Contributor Author

@soumyakoduri the passed string can also be a json structure, removing the decode_json will break this, right?

I was wondering about the same too. But I wasn't able to test multiple array objects (like 'acls') set in a single string to validate this.

So can we alternatively - use decode_json for data of obj_type & array_type and for rest of the types, copy string in the same format? Does it sound okay?

@soumyakoduri
Copy link
Contributor Author

retest this please

@cbodley
Copy link
Contributor

cbodley commented Jul 31, 2020

json_spirit is used in a lot of other components in ceph, including rbd osd mon and mgr - it's hard to tell what impact this change will have on them

@soumyakoduri
Copy link
Contributor Author

json_spirit is used in a lot of other components in ceph, including rbd osd mon and mgr - it's hard to tell what impact this change will have on them

okay...As the main issue is in the json_spirit template , this seemed right way to fix it (I referred to bitcoin/bitcoin@181771b ).

Do you suggest we add special checks in "JSONFormattable" structure (which seem to be used in only rgw sync module code), as a workaround for now?

@stale
Copy link

stale bot commented Oct 10, 2020

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@stale stale bot added the stale label Oct 10, 2020
@stale
Copy link

stale bot commented Jan 11, 2021

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@stale stale bot closed this Jan 11, 2021
@soumyakoduri soumyakoduri reopened this Jan 11, 2021
@soumyakoduri
Copy link
Contributor Author

json_spirit is used in a lot of other components in ceph, including rbd osd mon and mgr - it's hard to tell what impact this change will have on them

okay...As the main issue is in the json_spirit template , this seemed right way to fix it (I referred to bitcoin/bitcoin@181771b ).

Do you suggest we add special checks in "JSONFormattable" structure (which seem to be used in only rgw sync module code), as a workaround for now?

@yehudasa @cbodley ..so for this particular issue, do you suggest we workaround it in rgw layer itself?

@mattbenjamin
Copy link
Contributor

@soumyakoduri if we're not fixing json-spirit, we could perhaps just use the newer, seemingly better json parsing in RGW (i.e., rapid-json)?

@soumyakoduri
Copy link
Contributor Author

@stale
Copy link

stale bot commented Jan 9, 2022

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@stale stale bot added the stale label Jan 9, 2022
@soumyakoduri
Copy link
Contributor Author

unstale

@stale stale bot removed the stale label Jan 9, 2022
@github-actions github-actions bot added the tests label Apr 6, 2022
@soumyakoduri
Copy link
Contributor Author

jenkins test windows

@soumyakoduri
Copy link
Contributor Author

jenkins test make check

@soumyakoduri
Copy link
Contributor Author

jenkins test make check arm64

@soumyakoduri soumyakoduri force-pushed the json_fix branch 2 times, most recently from 1d21a22 to 25f3049 Compare April 7, 2022 15:36
src/common/ceph_json.cc Outdated Show resolved Hide resolved
@cbodley
Copy link
Contributor

cbodley commented Apr 7, 2022

looks great, thanks. just needs a qa run?

@soumyakoduri
Copy link
Contributor Author

looks great, thanks. just needs a qa run?

Started 'rgw' tests - http://pulpito.front.sepia.ceph.com/soumyakoduri-2022-04-11_08:46:28-rgw-wip-skoduri-json-fix-distro-basic-smithi/

Please let me know if it needs any other test-suite run.

@cbodley
Copy link
Contributor

cbodley commented Apr 11, 2022

@vshankar @idryomov @neha-ojha @epuertat can you please help us evaluate this potentially-breaking fix to JSONParser in your respective components?

given input like 312CNV15CC2ZN44IPB24A, we'll now parse this as the string "312CNV15CC2ZN44IPB24A" instead of the integer 312

it's hard to know what this change could break, so i didn't want to merge it before the quincy release. but now seems like a good time to try it, with a whole release cycle to identify any regressions

does anyone object to this approach? if not, could i request your assistance in running this through your teuthology suites?

Copy link
Member

@epuertat epuertat left a comment

Choose a reason for hiding this comment

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

LGTM! @cbodley I any impact to the dashboard it'll be definitely positive.

JSONFormattable::set calls JSONParser::parse() to check if the given string
is a valid JSON object, which internally uses json_spirit::read to determine
the string type and copy it into data.
This routine incorrectly sets data type to integer if the string starts with
digit and copies only the first set of numeric values of the string.

To work-around this issue, verify if the entire string is parsed to
determine if its valid json data type.

Signed-off-by: Soumya Koduri <skoduri@redhat.com>
@soumyakoduri
Copy link
Contributor Author

jenkins test make check arm64

@soumyakoduri
Copy link
Contributor Author

jenkins test api

@soumyakoduri
Copy link
Contributor Author

jenkins test windows

@soumyakoduri
Copy link
Contributor Author

soumyakoduri commented Jul 22, 2022

latest run (for rgw) - pulpito.front.sepia.ceph.com/soumyakoduri-2022-07-22_16:46:59-rgw-json_fix-distro-default-smithi/

http://pulpito.front.sepia.ceph.com/soumyakoduri-2022-07-25_06:10:37-rgw:cloud-transition-json_fix-distro-default-smithi/

@soumyakoduri
Copy link
Contributor Author

jenkins test api

@soumyakoduri
Copy link
Contributor Author

@cbodley ceph/api tests have failed with error reported in https://tracker.ceph.com/issues/53582

@cbodley
Copy link
Contributor

cbodley commented Jul 25, 2022

jenkins test api

@cbodley cbodley merged commit 9f226dd into ceph:main Jul 25, 2022
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants