LukeCarrier /
moodle-componentmgr
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Moodle component manager. |
||
| 5 | * |
||
| 6 | * @author Luke Carrier <[email protected]> |
||
| 7 | * @copyright 2016 Luke Carrier |
||
| 8 | * @license GPL-3.0+ |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace ComponentManager\PackageSource; |
||
| 12 | |||
| 13 | use ComponentManager\ComponentSource\GitComponentSource; |
||
| 14 | use ComponentManager\Exception\RetryablePackageFailureException; |
||
| 15 | use ComponentManager\Exception\VersionControlException; |
||
| 16 | use ComponentManager\ResolvedComponentVersion; |
||
| 17 | use ComponentManager\VersionControl\Git\GitRemote; |
||
| 18 | use ComponentManager\VersionControl\Git\GitVersionControl; |
||
| 19 | use Psr\Log\LoggerInterface; |
||
| 20 | use Symfony\Component\Filesystem\Filesystem; |
||
| 21 | use Symfony\Component\Process\Exception\ProcessTimedOutException; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Version control package source. |
||
| 25 | */ |
||
| 26 | class GitPackageSource extends AbstractPackageSource |
||
| 27 | implements PackageSource { |
||
| 28 | /** |
||
| 29 | * @inheritdoc PackageSource |
||
| 30 | */ |
||
| 31 | public function getId() { |
||
| 32 | return 'Git'; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc PackageSource |
||
| 37 | */ |
||
| 38 | public function getName() { |
||
| 39 | return 'Git repository'; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @inheritdoc PackageSource |
||
| 44 | */ |
||
| 45 | public function obtainPackage($tempDirectory, $timeout, |
||
| 46 | ResolvedComponentVersion $resolvedComponentVersion, |
||
| 47 | Filesystem $filesystem, |
||
| 48 | LoggerInterface $logger) { |
||
| 49 | $componentVersion = $resolvedComponentVersion->getVersion(); |
||
| 50 | |||
| 51 | $sources = $componentVersion->getSources(); |
||
| 52 | foreach ($sources as $source) { |
||
| 53 | if ($source instanceof GitComponentSource) { |
||
| 54 | $repositoryPath = $this->platform->joinPaths([ |
||
| 55 | $tempDirectory, |
||
| 56 | 'repo', |
||
| 57 | ]); |
||
| 58 | $indexPath = $this->platform->joinPaths([ |
||
| 59 | $tempDirectory, |
||
| 60 | 'index', |
||
| 61 | ]); |
||
| 62 | $repositoryUri = $source->getRepositoryUri(); |
||
| 63 | |||
| 64 | $finalRef = $resolvedComponentVersion->getFinalVersion(); |
||
| 65 | $ref = $source->getRef(); |
||
| 66 | if ($finalRef !== null) { |
||
| 67 | $logger->info('Installing pinned version', [ |
||
| 68 | 'ref' => $ref, |
||
| 69 | 'finalRef' => $finalRef, |
||
| 70 | ]); |
||
| 71 | |||
| 72 | $installRef = $finalRef; |
||
| 73 | } else { |
||
| 74 | $installRef = $ref; |
||
| 75 | } |
||
| 76 | |||
| 77 | // These paths must be removed in the event of a failure/retry |
||
| 78 | $paths = [ |
||
| 79 | $repositoryPath, |
||
| 80 | $indexPath, |
||
| 81 | ]; |
||
| 82 | $filesystem->mkdir($paths); |
||
|
0 ignored issues
–
show
|
|||
| 83 | |||
| 84 | $logger->debug('Trying git repository source', [ |
||
| 85 | 'repositoryPath' => $repositoryPath, |
||
| 86 | 'repositoryUri' => $repositoryUri, |
||
| 87 | 'ref' => $installRef, |
||
| 88 | 'indexPath' => $indexPath, |
||
| 89 | ]); |
||
| 90 | |||
| 91 | $repository = new GitVersionControl( |
||
| 92 | $this->platform->getExecutablePath('git'), |
||
| 93 | $repositoryPath, $timeout); |
||
| 94 | $repository->init(); |
||
| 95 | $repository->addRemote(new GitRemote('origin', $repositoryUri)); |
||
| 96 | |||
| 97 | $refsFetchOutput = $refsFetchErrors = ''; |
||
| 98 | $tagsFetchOutput = $tagsFetchErrors = ''; |
||
| 99 | try { |
||
| 100 | $refsFetchProcess = $repository->fetch(); |
||
| 101 | $refsFetchOutput = $refsFetchProcess->getOutput(); |
||
| 102 | $refsFetchErrors = $refsFetchProcess->getErrorOutput(); |
||
| 103 | |||
| 104 | $tagsFetchProcess = $repository->fetchTags(); |
||
| 105 | $refsFetchOutput = $tagsFetchProcess->getOutput(); |
||
| 106 | $refsFetchErrors = $tagsFetchProcess->getErrorOutput(); |
||
| 107 | } catch (ProcessTimedOutException $e) { |
||
| 108 | $logger->debug('Fetch stdout', [ |
||
| 109 | $refsFetchOutput, |
||
| 110 | $tagsFetchOutput, |
||
| 111 | ]); |
||
| 112 | $logger->debug('Fetch stderr', [ |
||
| 113 | $refsFetchErrors, |
||
| 114 | $tagsFetchErrors, |
||
| 115 | ]); |
||
| 116 | $filesystem->remove($paths); |
||
|
0 ignored issues
–
show
$paths is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|object<Symfony\Co...nt\Filesystem\iterable>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 117 | throw new RetryablePackageFailureException($e); |
||
|
0 ignored issues
–
show
$e is of type object<Symfony\Component...ocessTimedOutException>, but the function expects a object<Throwable>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 118 | } catch (VersionControlException $e) { |
||
| 119 | $filesystem->remove($paths); |
||
|
0 ignored issues
–
show
$paths is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|object<Symfony\Co...nt\Filesystem\iterable>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 120 | throw new RetryablePackageFailureException($e); |
||
|
0 ignored issues
–
show
$e is of type object<ComponentManager\...ersionControlException>, but the function expects a object<Throwable>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 121 | } |
||
| 122 | |||
| 123 | $repository->checkout($installRef); |
||
| 124 | $repository->checkoutIndex( |
||
| 125 | $indexPath . $this->platform->getDirectorySeparator()); |
||
| 126 | $resolvedComponentVersion->setFinalVersion(trim( |
||
| 127 | $repository->parseRevision($installRef)->getOutput())); |
||
| 128 | |||
| 129 | return $indexPath; |
||
| 130 | } else { |
||
| 131 | $logger->debug('Cannot accept component source; skipping', [ |
||
| 132 | 'componentSource' => $source, |
||
| 133 | ]); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: