Issue Details (XML | Word | Printable)

Key: MDL-7765
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Eloy Lafuente (stronk7)
Reporter: Martin Anderson
Votes: 0
Watchers: 1
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Error with SQL injection because of Comment field length

Created: 02/Dec/06 04:22 AM   Updated: 09/Feb/07 08:36 AM
Component/s: Installation
Affects Version/s: 1.7
Fix Version/s: 1.7.2

Environment: Windows XP SP2, Apache 2.2.3, PHP 5.2.0, MySQL 5.0.27
Issue Links:
Duplicate
 
Relates
 

Database: MySQL
URL: http://moodle.org/mod/forum/discuss.php?d=58264
Participants: Eloy Lafuente (stronk7), Martin Anderson and Petr Škoda (skodak)
Security Level: None
Resolved date: 09/Feb/07
Affected Branches: MOODLE_17_STABLE
Fixed Branches: MOODLE_17_STABLE


 Description  « Hide
This problem as well as another installation problem are described in this forum http://moodle.org/mod/forum/discuss.php?d=58264

During the database installation an error will occur with some of the comments for a table or column within a table with the error 1105
See the example error below:

(mysql): ALTER TABLE mdl_log_display COMMENT='For a particular module/action, specifies a moodle table/field' 1105: Too long comment for table '#sql-e0c_f9'

ADOConnection._Execute(ALTER TABLE mdl_log_display COMMENT='For a particular module/action, specifies a moodle table/field', false) % line 889, file: adodb.inc.php
ADOConnection.Execute(ALTER TABLE mdl_log_display COMMENT='For a particular module/action, specifies a moodle table/field') % line 71, file: dmllib.php
execute_sql(ALTER TABLE mdl_log_display COMMENT='For a particular module/action, specifies a moodle table/field', true) % line 1737, file: dmllib.php
execute_sql_arr(Array[235]) % line 548, file: ddllib.php
install_from_xmldb_file(C:\Inetpub\wwwroot\Moodle/lib/db/install.xml) % line 147, file: index.php

This error occurs with several of the COMMENT fields for either tables or columns, I found three during my installation test:
Line 85 of /moodle/mod/forum/db/install.xml
Line 275 of /moodle/mod/quiz/db/install.xml
Line 7 of /moodle/blocks/rss_client/db/install.xml

My own analysis:
I ran into this same problem (the adodb error) when doing an install on a test machine (WinXP, Apache 2.2, MySQL 5.0.27, PHP 5.2.0) using the latest Moodle build (1.7+) (not CVS), which seems to have something to do with comment field length being limited in MySQL (atleast in Windows?) and the Comment fields that are called in the XML files being too long. The installer for Moodle, on errors, then tries to reinstall the same information for the section that was being installed (i.e. quizzes, forums, etc, whatever SQL injection it was at when the error occured) when the comment error was reached and also to reinstall into the log_display table, resulting in duplicate key errors like those reported in forum posts (examples here:http://moodle.org/mod/forum/discuss.php?d=57513 and here:http://moodle.org/mod/forum/discuss.php?d=58775).

Work arounds were described by Gordon Bateson in the forum post, which included:
1. open "lib/adodb/adodb.inc.php" with a text editor
2. locate the following lines (around line 886):
function &_Execute($sql,$inputarr=false)
{
3. change the above lines to the following:
function &_Execute($sql,$inputarr=false)
{
$sql = preg_replace("/COMMENT='.*?'/", "COMMENT=''", $sql);
i.e. add the last line which removes comments from the $sql
4. save the modified "lib/adodb/adodb.inc.php"



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Petr Škoda (skodak) added a comment - 02/Dec/06 07:31 PM
Assigning to Eloy - our db guru

Eloy Lafuente (stronk7) added a comment - 03/Dec/06 03:21 AM
Wow, it never happened in my test environments...

After looking for it, it seems that MySQL has this limits about the lenght of its comments:

  • 60 cc for table comments.
  • 255 cc for column comments

Also, I've found one reported and fixed MySQL bug, before 5.0.24 (http://bugs.mysql.com/bug.php?id=13934) In that versions of MySQL the excess of characters was simply discarded while after 5.0.24 it shows the error showed in this bug.

So, I'm going to enforce such limits in Moodle XMLDB to prevent problems in the future.

Ciao


Eloy Lafuente (stronk7) added a comment - 09/Feb/07 08:36 AM
Hi Martin,

really afraid about not arriving to this bug until today! I missed it completely under a mountain of things. Changes are now in CVS for 1.7.1+. Comment limit for tables is now 60cc under MySQL.

Ciao