Issues (2)

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/Lock/MySQLPDOLock.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
 * This file is part of ninja-mutex.
4
 *
5
 * (C) Kamil Dziedzic <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace NinjaMutex\Lock;
11
12
use PDO;
13
14
/**
15
 * Lock implementor using MySQL PDO driver
16
 *
17
 * @author Kamil Dziedzic <[email protected]>
18
 */
19
class MySQLPDOLock extends LockAbstract
20
{
21
    /**
22
     * MySQL connections
23
     *
24
     * @var PDO[]
25
     */
26
    protected $pdo = array();
27
28
    /**
29
     * @var string
30
     */
31
    protected $dsn;
32
    /**
33
     * @var string
34
     */
35
    protected $username;
36
    /**
37
     * @var string
38
     */
39
    protected $passwd;
40
    /**
41
     * @var array
42
     */
43
    protected $options;
44
    /**
45
     * @var string
46
     */
47
    protected $classname;
48
49
    /**
50
     * Provide data for PDO connection
51
     *
52
     * @link http://php.net/manual/en/pdo.construct.php
53
     * @param string $dsn
54
     * @param string $username [optional]
55
     * @param string $passwd   [optional]
56
     * @param array  $options  [optional]
57
     *
58
     * @param string $classname class name to create as PDO connection,
59
     *                          by default this is PDO, but in tests we can inject MockPDO
60
     */
61
    public function __construct($dsn, $username = null, $passwd = null, $options = null, $classname = 'PDO')
62
    {
63
        parent::__construct();
64
65
        $this->dsn = $dsn;
66
        $this->username = $username;
67
        $this->passwd = $passwd;
68
        $this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options can be null. However, the property $options is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
69
        $this->classname = $classname;
70
    }
71
72 10
    public function __clone()
73
    {
74 10
        parent::__clone();
75 10
        $this->pdo = array();
76 10
    }
77
78
    /**
79
     * Acquire lock
80
     *
81
     * @param  string   $name    name of lock
82
     * @param  null|int $timeout 1. null if you want blocking lock
83
     *                           2. 0 if you want just lock and go
84
     *                           3. $timeout > 0 if you want to wait for lock some time (in milliseconds)
85
     * @return bool
86
     */
87 32
    public function acquireLock($name, $timeout = null)
88
    {
89 32
        if (!$this->setupPDO($name)) {
90
            return false;
91
        }
92
93 32
        return parent::acquireLock($name, $timeout);
94
    }
95
96
    /**
97
     * @param  string $name
98
     * @param  bool   $blocking
99
     * @return bool
100
     */
101 32
    protected function getLock($name, $blocking)
102
    {
103 32
        return !$this->isLocked($name) && $this->pdo[$name]->query(
104 32
            sprintf(
105 32
                'SELECT GET_LOCK(%s, %d)',
106 32
                $this->pdo[$name]->quote($name),
107
                0
108 32
            ),
109 32
            PDO::FETCH_COLUMN,
110
            0
111 32
        )->fetch();
112
    }
113
114
    /**
115
     * Release lock
116
     *
117
     * @param  string $name name of lock
118
     * @return bool
119
     */
120 32
    public function releaseLock($name)
121
    {
122 32
        if (!$this->setupPDO($name)) {
123
            return false;
124
        }
125
126 32
        $released = (bool) $this->pdo[$name]->query(
127 32
            sprintf(
128 32
                'SELECT RELEASE_LOCK(%s)',
129 32
                $this->pdo[$name]->quote($name)
130 32
            ),
131 32
            PDO::FETCH_COLUMN,
132
            0
133 32
        )->fetch();
134
135 32
        if (!$released) {
136 4
            return false;
137
        }
138
139 32
        unset($this->pdo[$name]);
140 32
        unset($this->locks[$name]);
141
142 32
        return true;
143
    }
144
145
    /**
146
     * Check if lock is locked
147
     *
148
     * @param  string $name name of lock
149
     * @return bool
150
     */
151 32
    public function isLocked($name)
152
    {
153 32
        if (empty($this->pdo) && !$this->setupPDO($name)) {
154
            return false;
155
        }
156
157 32
        return !current($this->pdo)->query(
158 32
            sprintf(
159 32
                'SELECT IS_FREE_LOCK(%s)',
160 32
                current($this->pdo)->quote($name)
161 32
            ),
162 32
            PDO::FETCH_COLUMN,
163
            0
164 32
        )->fetch();
165
    }
166
167
    /**
168
     * @param  string $name
169
     * @return bool
170
     */
171 32
    protected function setupPDO($name)
172
    {
173 32
        if (isset($this->pdo[$name])) {
174 32
            return true;
175
        }
176
177 32
        $this->pdo[$name] = new $this->classname($this->dsn, $this->username, $this->passwd, $this->options);
178
179 32
        return true;
180
    }
181
182 10
    public function __destruct()
183
    {
184 10
        parent::__destruct();
185
186 10
        foreach($this->pdo as $name => $pdo) {
187 6
            unset($this->pdo[$name]);
188 10
        }
189 10
    }
190
}
191