Issues (27)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Weew/Console/CommandExecutionLock.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Weew\Console;
4
5
use Weew\Console\Exceptions\CommandIsAlreadyRunningException;
6
use Weew\ConsoleArguments\ICommand;
7
8
class CommandExecutionLock implements ICommandExecutionLock {
9
    /**
10
     * @var array
11
     */
12
    protected $locks = [];
13
14
    /**
15
     * CommandExecutionLock constructor.
16
     */
17
    public function __construct() {
18
        $this->handleShutdowns();
19
    }
20
21
    /**
22
     * @param ICommand $command
23
     * @param bool $allowParallelism
24
     *
25
     * @return string
26
     */
27
    public function lockCommand(ICommand $command, $allowParallelism = true) {
28
        if ($command->isParallel() && $allowParallelism) {
29
            return;
30
        }
31
32
        if ($this->isLocked($command->getName())) {
33
            throw new CommandIsAlreadyRunningException(s(
34
                'Command "%s" is already being executed. ' .
35
                'Parallel execution for this command has been forbidden. ' .
36
                'This is the corresponding lock file "%s".',
37
                $command->getName(),
38
                $this->getLockName($command->getName())
39
            ));
40
        }
41
42
        return $this->createLock($command->getName());
43
    }
44
45
    /**
46
     * @param ICommand $command
47
     */
48
    public function unlockCommand(ICommand $command) {
49
        $this->deleteLock($command->getName());
50
    }
51
52
    /**
53
     * Delete all locks created by this particular instance.
54
     */
55
    public function unlockAllCommands() {
56
        $this->deleteAllLocks();
57
    }
58
59
    /**
60
     * Handle shutdown events and clean up lock files.
61
     */
62
    protected function handleShutdowns() {
63
        declare(ticks = 1);
64
65
        $self = $this;
66
67
        $cleanup = function($signal = null) use ($self) {
68
            if ($signal === SIGTERM) {
69
                fprintf(STDERR, 'Received SIGTERM...');
70
            } else if ($signal === SIGINT) {
71
                fprintf(STDERR, 'Received SIGINT...');
72
            } else if ($signal === SIGTSTP) {
73
                fprintf(STDERR, 'Received SIGTSTP...');
74
            }
75
76
            $self->deleteAllLocks();
77
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method handleShutdowns() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
78
        };
79
80
        if (extension_loaded('pcntl')) {
81
            pcntl_signal(SIGTERM, $cleanup, false);
82
            pcntl_signal(SIGINT, $cleanup, false);
83
            pcntl_signal(SIGTSTP, $cleanup, false);
84
        }
85
86
        register_shutdown_function($cleanup);
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    protected function getLockFileBaseName() {
93
        return path(sys_get_temp_dir(), md5(__DIR__), 'console_lock');
94
    }
95
96
    /**
97
     * @param string $value
98
     *
99
     * @return string
100
     */
101
    protected function getLockName($value) {
102
        return s('%s_%s', $this->getLockFileBaseName(), md5($value));
103
    }
104
105
    /**
106
     * @param string $value
107
     *
108
     * @return string
109
     */
110
    protected function createLock($value) {
111
        $lockFile = $this->getLockName($value);
112
        file_create($lockFile);
113
        $this->locks[$value] = $lockFile;
114
115
        return $lockFile;
116
    }
117
118
    /**
119
     * @param string $value
120
     */
121
    protected function deleteLock($value) {
122
        file_delete($this->getLockName($value));
123
        unset($this->locks[$value]);
124
    }
125
126
    /**
127
     * Remove all locks for commands called trough
128
     * this particular lock instance.
129
     */
130
    protected function deleteAllLocks() {
131
        foreach ($this->locks as $commandName => $lockFile) {
132
            $this->deleteLock($commandName);
133
        }
134
    }
135
136
    /**
137
     * @param string $value
138
     *
139
     * @return bool
140
     */
141
    protected function isLocked($value) {
142
        return file_exists($this->getLockName($value));
143
    }
144
}
145