Remove unsafe uses of reset

This commit is contained in:
Stephen Paul Weber 2013-01-20 21:49:48 -05:00
parent 4263d03188
commit 7a1510f2e1

View File

@ -365,7 +365,8 @@ class OpenPGP_Packet {
return array($tag, 3, (($len - 192) << 8) + ord($input[2]) + 192); return array($tag, 3, (($len - 192) << 8) + ord($input[2]) + 192);
} }
if($len == 255) { // Five octet length if($len == 255) { // Five octet length
return array($tag, 6, reset(unpack('N', substr($input, 2, 4)))); $unpacked = unpack('N', substr($input, 2, 4));
return array($tag, 6, reset($unpacked));
} }
// TODO: Partial body lengths. 1 << ($len & 0x1F) // TODO: Partial body lengths. 1 << ($len & 0x1F)
} }
@ -445,7 +446,8 @@ class OpenPGP_Packet {
* @see http://php.net/manual/en/function.unpack.php * @see http://php.net/manual/en/function.unpack.php
*/ */
function read_unpacked($count, $format) { function read_unpacked($count, $format) {
return reset(unpack($format, $this->read_bytes($count))); $unpacked = unpack($format, $this->read_bytes($count));
return reset($unpacked);
} }
function read_byte() { function read_byte() {
@ -535,7 +537,8 @@ class OpenPGP_SignaturePacket extends OpenPGP_Packet {
$this->trailer = $this->body(true); $this->trailer = $this->body(true);
$signer = $signers[$this->key_algorithm_name()][$this->hash_algorithm_name()]; $signer = $signers[$this->key_algorithm_name()][$this->hash_algorithm_name()];
$this->data = call_user_func($signer, $this->data.$this->trailer); $this->data = call_user_func($signer, $this->data.$this->trailer);
$this->hash_head = reset(unpack('n', substr($this->data, 0, 2))); $unpacked = unpack('n', substr($this->data, 0, 2));
$this->hash_head = reset($unpacked);
} }
function read() { function read() {
@ -700,7 +703,8 @@ class OpenPGP_SignaturePacket extends OpenPGP_Packet {
} }
if($len == 255) { // Five octet length if($len == 255) { // Five octet length
$length_of_length = 5; $length_of_length = 5;
$len = reset(unpack('N', substr($input, 1, 4))); $unpacked = unpack('N', substr($input, 1, 4));
$len = reset($unpacked);
} }
$input = substr($input, $length_of_length); // Chop off length header $input = substr($input, $length_of_length); // Chop off length header
$tag = ord($input[0]); $tag = ord($input[0]);