Skip to content
Permalink
Browse files

Use length function

  • Loading branch information
fredriklengstrand committed Oct 4, 2019
1 parent fe84253 commit 3e9f60e1f572b67014fe611a689886ab63f2179b
@@ -32,7 +32,7 @@ function authoritypost($opts, $headers, $fp)

$postamble = "\r\n--$boundary--\r\n";

$length += strlen($preamble) + strlen($rfc822) + strlen($postamble);
$length += length($preamble) + length($rfc822) + length($postamble);

if (!$socket->send(implode("\r\n", [
"POST $uri HTTP/1.0",
@@ -49,7 +49,7 @@ function authoritypost($opts, $headers, $fp)
$b = 0;
while ($str = $fp->read(($maxMessageSize - $b < 8192) ? ($maxMessageSize - $b) : 8192)) {
if (!$socket->send($str)) return;
$b += strlen($str);
$b += length($str);
if ($b >= $maxMessageSize)
break;
}
@@ -18,7 +18,7 @@ function ctasd($senderip, $sender, $mailpath)
$request[] = "Accept-Language: en-us";
$request[] = "Accept: */*";
$request[] = "Host: 127.0.0.1";
$request[] = "Content-Length: " + strlen($body);
$request[] = "Content-Length: " + length($body);
$request[] = "";
$request[] = $body;
$request = implode("\r\n", $request);
@@ -69,7 +69,7 @@ function ctipd($senderip)
$request[] = "Accept-Language: en-us";
$request[] = "Accept: */*";
$request[] = "Host: 127.0.0.1";
$request[] = "Content-Length: " + strlen($body);
$request[] = "Content-Length: " + length($body);
$request[] = "";
$request[] = $body;
$request = implode("\r\n", $request);
@@ -55,7 +55,7 @@ function milter_v2($opts, $senderip, $senderport, $senderhelo, $sender, $recipie

function milter_send($socket, $cmd, $data = "")
{
return $socket->send(pack("N", 1 + strlen($data)).$cmd.$data);
return $socket->send(pack("N", 1 + length($data)).$cmd.$data);
}

function milter_read($socket, $parse)
@@ -55,7 +55,7 @@ class rspamd
$b = 0;
while ($str = $fp->read(($maxMessageSize - $b < 8192) ? ($maxMessageSize - $b) : 8192)) {
if (!$socket->send($str)) return;
$b += strlen($str);
$b += length($str);
if ($b >= $maxMessageSize)
break;
}
@@ -135,7 +135,7 @@ class SPAMC
$s = $this->mail->seek(0, "SEEK_END");
$this->mail->seek(0, "SEEK_SET");
if ($this->sender)
$s += strlen("Return-Path: <".$this->sender.">\r\n");
$s += length("Return-Path: <".$this->sender.">\r\n");
return $s;
}
}
@@ -65,7 +65,7 @@ class VADE
$b = 0;
while ($str = $fp->read(($this->msgsize - $b < 8192) ? ($this->msgsize - $b) : 8192)) {
if (!$socket->send($str)) return ["error" => "An error occurred when sending data"];
$b += strlen($str);
$b += length($str);
if ($b >= $this->msgsize)
break;
}
@@ -1,9 +1,9 @@
// Knuth shuffle (O(n))
function array_shuffle($l)
{
$count = count($l);
$length = length($l);
$i = 1;
while ($i < $count)
while ($i < $length)
{
$r = random_number(0, $i);
if ($r != $i) {
@@ -19,13 +19,13 @@ class ARC
"tl" => $tl,
"h" => $header,
];
if (count($arcset) > 50) return [
if (length($arcset) > 50) return [
"status" => "fail",
"error" => "Too many ARC-Seal headers",
];
}

if (count($arcset) == 0) return ["status" => "none"];
if (length($arcset) == 0) return ["status" => "none"];

foreach (MIME("0")->getHeaders("ARC-Message-Signature", ["field" => true]) as $x => $header)
{
@@ -43,7 +43,7 @@ class ARC
"tl" => $tl,
"h" => $header,
];
if (count($arcset) > 50) return [
if (length($arcset) > 50) return [
"status" => "fail",
"error" => "Too many ARC-Message-Signature headers",
];
@@ -65,21 +65,21 @@ class ARC
"h" => $header,
"ar" => $h[2],
];
if (count($arcset) > 50) return [
if (length($arcset) > 50) return [
"status" => "fail",
"error" => "Too many ARC-Authentication-Results headers",
];
}

for ($i = 1; $i <= count($arcset); ++$i)
for ($i = 1; $i <= length($arcset); ++$i)
{
// 4.2.2
if (!isset($arcset[$i])) return [
"status" => "fail",
"error" => "ARC set (i=$i) is missing",
];
// 4.2.1
if (count($arcset[$i]) != 3) return [
if (length($arcset[$i]) != 3) return [
"status" => "fail",
"error" => "ARC set (i=$i) is missing a header",
];
@@ -94,15 +94,15 @@ class ARC
];
}

$highest = count($arcset);
$highest = length($arcset);

$dkim = DKIMVerify($arcset[$highest]["ams"]["h"]);
if ($dkim["result"] != "pass") return [
"status" => "fail",
"error" => "ARC-Message-Signature (i=$highest) could not be verified: " . $dkim["error"]
];

$oldestpass = count($arcset) - 1;
$oldestpass = length($arcset) - 1;
for (; $oldestpass > 0; --$oldestpass)
{
$dkim = DKIMVerify($arcset[$oldestpass]["ams"]["h"]);
@@ -113,7 +113,7 @@ class ARC
}
}

for ($i = count($arcset); $i >= 1; --$i)
for ($i = length($arcset); $i >= 1; --$i)
{
$data = "";
for ($x = 1; $x <= $i; ++$x)
@@ -159,7 +159,7 @@ class ARC
return [
"status" => "pass",
"oldestpass" => $oldestpass,
"instance" => count($arcset),
"instance" => length($arcset),
"domains" => array_map(function ($set) { return $set["seal"]["tl"]["d"]; }, $arcset),
"ar1" => $arcset[1]["aar"]["ar"],
"arcset" => $arcset,
@@ -188,7 +188,7 @@ class ARC
$headers[] = ["ARC-Seal", "i=$i; a=rsa-sha256; t=$t; cv=$cv;\r\n\td=$domain; s=$selector;\r\n\tb="];

$data = "";
for ($x = 1; $x <= count($chain["arcset"]); ++$x)
for ($x = 1; $x <= length($chain["arcset"]); ++$x)
{
$arcset = $chain["arcset"];
$data .= static::header_canonicalization("ARC-Authentication-Results:".$arcset[$x]["aar"]["h"]) . "\r\n";
@@ -214,14 +214,14 @@ class ARC

static function split_header_b($key)
{
$l = strlen($key);
$l = length($key);
$result = "";
$p = 77;
for ($i = 0; $i < $l; $i += $p)
{
if ($i > 0) $p = 78;
$result .= $key[$i:$i + $p];
if ($i + $p < strlen($key))
if ($i + $p < length($key))
$result .= "\r\n\t ";
}
return $result;
@@ -243,7 +243,7 @@ class ARC
if (implode("", $result[0]) != $list)
return none;
$tags = [];
for ($i = 0; $i < count($result[1]); $i++)
for ($i = 0; $i < length($result[1]); $i++)
{
if (isset($tags[$result[1][$i]]))
return none;
@@ -74,7 +74,7 @@ class AuthenticationResults
{
$result = gethostname().";";

if (count($this->authresult))
if (length($this->authresult))
{
foreach ($this->authresult as $method => $i)
{
@@ -77,7 +77,7 @@ class Memcached
}
$values = [];
$offset = 0;
while ($offset < strlen($data))
while ($offset < length($data))
{
$lineEnd = str_find($data, "\r\n", $offset) - $offset;
$line = str_slice($data, $offset, $lineEnd);
@@ -100,7 +100,7 @@ class Memcached

private function __store($command, $key, $flags, $exptime, $value)
{
$bytes = strlen($value);
$bytes = length($value);
if (!$this->socket->send("$command $key $flags $exptime $bytes\r\n$value\r\n")) return;
if (!$resp = $this->socket->recv(8192)) return;
$resp = str_strip($resp);
@@ -50,7 +50,7 @@ class MongoDB
$numberToReturn,
$query,
$returnFieldsSelector);
$this->socket->send(pack("V", 4 + strlen($data)) . $data);
$this->socket->send(pack("V", 4 + length($data)) . $data);

$result = [];
forever
@@ -67,7 +67,7 @@ class MongoDB
if ($chunk == none)
return none;
$data .= $chunk;
$len -= strlen($chunk);
$len -= length($chunk);
$chunk = "";
}

@@ -94,7 +94,7 @@ class MongoDB
] = unpack("VVVVV", $data, $i);
$i += 20;

while ($i < strlen($data))
while ($i < length($data))
{
$l = unpack("V", $data, $i)[0];
$result[] = $this->bson_decode($data, $i);
@@ -124,7 +124,7 @@ class MongoDB
$limit,
$cursorID1,
$cursorID2);
$this->socket->send(pack("V", 4 + strlen($data)) . $data);
$this->socket->send(pack("V", 4 + length($data)) . $data);
}

return $result;
@@ -151,7 +151,7 @@ class MongoDB

if ($i == $l)
{
if (count($stack) == 1)
if (length($stack) == 1)
return $output;
$last = $stack[-1:][0];
$stack = $stack[:-1];
@@ -181,7 +181,7 @@ class MongoDB
}

[$key] = unpack("Z*", $data, $i);
$i += strlen($key) + 1;
$i += length($key) + 1;

switch ($type)
{
@@ -230,7 +230,7 @@ class MongoDB
break;
case 0x0b:
[$pattern, $options] = unpack("Z*Z*", $data, $i);
$i += strlen($pattern) + strlen($options) + 2;
$i += length($pattern) + length($options) + 2;
echo "unsupported BSON type (Regular expression)";
break;
case 0x0c:
@@ -292,29 +292,29 @@ class MongoDB
{
["k" => $k, "d" => $d, "i" => $i, "o" => $o] = $stack[-1:][0];

if ($i == count($k))
if ($i == length($k))
{
if (count($stack) == 1)
return pack("Va*x", 4 + strlen($stack[0]["o"]) + 1, $stack[0]["o"]);
if (length($stack) == 1)
return pack("Va*x", 4 + length($stack[0]["o"]) + 1, $stack[0]["o"]);

$last = $stack[-1:][0];
$stack = $stack[:-1];
$head = $stack[-1:][0];
$head["o"] .= pack("Va*x", 4 + strlen($last["o"]) + 1, $last["o"]);
$head["o"] .= pack("Va*x", 4 + length($last["o"]) + 1, $last["o"]);
$stack = $stack[:-1];
$stack[] = $head;
continue;
}

$break = false;
while (!$break and $i < count($k))
while (!$break and $i < length($k))
{
$v = $d[$k[$i]];

if (is_array($v))
{
$keys = array_keys($v);
$type = (count($v) == 0 or is_number($keys[0])) ? 0x04 : 0x03;
$type = (length($v) == 0 or is_number($keys[0])) ? 0x04 : 0x03;
$stack = $stack[:-1];
$stack[] = ["k" => $k, "d" => $d, "i" => $i + 1, "o" => $o . pack("CZ*", $type, $k[$i]) ];
$stack[] = ["k" => $keys, "d" => $v, "i" => 0, "o" => ""];
@@ -327,7 +327,7 @@ class MongoDB
}
else if (is_string($v))
{
$o .= pack("CZ*VZ*", 0x02, $k[$i], strlen($v) + 1, $v);
$o .= pack("CZ*VZ*", 0x02, $k[$i], length($v) + 1, $v);
}
else if ($v == none)
{
@@ -96,7 +96,7 @@ class MySQL
if ($numcols and !([$columns] = $this->getResultsetColumns($numcols))) return;

$args = "";
if (count($params) > 0)
if (length($params) > 0)
{
$bitmap = [];
$types = "";
@@ -112,7 +112,7 @@ class MySQL
$types .= "\x0f\x00";

if ($a != none)
$values .= "\xfc".pack("va*", strlen($a), $a);
$values .= "\xfc".pack("va*", length($a), $a);
}

$args = pack("C*", ...$bitmap).pack("Ca*a*", 0x1, $types, $values);
@@ -158,7 +158,7 @@ class MySQL
if (($payload = $this->recv()) == none) return;
if ($payload == "") continue;

if (ord($payload[0]) == 0xfe and strlen($payload) < 9)
if (ord($payload[0]) == 0xfe and length($payload) < 9)
{
// make sure it's an EOF
if ($this->capabilities & 0x200)
@@ -323,7 +323,7 @@ class MySQL
if (($payload = $this->recv()) == none) return;
if ($payload == "") continue;

if (ord($payload[0]) == 0xfe and strlen($payload) < 9)
if (ord($payload[0]) == 0xfe and length($payload) < 9)
{
// make sure it's an EOF
if ($this->capabilities & 0x200)
@@ -419,7 +419,7 @@ class MySQL
if ($chunk == none)
return none;
$payload .= $chunk;
$len -= strlen($chunk);
$len -= length($chunk);
$chunk = "";
}

@@ -442,7 +442,7 @@ class MySQL

private function send($seqId, $pkt)
{
$len = strlen($pkt);
$len = length($pkt);
$l = $this->socket->send(pack("vCC", ($len & 0xffff), $len >> 16, $seqId).$pkt);
return ($l == $len + 4);
}

0 comments on commit 3e9f60e

Please sign in to comment.
You can’t perform that action at this time.