Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-21790

grade_object::fetch_all_helper() mishandles null values

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Gradebook
    • Labels:
      None
    • Database:
      MySQL
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      There is a bug in grade_object::fetch_all_helper() (/lib/grade/grade_object.php lines 162-72) such that when one of the values in the function argument $params is null, the values get out of sync with the sql query they relate to.

      The code builds up two arrays (lines 162-72), one containing the new SQL_PARAMS_QM db syntax and the other containing the numerically indexed values. However because the second array is not empty when the loop begins these items are pushed onto the end of an existing array, meaning that they are not properly matched to their corresponding question mark.

      In moodle_database::fix_sql_params() (/lib/dml/moodle_database.php line 711
      ) the $params argument is then array_sliced() to the correct length, cutting off the values that should have been passed in.

      The result of this is that fetch_all_helper() will always return false for any index with a value of null in $params (or at least this is what happens in MySQL because the equals sign is not a null safe operator, different buggy behaviour may be exhibited in other db environments).

      This is highly problematic as it means that public API functions with a dependency on fetch_all_helper() (like grade_update_outcomes(), which is how I found the bug) don't to work properly.

        Attachments

          Activity

            People

            Assignee:
            skodak Petr Skoda
            Reporter:
            evan.irving-pease Evan Irving-Pease
            Tester:
            Nobody
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              24/Nov/10