Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Validate that the key parameter is a string #1486

Merged
merged 1 commit into from Aug 23, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/joomla/database/driver.php
Expand Up @@ -851,7 +851,7 @@ public function insertObject($table, &$object, $key = null)

// Update the primary key if it exists.
$id = $this->insertid();
if ($key && $id)
if ($key && $id && is_string($key))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it would be enough to do if (is_string($key) && $id). If the condition fails for $key it will fail for is_string($key) too.

Choose a reason for hiding this comment

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

But if $key would not exist you would then get a Notice: Undefined variable: key
That's why $key is tested first and cannot be left.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but $key is by default null. I can't see any case when $key is not defined in this context.

Choose a reason for hiding this comment

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

You are right (I was wrong).

{
$object->$key = $id;
}
Expand Down