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

Use sprintf('%d') like in DB2, SQLServer and Oracle to harden against wrong limit and offset #4999

Merged

Conversation

nickvergessen
Copy link
Contributor

@nickvergessen nickvergessen commented Nov 19, 2021

Q A
Type bug
BC Break no
Fixed issues Follow up to #4984

Summary

In Oracle, SQLServer and DB2 the limit and offset are handled via a %d in a sprintf() call already, adding this to the other platforms here should prevent further issues in case #4984 is ever reverted by accident again.

@@ -765,7 +765,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit === null && $offset > 0) {
return $query . ' LIMIT -1 OFFSET ' . $offset;
return $query . sprintf(' LIMIT -1 OFFSET %d', $offset);
Copy link
Member

Choose a reason for hiding this comment

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

Should $query also be moved under sprintf()? This way, we'll have one variable / memory allocation fewer .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is in a return line it shouldn't really matter anymore.

Copy link
Member

Choose a reason for hiding this comment

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

It still does. In order to return a value, the interpreter needs to allocate a new zval, copy the value of $query there, then append the value returned by sprintf(), then return it. If it's just sprintf(), this could be avoided.

We're of course not trying to save CPU ticks here but a combination of sprintf() and . on the same line looks dirty to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

What about the $query .= sprintf in all the other platforms, they are okay?

@morozov morozov changed the title Use sprintf('%d') like in DB2, SQLServer and Oracle to harden against… Use sprintf('%d') like in DB2, SQLServer and Oracle to harden against wrong limit and offset Nov 19, 2021
@morozov morozov added this to the 3.1.5 milestone Nov 19, 2021
@morozov
Copy link
Member

morozov commented Nov 19, 2021

Since it's not a bugfix but is more of an improvement, should this be retargeted against 3.2.x?

@nickvergessen
Copy link
Contributor Author

I can rebase on 3.2.x if you want, but since it's a hardening to a security related problem I thought it might make sense to have it there.

@derrabus
Copy link
Member

The actual security problem is solved already, at least to my knowledge. So let's do the hardening on the next feature release.

@derrabus derrabus modified the milestones: 3.1.5, 3.2.0 Nov 22, 2021
@derrabus derrabus changed the base branch from 3.1.x to 3.2.x November 22, 2021 08:48
@morozov
Copy link
Member

morozov commented Nov 22, 2021

@nickvergessen please rebase on top of 3.2.x to allow all required builds to pass.

… wrong limit and offset

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen nickvergessen force-pushed the sanitize-limit-parameters-like-in-oracle branch from 9e6d5c5 to 16de953 Compare November 23, 2021 07:44
@nickvergessen
Copy link
Contributor Author

please rebase on top of 3.2.x to allow all required builds to pass.

Rebased

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

LGTM, the failing CI is unrelated to these changes.

@morozov morozov merged commit 3ef4db2 into doctrine:3.2.x Nov 23, 2021
@nickvergessen nickvergessen deleted the sanitize-limit-parameters-like-in-oracle branch November 23, 2021 17:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants