Uploaded image for project: 'Plugins'
  1. Plugins
  2. CONTRIB-4456

Potential infinite loop in temporary file creation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 2.5
    • Module: Turnitintool
    • None
    • MOODLE_25_STABLE

      In mod/turnitintool/lib.php there is a function called turnitintool_tempfile(). This contains a potential infinite loop..

      The lines are...

          while(!$fp) {
              $file = $temp_dir.DIRECTORY_SEPARATOR.mt_rand().'.'.$suffix;
              $fp = @fopen($file, 'w');
          }
      

      I assume the idea is that it loops if a filename clashes. However, this will loop "forever" if the fopen() fails for ANY reason. Something like a permission problem or a lack of disk space would be all that was needed. Worse - if something has gone wrong the @ prevents the admin ever finding out what the actual underlying error is.

      This needs rewriting. Personally I would pick a random number and then increment it by one until a valid file was found by actually checking if the file exists. I think Moodle had a function for this somewhere but, of course, I can't find it now!

            paul.dawson Paul Dawson (Inactive)
            howardsmiller Howard Miller
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.