Issues (1)

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/LogIterator.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
/*
4
 * (c) Mantas Varatiejus <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace MVar\LogParser;
11
12
use MVar\LogParser\Exception\MatchException;
13
use MVar\LogParser\Exception\ParserException;
14
15
/**
16
 * This is the class that helps to iterate through log file.
17
 */
18
class LogIterator implements \Iterator
19
{
20
    /**
21
     * @var LineParserInterface
22
     */
23
    private $parser;
24
25
    /**
26
     * @var string
27
     */
28
    private $logFile;
29
30
    /**
31
     * @var resource
32
     */
33
    private $fileHandler;
34
35
    /**
36
     * @var string
37
     */
38
    private $currentLine;
39
40
    /**
41
     * @var bool
42
     */
43
    private $skipEmptyLines;
44
45
    /**
46
     * Constructor.
47
     *
48
     * @param string              $logFile
49
     * @param LineParserInterface $parser
50
     * @param bool                $skipEmptyLines
51
     */
52 5
    public function __construct($logFile, $parser, $skipEmptyLines = true)
53
    {
54 5
        $this->logFile = $logFile;
55 5
        $this->parser = $parser;
56 5
        $this->skipEmptyLines = $skipEmptyLines;
57 5
    }
58
59
    /**
60
     * Destructor.
61
     */
62 5
    public function __destruct()
63
    {
64 5
        @fclose($this->fileHandler);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
65 5
    }
66
67
    /**
68
     * Returns file handler.
69
     *
70
     * @return resource
71
     * @throws ParserException
72
     */
73 5
    protected function getFileHandler()
74
    {
75 5
        if ($this->fileHandler === null) {
76 5
            $fileHandler = @fopen($this->logFile, 'r');
77
78 5
            if ($fileHandler === false) {
79 1
                throw new ParserException('Can not open log file.');
80
            }
81
82 4
            $this->fileHandler = $fileHandler;
83 4
        }
84
85 4
        return $this->fileHandler;
86
    }
87
88
    /**
89
     * Reads single line from file.
90
     *
91
     * @throws ParserException
92
     */
93 4
    protected function readLine()
94
    {
95 4
        $buffer = '';
96
97 4
        while ($buffer === '') {
98 4
            if (($buffer = fgets($this->getFileHandler())) === false) {
99 4
                $this->currentLine = null;
100
101 4
                return;
102
            }
103 4
            $buffer = trim($buffer, "\n\r\0");
104
105 4
            if (!$this->skipEmptyLines) {
106 1
                break;
107
            }
108 3
        }
109
110 4
        $this->currentLine = $buffer;
111 4
    }
112
113
    /**
114
     * Returns parsed current line.
115
     *
116
     * @return array|null
117
     */
118 4
    public function current()
119
    {
120 4
        if ($this->currentLine === null) {
121 4
            $this->readLine();
122 4
        }
123
124
        try {
125 4
            $data = $this->parser->parseLine($this->currentLine);
126 4
        } catch (MatchException $exception) {
127 1
            $data = null;
128
        }
129
130 4
        return $data;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136 4
    public function next()
137
    {
138 4
        $this->readLine();
139 4
    }
140
141
    /**
142
     * Returns current line
143
     *
144
     * @return string
145
     */
146 2
    public function key()
147
    {
148 2
        return $this->currentLine;
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154 4
    public function valid()
155
    {
156 4
        return !feof($this->getFileHandler()) || $this->currentLine;
157
    }
158
159
    /**
160
     * {@inheritdoc}
161
     */
162 5
    public function rewind()
163
    {
164 5
        rewind($this->getFileHandler());
165 4
    }
166
}
167