1
0
Fork 0

Fix potential bugs without expected behavior change

- Fix uninitialized variables
- Fix potentially not set variables
- Fix wrong parameter default value
- Fix method scope
- Fix missing return value
This commit is contained in:
Hypolite Petovan 2019-01-07 12:51:48 -05:00
commit 7f2dc40601
35 changed files with 87 additions and 67 deletions

View file

@ -1298,7 +1298,7 @@ function admin_page_site_post(App $a)
Config::set('system', 'banner', $banner);
}
if ($info == "") {
if (empty($info)) {
Config::delete('config', 'info');
} else {
Config::set('config', 'info', $info);

View file

@ -300,6 +300,7 @@ function dfrn_notify_content(App $a) {
break;
default:
$status = 1;
$my_id = '';
break;
}

View file

@ -34,9 +34,9 @@ function dfrn_request_init(App $a)
{
if ($a->argc > 1) {
$which = $a->argv[1];
Profile::load($a, $which);
}
Profile::load($a, $which);
return;
}
@ -168,7 +168,7 @@ function dfrn_request_post(App $a)
$r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `site-pubkey` = '%s' LIMIT 1",
intval(local_user()),
DBA::escape($dfrn_url),
$parms['key'] // this was already escaped
defaults($parms, 'key', '') // Potentially missing
);
if (DBA::isResult($r)) {
Group::addMember(User::getDefaultGroup(local_user(), $r[0]["network"]), $r[0]['id']);
@ -187,7 +187,7 @@ function dfrn_request_post(App $a)
$dfrn_request = $contact_record['request'];
}
if (strlen($dfrn_request) && strlen($confirm_key)) {
if (!empty($dfrn_request) && strlen($confirm_key)) {
Network::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key);
}

View file

@ -111,8 +111,11 @@ function directory_content(App $a)
$photo = 'photo';
}
$entries = [];
while ($rr = DBA::fetch($r)) {
while ($rr = DBA::fetch($r)) {
$itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
$profile_link = $rr['profile_url'];

View file

@ -179,21 +179,19 @@ function dirfind_content(App $a, $prefix = "") {
// Add found profiles from the global directory to the local directory
Worker::add(PRIORITY_LOW, 'DiscoverPoCo', "dirsearch", urlencode($search));
} else {
} elseif (strlen(Config::get('system','directory'))) {
$p = (($pager->getPage() != 1) ? '&p=' . $pager->getPage() : '');
if (strlen(Config::get('system','directory'))) {
$x = Network::fetchUrl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search));
}
$x = Network::fetchUrl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search));
$j = json_decode($x);
$pager->setItemsPerPage($j->items_page);
}
if (!empty($j->results)) {
$id = 0;
$entries = [];
foreach ($j->results as $jj) {
$alt_text = "";

View file

@ -29,6 +29,8 @@ function fbrowser_content(App $a)
$template_file = "filebrowser.tpl";
$o = '';
switch ($a->argv[1]) {
case "image":
$path = [["", L10n::t("Photos")]];

View file

@ -35,7 +35,7 @@ function feedtest_content(App $a)
$import_result = Feed::import($xml, $importer, $contact, $dummy, true);
$result = [
'input' => text_highlight($xml, 'xml'),
'input' => $xml,
'output' => var_export($import_result, true),
];
}

View file

@ -33,6 +33,7 @@ function help_content(App $a)
Nav::setSelected('help');
$text = '';
$filename = '';
if ($a->argc > 1) {
$path = '';

View file

@ -14,7 +14,7 @@ function ignored_init(App $a)
$message_id = intval($a->argv[1]);
}
if (!$message_id) {
if (empty($message_id)) {
exit();
}

View file

@ -41,6 +41,8 @@ function invite_post(App $a)
$message = !empty($_POST['message']) ? Strings::escapeTags(trim($_POST['message'])) : '';
$total = 0;
$invitation_only = false;
$invites_remaining = null;
if (Config::get('system', 'invitation_only')) {
$invitation_only = true;

View file

@ -1049,7 +1049,7 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network =
* Status.Net seems to require the numeric ID URL in a mention if the person isn't
* subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
*/
if (strlen($alias)) {
if (!empty($alias)) {
$newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
if (!stripos($str_tags, '[url=' . $alias . ']')) {
if (strlen($str_tags)) {

View file

@ -20,6 +20,8 @@ function msearch_post(App $a)
exit();
}
$total = 0;
$count_stmt = DBA::p(
"SELECT COUNT(*) AS `total`
FROM `profile`
@ -29,7 +31,6 @@ function msearch_post(App $a)
AND MATCH(`pub_keywords`) AGAINST (?)",
$search
);
if (DBA::isResult($count_stmt)) {
$row = DBA::fetch($count_stmt);
$total = $row['total'];

View file

@ -92,6 +92,8 @@ function notifications_content(App $a)
$notif_header = L10n::t('Notifications');
$all = false;
// Get introductions
if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
Nav::setSelected('introductions');

View file

@ -58,6 +58,8 @@ function notify_content(App $a)
return Login::form();
}
$notif_content = '';
$nm = new NotificationsManager();
$notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');

View file

@ -93,17 +93,17 @@ function openid_content(App $a) {
}
}
}
if ($nick) {
if (!empty($nick)) {
$args .= '&nickname=' . urlencode($nick);
}
elseif ($first) {
elseif (!empty($first)) {
$args .= '&nickname=' . urlencode($first);
}
if ($photosq) {
if (!empty($photosq)) {
$args .= '&photo=' . urlencode($photosq);
}
elseif ($photo) {
elseif (!empty($photo)) {
$args .= '&photo=' . urlencode($photo);
}

View file

@ -26,9 +26,9 @@ function poco_init(App $a) {
}
if ($a->argc > 1) {
$user = Strings::escapeTags(trim($a->argv[1]));
$nickname = Strings::escapeTags(trim($a->argv[1]));
}
if (empty($user)) {
if (empty($nickname)) {
$c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1");
if (!DBA::isResult($c)) {
System::httpExit(401);
@ -70,7 +70,7 @@ function poco_init(App $a) {
if (! $system_mode && ! $global) {
$users = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
DBA::escape($user)
DBA::escape($nickname)
);
if (! DBA::isResult($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) {
System::httpExit(404);

View file

@ -77,6 +77,7 @@ function suggest_content(App $a)
}
$id = 0;
$entries = [];
foreach ($r as $rr) {

View file

@ -38,7 +38,9 @@ function worker_init()
Worker::callWorker();
if ($r = Worker::workerProcess()) {
$passing_slow = false;
if ($r = Worker::workerProcess($passing_slow)) {
// On most configurations this parameter wouldn't have any effect.
// But since it doesn't destroy anything, we just try to get more execution time in any way.
set_time_limit(0);

View file

@ -63,13 +63,13 @@ function xrd_init(App $a)
}
if ($mode == 'xml') {
xrd_xml($a, $addr, $alias, $profile_url, $user);
xrd_xml($addr, $alias, $profile_url, $user);
} else {
xrd_json($a, $addr, $alias, $profile_url, $user);
xrd_json($addr, $alias, $profile_url, $user);
}
}
function xrd_json($a, $uri, $alias, $profile_url, $r)
function xrd_json($uri, $alias, $profile_url, $r)
{
$salmon_key = Salmon::salmonKey($r['spubkey']);
@ -100,7 +100,7 @@ function xrd_json($a, $uri, $alias, $profile_url, $r)
exit();
}
function xrd_xml($a, $uri, $alias, $profile_url, $r)
function xrd_xml($uri, $alias, $profile_url, $r)
{
$salmon_key = Salmon::salmonKey($r['spubkey']);