1
0
Fork 0

Merge remote-tracking branch 'upstream/develop' into annando/issue8514

This commit is contained in:
Michael 2020-05-18 21:38:17 +00:00
commit 2a56370cf4
11 changed files with 109 additions and 41 deletions

View file

@ -126,7 +126,7 @@ class ForumManager
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
$entry = [
'url' => 'network?cid=' . $contact['id'],
'url' => 'network?contactid=' . $contact['id'],
'external_url' => Contact::magicLink($contact['url']),
'name' => $contact['name'],
'cid' => $contact['id'],

View file

@ -1724,7 +1724,15 @@ class BBCode
// Replace non graphical smilies for external posts
if (!$nosmile && !$for_plaintext) {
$text = Smilies::replace($text);
$text = Smilies::replace($text);
}
if (!$for_plaintext && DI::config()->get('system', 'big_emojis') && ($simple_html != self::DIASPORA)) {
$conv = html_entity_decode(str_replace([' ', "\n", "\r"], '', $text));
// Emojis are always 4 byte Unicode characters
if (!empty($conv) && (strlen($conv) / mb_strlen($conv) == 4)) {
$text = '<span style="font-size: xx-large; line-height: initial;">' . $text . '</span>';
}
}
if (!$for_plaintext) {

View file

@ -135,8 +135,9 @@ class Database
}
$this->emulate_prepares = (bool)$this->configCache->get('database', 'emulate_prepares');
$this->pdo_emulate_prepares = (bool)$this->configCache->get('database', 'pdo_emulate_prepares');
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
$this->driver = 'pdo';
$connect = "mysql:host=" . $server . ";dbname=" . $db;
@ -150,7 +151,7 @@ class Database
try {
$this->connection = @new PDO($connect, $user, $pass);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
$this->connected = true;
} catch (PDOException $e) {
$this->connected = false;
@ -504,6 +505,7 @@ class Database
$sql = "/*" . System::callstack() . " */ " . $sql;
}
$is_error = false;
$this->error = '';
$this->errorno = 0;
$this->affected_rows = 0;
@ -533,6 +535,7 @@ class Database
$this->error = $errorInfo[2];
$this->errorno = $errorInfo[1];
$retval = false;
$is_error = true;
break;
}
$this->affected_rows = $retval->rowCount();
@ -545,6 +548,7 @@ class Database
$this->error = $errorInfo[2];
$this->errorno = $errorInfo[1];
$retval = false;
$is_error = true;
break;
}
@ -562,6 +566,7 @@ class Database
$this->error = $errorInfo[2];
$this->errorno = $errorInfo[1];
$retval = false;
$is_error = true;
} else {
$retval = $stmt;
$this->affected_rows = $retval->rowCount();
@ -580,6 +585,7 @@ class Database
$this->error = $this->connection->error;
$this->errorno = $this->connection->errno;
$retval = false;
$is_error = true;
} else {
if (isset($retval->num_rows)) {
$this->affected_rows = $retval->num_rows;
@ -596,6 +602,7 @@ class Database
$this->error = $stmt->error;
$this->errorno = $stmt->errno;
$retval = false;
$is_error = true;
break;
}
@ -623,6 +630,7 @@ class Database
$this->error = $this->connection->error;
$this->errorno = $this->connection->errno;
$retval = false;
$is_error = true;
} else {
$stmt->store_result();
$retval = $stmt;
@ -631,6 +639,16 @@ class Database
break;
}
// See issue https://github.com/friendica/friendica/issues/8572
// Ensure that we always get an error message on an error.
if ($is_error && empty($this->errorno)) {
$this->errorno = -1;
}
if ($is_error && empty($this->error)) {
$this->error = 'Unknown database error';
}
// We are having an own error logging in the function "e"
if (($this->errorno != 0) && !$called_from_e) {
// We have to preserve the error code, somewhere in the logging it get lost
@ -642,8 +660,8 @@ class Database
}
$this->logger->error('DB Error', [
'code' => $this->errorno,
'error' => $this->error,
'code' => $errorno,
'error' => $error,
'callstack' => System::callstack(8),
'params' => $this->replaceParameters($sql, $args),
]);
@ -654,21 +672,21 @@ class Database
// It doesn't make sense to continue when the database connection was lost
if ($this->in_retrial) {
$this->logger->notice('Giving up retrial because of database error', [
'code' => $this->errorno,
'error' => $this->error,
'code' => $errorno,
'error' => $error,
]);
} else {
$this->logger->notice('Couldn\'t reconnect after database error', [
'code' => $this->errorno,
'error' => $this->error,
'code' => $errorno,
'error' => $error,
]);
}
exit(1);
} else {
// We try it again
$this->logger->notice('Reconnected after database error', [
'code' => $this->errorno,
'error' => $this->error,
'code' => $errorno,
'error' => $error,
]);
$this->in_retrial = true;
$ret = $this->p($sql, $args);
@ -745,8 +763,8 @@ class Database
}
$this->logger->error('DB Error', [
'code' => $this->errorno,
'error' => $this->error,
'code' => $errorno,
'error' => $error,
'callstack' => System::callstack(8),
'params' => $this->replaceParameters($sql, $params),
]);
@ -755,8 +773,8 @@ class Database
// A reconnect like in $this->p could be dangerous with modifications
if ($errorno == 2006) {
$this->logger->notice('Giving up because of database error', [
'code' => $this->errorno,
'error' => $this->error,
'code' => $errorno,
'error' => $error,
]);
exit(1);
}
@ -1029,7 +1047,7 @@ class Database
$success = $this->e("LOCK TABLES " . DBA::buildTableString($table) . " WRITE");
if ($this->driver == 'pdo') {
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
}
if (!$success) {
@ -1062,7 +1080,7 @@ class Database
$success = $this->e("UNLOCK TABLES");
if ($this->driver == 'pdo') {
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
$this->e("SET autocommit=1");
} else {
$this->connection->autocommit(true);

View file

@ -353,6 +353,15 @@ class GServer
return;
}
// Sanitize incoming data, see https://github.com/friendica/friendica/issues/8565
$data['subscribe'] = (bool)$data['subscribe'] ?? false;
if (!$data['subscribe'] || empty($data['scope']) || !in_array(strtolower($data['scope']), ['all', 'tags'])) {
$data['scope'] = '';
$data['subscribe'] = false;
$data['tags'] = [];
}
$gserver = DBA::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => Strings::normaliseLink($server_url)]);
if (!DBA::isResult($gserver)) {
return;

View file

@ -3139,7 +3139,9 @@ class Diaspora
$json = json_encode(["iv" => $b_iv, "key" => $b_aes_key]);
$encrypted_key_bundle = "";
openssl_public_encrypt($json, $encrypted_key_bundle, $pubkey);
if (!@openssl_public_encrypt($json, $encrypted_key_bundle, $pubkey)) {
return false;
}
$json_object = json_encode(
["aes_key" => base64_encode($encrypted_key_bundle),