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

Fixed self-update command with non-sha1 version argument #4304

Closed

Conversation

mickaelandrieu
Copy link

Hi,
I have updated this command that have a weird behavior when we use non corrects arguments:

composer

I think the if statment shouldn't check for 2 conditions but only one on the validity of the hash, because the check between actual updated one and latest sha1 version is already done later.

@Seldaek does it solve the issue ?

Also, How to realy test it ? This command is not loaded when we are outside of "Phar" context.

@@ -83,9 +83,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl. '/version', false));
$updateVersion = $input->getArgument('version') ?: $latestVersion;

if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
if (!preg_match('{^[0-9a-f]{40}$}', $updateVersion)){
Copy link
Contributor

Choose a reason for hiding this comment

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

the condition you removed is not about comparing to the current version. It is about comparing to the latest version, to avoid displaying such message when the user has not passed the argument.

and the condition you added is wrong. It prevents using an explicit version, while it is the only valid case (passing a sha1 hash does not work unless you pass the hash of the latest version, in which case it is useless to pass it)

@mickaelandrieu
Copy link
Author

@stof this does not make sense (to me) to make a preg_match on a sha1 hash if the only accepted value is the latest (that we already know without any hash).

2 valid solutions:

  • we allow any valid hash
  • we disallow hashes

So if a version is provided and is a valid hash => DL, if not => error.
If no version argument => DL of latest.

Do you agree?

@sbuzonas
Copy link
Contributor

@mickaelandrieu to test you can compile the phar with the script in the bin dir. You need to ensure that phar.readonly is off in your php.ini when you run it.

In regards to the remark on the hash verification. There are not builds for specific hashes only the latest. Updating by specific version is useful for build servers that use a tested composer version. I do not want to blindly update my build machine to the latest version of composer. At this time we whitelist the version it's allowed to upgrade to. Allow the error to occur, and send out a notification to QA when the version no longer matches.

@alcohol
Copy link
Member

alcohol commented Jul 29, 2015

The only valid update targets are the latest version (sha), or an existing tag/release. hello-world is not a sha, so Composer assumes you specified a valid tag/release. It then fails to download it because it actually does not exist. There is no need to add further validation here in my opinion. The error is clear enough.

@mickaelandrieu
Copy link
Author

Humm... after reading your comments and have better knowledges on how composer selfupdate works. I agree with @alcohol (you, again :) ) and think it's a funny edge that don't need any update.

Thank you all, closed ;)

@Seldaek
Copy link
Member

Seldaek commented Jul 30, 2015

For the record what I meant on twitter was that if the version arg's value is update we could just make it null which would fix the typo case of composer self update. I doubt it's such a common typo though so not sure it's worth doing.

@mickaelandrieu mickaelandrieu deleted the self-update-edge-case branch July 30, 2015 21:55
@mickaelandrieu
Copy link
Author

@Seldaek agree.

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.

5 participants