Issues (25)

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/Semaphore.php (2 issues)

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
 * Created by PhpStorm.
4
 * User: Jenner
5
 * Date: 2015/8/12
6
 * Time: 20:52
7
 */
8
9
namespace Jenner\SimpleFork\Lock;
10
11
12
/**
13
 * sem lock
14
 *
15
 * @package Jenner\SimpleFork\Lock
16
 */
17
class Semaphore implements LockInterface
18
{
19
    /**
20
     * @var
21
     */
22
    private $lock_id;
23
    /**
24
     * @var bool
25
     */
26
    private $locked = false;
27
28
    /**
29
     * init a lock
30
     *
31
     * @param $key
32
     * @param $count
33
     * @throws \RuntimeException
34
     */
35 9
    private function __construct($key, $count = 1)
36
    {
37 9
        if (($this->lock_id = sem_get($this->_stringToSemKey($key), $count)) === false) {
38
            throw new \RuntimeException("Cannot create semaphore for key: {$key}");
39
        }
40 9
    }
41
42
    /**
43
     * Semaphore requires a numeric value as the key
44
     *
45
     * @param $identifier
46
     * @return int
47
     */
48 9
    protected function _stringToSemKey($identifier)
49
    {
50 9
        $md5 = md5($identifier);
51 9
        $key = 0;
52 9
        for ($i = 0; $i < 32; $i++) {
53 9
            $key += ord($md5{$i}) * $i;
54 9
        }
55 9
        return $key;
56
    }
57
58
    /**
59
     * create a lock instance
60
     *
61
     * @param $key
62
     * @return Semaphore
63
     */
64 9
    public static function create($key)
65
    {
66 9
        return new Semaphore($key);
67
    }
68
69
    /**
70
     * release lock
71
     *
72
     * @throws \RuntimeException
73
     */
74 9
    public function __destruct()
75
    {
76 9
        if ($this->isLocked()) {
77 3
            $this->release();
78 3
        }
79 9
    }
80
81
    /**
82
     * is locked
83
     *
84
     * @return bool
85
     */
86 9
    public function isLocked()
87
    {
88 9
        return $this->locked === true ? true : false;
89
    }
90
91
    /**
92
     * release lock
93
     *
94
     * @return bool
95
     * @throws \RuntimeException
96
     */
97 9 View Code Duplication
    public function release()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99 9
        if (!$this->locked) {
100 3
            throw new \RuntimeException("release a non lock");
101
        }
102
103 6
        if (!sem_release($this->lock_id)) {
104
            return false;
105
        }
106 6
        $this->locked = false;
107
108 6
        return true;
109
    }
110
111
    /**
112
     * get a lock
113
     *
114
     * @param bool $blocking
115
     * @return bool
116
     */
117 6
    public function acquire($blocking = true)
118
    {
119 6
        if ($this->locked) {
120 3
            throw new \RuntimeException('already lock by yourself');
121
        }
122
123 6
        if ($blocking === false) {
124
            if (version_compare(PHP_VERSION, '5.6.0') < 0) {
125
                throw new \RuntimeException('php version is at least 5.6.0 for param blocking');
126
            }
127
            if (!sem_acquire($this->lock_id, true)) {
128
                return false;
129
            }
130
            $this->locked = true;
131
132
            return true;
133
        }
134
135 6
        if (!sem_acquire($this->lock_id)) {
136
            return false;
137
        }
138 6
        $this->locked = true;
139
140 6
        return true;
141
    }
142
143
    /**
144
     * remove the semaphore resource
145
     *
146
     * @return bool
147
     */
148 View Code Duplication
    public function remove()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        if ($this->locked) {
151
            throw new \RuntimeException('can not remove a locked semaphore resource');
152
        }
153
        if (!is_resource($this->lock_id)) {
154
            throw new \RuntimeException('can not remove a empty semaphore resource');
155
        }
156
157
        if (!sem_release($this->lock_id)) {
158
            return false;
159
        }
160
161
        return true;
162
    }
163
}