Skip to content

Commit

Permalink
fix #1647 rand()をmt_rand()に変更 (#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
yama committed Apr 10, 2021
1 parent 43723c3 commit 154718d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/Baser/Controller/BcAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,11 @@ protected function convertBetweenCondition($fieldName, $value)
*/
protected function generatePassword($len = 8)
{
srand((double)microtime() * 1000000);
mt_srand((double)microtime() * 1000000);
$seed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$password = "";
while($len--) {
$pos = rand(0, 61);
$pos = mt_rand(0, 61);
$password .= $seed[$pos];
}
return $password;
Expand Down
4 changes: 2 additions & 2 deletions lib/Baser/Controller/Component/BcManagerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function setSecuritySalt($length = 40)
$keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$randkey = "";
for($i = 0; $i < $length; $i++) {
$randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
$randkey .= $keyset[mt_rand(0, strlen($keyset) - 1)];
}
Configure::write('Security.salt', $randkey);
return $randkey;
Expand All @@ -555,7 +555,7 @@ public function setSecurityCipherSeed($length = 29)
$keyset = "0123456789";
$randkey = "";
for($i = 0; $i < $length; $i++) {
$randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
$randkey .= $keyset[mt_rand(0, strlen($keyset) - 1)];
}
Configure::write('Security.cipherSeed', $randkey);
return $randkey;
Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/Controller/InstallationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ protected function _testConnectDb($config)
}

/* 一時的にテーブルを作成できるかテスト */
$randomtablename = 'deleteme' . rand(100, 100000);
$randomtablename = 'deleteme' . mt_rand(100, 100000);
$result = $db->execute("CREATE TABLE $randomtablename (a varchar(10))");


Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/Vendor/ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getVisitorId($guid, $account, $userAgent, $cookie) {

// Get a random number string.
function getRandomNumber() {
return rand(0, 0x7fffffff);
return mt_rand(0, 0x7fffffff);
}

// Writes the bytes of a 1x1 transparent gif into the response.
Expand Down
6 changes: 3 additions & 3 deletions lib/Baser/View/Helper/BcFreezeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ public function image($fieldName, $attributes = [], $imageAttributes = [])

// 確認画面
if (!empty($this->request->data[$model][$field]['name'])) {
$path = "tmp" . DS . Inflector::underscore($model) . DS . "img" . DS . $field . $imageAttributes['ext'] . "?" . rand();
$path = "tmp" . DS . Inflector::underscore($model) . DS . "img" . DS . $field . $imageAttributes['ext'] . "?" . mt_rand();
unset($imageAttributes['ext']);
$output = parent::text($fieldName . "_exists", $attributes);
$output .= sprintf($this->Html->_tags['image'], $path, $this->Html->_parseAttributes($imageAttributes));
return $output;
// 通常表示
} else {
if (!empty($this->request->data[$model][$field . '_exists'])) {
$path = DS . $imageAttributes['dir'] . DS . Inflector::tableize($model) . DS . $imageAttributes['id'] . DS . $field . "." . $imageAttributes['ext'] . "?" . rand();
$path = DS . $imageAttributes['dir'] . DS . Inflector::tableize($model) . DS . $imageAttributes['id'] . DS . $field . "." . $imageAttributes['ext'] . "?" . mt_rand();
unset($imageAttributes['ext']);
return sprintf($this->Html->_tags['image'], $path, $this->Html->_parseAttributes($imageAttributes));
} else {
Expand All @@ -442,7 +442,7 @@ public function image($fieldName, $attributes = [], $imageAttributes = [])
}
} else {
if (!empty($this->request->data[$model][$field . '_exists'])) {
$path = DS . $imageAttributes['dir'] . DS . Inflector::tableize($model) . DS . $imageAttributes['id'] . DS . $field . "." . $imageAttributes['ext'] . "?" . rand();
$path = DS . $imageAttributes['dir'] . DS . Inflector::tableize($model) . DS . $imageAttributes['id'] . DS . $field . "." . $imageAttributes['ext'] . "?" . mt_rand();
unset($imageAttributes['ext']);
$output = sprintf($this->Html->_tags['image'], $path, $this->Html->_parseAttributes($imageAttributes));
$output .= "<br />" . $this->checkbox($fieldName . "_delete", ['label' => __d('baser', '削除する')]);
Expand Down
8 changes: 4 additions & 4 deletions lib/Baser/View/Helper/BcUploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,21 +350,21 @@ public function uploadImage($fieldName, $fileName, $options = [])

if ($fileExists || $options['force']) {
if ($check && !$mostSizeExists) {
$mostSizeUrl = $fileUrl . $subdir . $imgPrefix . $basename . $imgSuffix . '.' . $ext . '?' . rand();
$mostSizeUrl = $fileUrl . $subdir . $imgPrefix . $basename . $imgSuffix . '.' . $ext . '?' . mt_rand();
$mostSizeExists = true;
} elseif (!$mostSizeExists && !$maxSizeExists) {
$maxSizeUrl = $fileUrl . $subdir . $imgPrefix . $basename . $imgSuffix . '.' . $ext . '?' . rand();
$maxSizeUrl = $fileUrl . $subdir . $imgPrefix . $basename . $imgSuffix . '.' . $ext . '?' . mt_rand();
$maxSizeExists = true;
}
}
}
}

if (!isset($mostSizeUrl)) {
$mostSizeUrl = $fileUrl . $fileName . '?' . rand();
$mostSizeUrl = $fileUrl . $fileName . '?' . mt_rand();
}
if (!isset($maxSizeUrl)) {
$maxSizeUrl = $fileUrl . $fileName . '?' . rand();
$maxSizeUrl = $fileUrl . $fileName . '?' . mt_rand();
}
}

Expand Down

0 comments on commit 154718d

Please sign in to comment.