Skip to content

Commit d84a448

Browse files
author
Boy Baukema
committed
Fix for issue #87, MessageParser is too greedy
1 parent a2949a4 commit d84a448

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

library/EngineBlock/Log/Writer/Syslog/MessageParser.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,32 @@ class EngineBlock_Log_Writer_Syslog_MessageParser
77
*/
88
public function parse(array $event)
99
{
10-
$message = isset($event['message'])
11-
? $this->_normalizeMessage($event['message']) : '';
10+
$message = isset($event['message']) ? $this->_normalizeMessage($event['message']) : '';
1211

1312
preg_match_all(
14-
'/([^\]]*\[[a-zA-Z0-9 ]+\]\[[a-zA-Z0-9 ]+\](\[DUMP[^\]]*\])?)( .*)/',
15-
$message, $matches
13+
'/' .
14+
'('.
15+
'[^\]]*'. // .... (anything but a ]), followed by:
16+
'\[[a-zA-Z0-9 ]+\]'. // [ ... ]
17+
'\[[a-zA-Z0-9 ]+\]'. // [ ... ]
18+
'(\[DUMP[^\]]*\])?'. // Optionally: [DUMP ...]
19+
')'.
20+
'( .*)'. // Anything, starting with a space.
21+
'/',
22+
$message,
23+
$matches
1624
);
1725

26+
if (!isset($matches[1][0]) || !isset($matches[3][0])) {
27+
return array(
28+
'prefix' => 'P[' . time() . '][' . rand(0, 1000000) . ']',
29+
'message' => $message
30+
);
31+
}
32+
1833
return array(
19-
'prefix' => isset($matches[1][0]) ? $matches[1][0] : 'PREFIX REMOVED BY PARSER',
20-
'message' => isset($matches[3][0]) ? $matches[3][0] : 'MESSAGE REMOVED BY PARSER',
34+
'prefix' => $matches[1][0],
35+
'message' => $matches[3][0],
2136
);
2237
}
2338

@@ -30,7 +45,7 @@ public function parse(array $event)
3045
* Serialized content is prepended with '!FORMAT_[type]', this
3146
* notation is parsed by logparse.sh
3247
*
33-
* @param mixed data structure to dump
48+
* @param string $message structure to dump
3449
* @return string
3550
*/
3651
protected function _normalizeMessage($message)

library/EngineBlock/Log/Writer/Syslog/MessageSplitter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public function __construct($messageSplitSize)
1414
* messages and logs them to parent::log(). Message size is determined
1515
* by EngineBlock_Log::MESSAGE_SPLIT_SIZE.
1616
*
17-
* @param string $prefix Message prefix
18-
* @param string $message Message to log
17+
* @param string $prefix Message prefix
18+
* @param string $message Message to log
1919
* @return array
20+
* @throws InvalidArgumentException
2021
*/
2122
public function split($prefix, $message)
2223
{

0 commit comments

Comments
 (0)