TypeError in ExternalReferrer under php8

Thom Jeera via Phpwiki-talk <[email protected]> Tue, 24 Oct 2023 19:34:34 +0000
Newsgroups gmane.comp.web.wiki.phpwiki.talk
Message-ID <6ZpWMpHfeLKrAvU2L75NVL50dbOPPevmooZehdEvSNfWro1wb_YIvQWFYn_Gybn9W3KjZAJmsM-Ecz7OAH_yD1kUm7ud_fWc2GzehGTV1LA=@proton.me>
Hi - I'm running phpwiki-1.6.2 on php 8.2.11.

I saw an error when someone clicked a phpwiki link from within a gmail app - see bottom of email. The 'google.' in the referer triggers the external referrer code, which breaks under php8 (seems ok in php5 - I couldn't recreate it against phpwiki.demo.free.fr for instance).

Something like this would trigger it under php8:

curl -H 'referer: android-app://com.google.android.gm/' http://phpwiki.demo.free.fr/index.php/SandBox

The code here in ExternalReferrer.php looks inconsistent - if there is no query string (ie the tested value IS empty), then $url is still an array when it gets passed into stristr, hence the error.

        if (!empty($url["query"])) {
            $url = $url["query"];
        }

        if ($query1 and @stristr($url, $query1)) {

The behaviour is present but the error gets suppressed under earlier versions of php.

Suggested fix: add "else return false;" after the !empty test ?


Reported error:

Got error 'PHP message: PHP Fatal error:  Uncaught TypeError: stristr():
Argument #1 ($haystack) must be of type string, array given in /syshome/webchris/html/phpwiki-1.6.1/lib/ExternalReferrer.php:129
Stack trace:
#0 /syshome/webchris/html/phpwiki-1.6.1/lib/ExternalReferrer.php(129): stristr()
#1 /syshome/webchris/html/phpwiki-1.6.1/lib/stdlib.php(1890): SearchEngines->parseSearchQuery()
#2 /syshome/webchris/html/phpwiki-1.6.1/lib/display.php(324): isExternalReferrer()
#3 /syshome/webchris/html/phpwiki-1.6.1/lib/main.php(1069): displayPage()
#4 /syshome/webchris/html/phpwiki-1.6.1/lib/main.php(816): WikiRequest->action_browse()
#5 /syshome/webchris/html/phpwiki-1.6.1/lib/main.php(1451): WikiRequest->handleAction()
#6 /syshome/webchris/html/phpwiki-1.6.1/lib/main.php(1475): main()
#7 /syshome/webchris/html/phpwiki-1.6.1/index.php(60): include('...')
#8 {main}
  thrown in /syshome/webchris/html/phpwiki-1.6.1/lib/ExternalReferrer.php on line 129', referer: android-app://com.google.android.gm/


Regards,
Thom.