Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4.0-r1] [Moodle 4.1] [PHP 8.1] htmlspecialchars called with NULL value as first parameter #56

Open
danowar2k opened this issue Jan 3, 2025 · 4 comments

Comments

@danowar2k
Copy link

Message from our error logs:

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in blocks/onlinesurvey/locallib.php on line 800

Code in question:

    foreach ($parameter as $key => $value) {
        $key = htmlspecialchars($key);
        $value = htmlspecialchars($value);
        if ( $key != "ext_submit" ) {
            $fields[$key] = urlencode($value);
        }
    }

The value line. So there can be parameters with NULL value. Don't know if that's intended, but one should probably check for null values there and don't call this when it's NULL.

@danowar2k danowar2k changed the title [v4.0-r1] [Moodle 4.1] [PHP 8.1] [v4.0-r1] [Moodle 4.1] [PHP 8.1] htmlspecialchars called with NULL value as first parameter Jan 3, 2025
@danowar2k
Copy link
Author

Maybe the problem isn't at this spot, maybe it is somewhere else where the NULL value is stored to the parameter array. Or even at the spot where the NULL value is stored in the database, don't know yet about the inner workings here.

@danowar2k
Copy link
Author

The key that produces this value is resource_link_id.

@danowar2k
Copy link
Author

resource_link_id null because of this:

    if (!isset($config->id)) {
        $config->id = null;
    }
    $requestparams = $allparams;
    $requestparams = array_merge($requestparams, lti_build_standard_message($config, $orgid, false));

Because $instance->id in lti_build_standard_message() is $config outside.

@danowar2k
Copy link
Author

Final guesswork: config->id is never set because the config_plugins table doesn't have a value for that.

To build the standard LTI request, $instance->id is explicitly required to be present, but not to be set. So you set id to NULL.

So basically, it seems you just have to check for NULL like I said above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant