glpi-project / glpi

GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.
https://glpi-project.org
GNU General Public License v3.0
4.2k stars 1.28k forks source link

strange recurrent SQL error #1264

Closed vrocheUP closed 6 years ago

vrocheUP commented 7 years ago

Hello team, I have a strange bug with GLPI 9.1. Extract from sql-errors.log :

2016-11-09 08:51:02 [@glpi] * MySQL query error: SQL: INSERT INTO glpi_ticketfollowups (content,tickets_id,users_id,requesttypes_id,is_private,date,date_creation,date_mod) VALUES (\'Bonsoir,\nJe vous réponds pour vous donner la réponse à ma question secrète : xxxx,\nSi je me suis trompé, pourriez vous quand même envoyer l\'identifiant sur la boite laposte.net ? \nVous remerciant d\'avance,\nCordialement,\nA. François\n\nLe 4 novembre 2016 à 22:22, <helpdesk@univ-poitiers.fr> a écrit :\n\n \n\n\',\'2602\',\'0\',\'0\',0**,\'2016-11-09 08:51:01\',\'2016-11-09 08:51:01\',\'2016-11-09 08:51:01\')

As you can see, the value of the field "is_private" is not delimited by simple quotes. There is a new line in sql-erros.log every 5 minutes (this is the time-step I choosed for cron) since #4 of november.

So I have 2 or 3 questions :

  1. why is this request malformed ? It's the only one of this sort in sql-errors.log
  2. why is GLPI still trying to insert this request after several trials ? Isn't there a time-out for such errors ? Today, I have 1033 trials !
  3. I have restarted Apache, and even rebooted the server, thinking of something like a cache. No way, GLPI is still trying to insert this wrong request. Where is it stored ? How can I delete this request ?

Sincerely, Valéry config_GLPI.txt

tomolimo commented 7 years ago

Hello, I tried this with an email with a quote in it with the 9.1/bugfixes branch, and I can't reproduce the issue. Could you send to me the original email that cause this error? Or attach it to the issue? Thank you, Regards, Tomolimo

tomolimo commented 7 years ago

To answer your question: if you want to cancel the integration of this email, you have to delete it from the mailbox. GLPi is still trying to insert it as it is kept in the mailbox

tomolimo commented 7 years ago

regarding the is_private field value: as the field is an integer, there is no need for the quotes, but I believe the real root cause is the ' in l'identifiant

vrocheUP commented 7 years ago

It seems that the collector mailbox is empty. Trying to investigate further more.

tomolimo commented 7 years ago

you mean on your mail server?

vrocheUP commented 7 years ago

Yes I confirm : the mailbox is empty. GLPI is configured with POP

vrocheUP commented 7 years ago

Sorry, the mailbox is not empty, I was looking in the wrong one. The message was in the user's mailbox corresponding to the "'Reply-to" field, as configured in GLPI. That's pure logic. Sorry for the inconvenience. I've learned something today.

Regards, Valéry

vrocheUP commented 7 years ago

Is it possible, in the future, to have quotes really escaped ?

tomolimo commented 7 years ago

they are really :), as I said, I cannot reproduce the issue, mine quotes are escaped. that's why, if you send to me (or attach) the faulty email, I can try to reproduce the issue

vrocheUP commented 7 years ago

Oh sh... I have deleted the message, forgot your request. Fortunately, terminal is still open, I have a "screen copy", see it attached bogus_mail.txt

remicollet commented 7 years ago

Full error message needed, with the SQL error message and the backtrace.

is_private being not escaped IS NOT the issue.

vrocheUP commented 7 years ago

The full error message is at the top of this thread.

vrocheUP commented 7 years ago

Forgot the backtrace.

2016-11-09 10:26:01 [@glpi] *\ MySQL query error: SQL: INSERT INTO glpi_ticketfollowups (content,tickets_id,users_id,requesttypes_id,is_private,date,date_creation,date_mod) VALUES (\'Bonsoir,\nJe vous réponds pour vous donner la réponse à ma question secrète : xxxxxxx,\nSi je me suis trompé, pourriez vous quand même envoyer l\'identifiant sur la boite laposte.net ? \nVous remerciant d\'avance,\nCordialement,\nA. François\n\nLe 4 novembre 2016 à 22:22, <helpdesk@univ-poitiers.fr> a écrit :\n\n \n\n\',\'2602\',\'0\',\'0\',0,\'2016-11-09 10:26:01\',\'2016-11-09 10:26:01\',\'2016-11-09 10:26:01\') Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identifiant sur la boite laposte.net ? \nVous remerciant d'avance,\nCordialement' at line 2 Backtrace : inc/commondbtm.class.php:427 inc/commondbtm.class.php:838 CommonDBTM->addToDB() inc/mailcollector.class.php:554 CommonDBTM->add() inc/mailcollector.class.php:1614 MailCollector->collect() : MailCollector::cronMailgate() inc/crontask.class.php:803 call_user_func() front/cron.php:88 CronTask::launch()

tomolimo commented 7 years ago

unfortunately, the attached text file is not a real email: it's an email representation! could you try on your side to reproduce the issue (with a new email), and then to send to me the faulty email?

remicollet commented 7 years ago

The full error message is at the top of this thread.

It was not.

The important part if "near 'identifiant sur la boite laposte.net" And indeed l'identificant* create this issue, the body not being escaped.

tomolimo commented 7 years ago

the body not being escaped.

??? For me the following code really does the escape (file: mailcollector.php, function buildTicket, line: 930):

     }

     $tkt = Toolbox::addslashes_deep($tkt);
     return $tkt;
  }

When sending an email with body: Test fu'p then I get Test fu\'p: the quote is really escaped.

remicollet commented 7 years ago

I didn't say the code does not escape the body ;) I only said it is not escaped to above debug output.

tomolimo commented 7 years ago

ok :)

remicollet commented 7 years ago

In mailcollector, we have $tkt = Toolbox::addslashes_deep($tkt);

But in TicketFollowup::prepareInputForAdd => Ticket::setSimpleTextContent => Html::entity_decode_deep(). => httml_entity_decode($value, ENT_QUOTES, "UTF-8"));

So, I think that if a mail contains an encoded quote ("'"), this can raise such issue.

vrocheUP commented 7 years ago

Hello, Attached is a mail that can't be added to database, same error. It seems that this error occurs only with gmail accounts. mail.txt

trasher commented 7 years ago

I've just tested adding a followup to a ticket with single quote from a "standard" mailer and from gmail on current 9.1/bugfixes branch (mostly 9.1.3); I cannot reproduce the issue.

vrocheUP commented 7 years ago

Hello team, My GLPI version is 9.1.2. The problem is still occurring with messages sent from a GMail address :

  • when writing to a receiver to create a ticket, everything works as expected, the ticket is created
  • if replying to the notification, the collector has an error (same error as before) : 2017-07-13 15:10:03 [@glpi] *** MySQL query error: SQL: INSERT INTO glpi_ticketfollowups (content,tickets_id,users_id,requesttypes_id,is_private,date,date_creation,date_mod) VALUES (\'Cette fois on ne met pas d\'apostrophes\n\nLe 13 juillet 2017 à 13:55, <helpdesk@univ-poitiers.fr> a écrit :\n\n \n\n\',\'10727\',\'0\',\'0\',0,\'2017-07-13 15:10:01\',\'2017-07-13 15:10:01\',\'2017-07-13 15:10:01\') Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'apostrophes\n\nLe 13 juillet 2017 à 13:55, <helpdesk@univ-poitiers.fr> a ' at line 2 Backtrace : inc/commondbtm.class.php:436 inc/commondbtm.class.php:852 CommonDBTM->addToDB() inc/mailcollector.class.php:554 CommonDBTM->add() inc/mailcollector.class.php:1614 MailCollector->collect() : MailCollector::cronMailgate() inc/crontask.class.php:832 call_user_func() front/cron.php:88 CronTask::launch()

Does the last version correct this problem ?

Bonne fin de journée :)

vrocheUP commented 7 years ago

Last comment : when going to "configuration -> receivers" and clicking on the "list of not imported emails" button, GLPI does import the emails with no errors.

lgigant commented 6 years ago

HI,

Same issue for us...our GLPI version is 9.1.6, we can reproduce the error. We are using gmail (G-Suite) as corporate mail server. Reproduce part of original email:

Gracias Luis Quisiera acceder a las carpetas que gestionan Paco y Patro para almacenar los reportes de operaci=C3=B3n en general, tanto de filiales = como de BU's Solo Lectura es suficiente. No tengo ninguna actuaci=C3=B3n que realiz= ar

And here the SQL error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 's\nSolo Lectura es suficiente. No tengo ninguna actuación que realizar\n\nEl 20' at line 2

It´s a bug with the apostrophe

Blank-Vcf commented 6 years ago

I have the same problem on 9.2.1:

*** MySQL query error: SQL: INSERT INTOglpi_tickets(content,name,urgency,requesttypes_id,entities_id,status,impact,priority,users_id_recipient,itilcategories_id,date,global_validation,type,date_creation,date_mod) VALUES ('Alerte relative aux nouvelles mises à jour Les 8 nouvelles mises à jour suivantes ont été synchronisées avec FLESRV202 depuis vendredi 5 janvier 2018 05:20 (GMT).\n\nMises à jour critiques et de sécurité &lt;a href=\"http://support.microsoft.com/kb/4056568\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"Mise à jour de sécurité pour Internet Explorer 10 pour Windows Server 2012 (KB4056568)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/help/4056894\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"2018-01 Correctif cumulatif mensuel de qualité pour Windows 7 pour les systèmes basés sur x86 (KB4056894)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/help/4056894\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"2018-01 Correctif cumulatif mensuel de qualité pour Windows Server 2008 R2 pour les systèmes basés sur Itanium (KB4056894)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/help/4056894\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"2018-01 Correctif cumulatif mensuel de qualité pour Windows 7 pour les systèmes basés sur x64 (KB4056894)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/help/4056894\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"2018-01 Correctif cumulatif mensuel de qualité pour Windows Server 2008 R2 pour les systèmes basés sur x64 (KB4056894)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/help/4056896\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"2018-01 Correctif cumulatif mensuel de qualité pour Windows Server 2012 pour les systèmes basés sur x64 (KB4056896)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/kb/4056568\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"Mise à jour de sécurité pour Internet Explorer 9 pour Windows Server 2008 (KB4056568)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\n&lt;a href=\"http://support.microsoft.com/kb/4056568\" title=\"Cliquez ici pour consulter des informations supplémentaires sur cette mise à jour\"Mise à jour de sécurité cumulative pour Internet Explorer 9 pour Windows Server 2008 pour les systèmes x64 (KB4056568)\nUn problème de sécurité qui pourrait avoir un impact sur votre système a été identifié dans un produit logiciel Microsoft. Vous pouvez renforcer la protection de votre système en installant cette mise à jour de Microsoft. Pour consulter la liste complète des problèmes résolus par cette mise à jour et en savoir plus, reportez-vous à l'article correspondant de la Base de connaissances Microsoft. Une fois la mise à jour installée, vous serez peut-être amené à redémarrer l’ordinateur.\n\nAutres mises à jour Aucune nouvelle mise à jour non critique ou non liée à la sécurité n’a été synchronisée.','WSUS : Alerte relative aux nouvelles mises à jour en provenance de FLESRV202','3','2','6','2','3','3','9960','5','2018-01-09 14:10:01','1','1','2018-01-09 14:10:01','2018-01-09 14:10:01') Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'article correspondant de la Base de connaissances Microsoft. Une fois la mise à' at line 2 Backtrace : inc/commondbtm.class.php:504 inc/commondbtm.class.php:928 CommonDBTM->addToDB() inc/mailcollector.class.php:596 CommonDBTM->add() inc/mailcollector.class.php:1659 MailCollector->collect() : MailCollector::cronMailgate() inc/crontask.class.php:832 call_user_func() front/cron.php:87 CronTask::launch()

mail are wus report,unfortunately, problem is appearing since i have update from 9.1.6 to 9.1.7.1 and 9.2.1

butyn13 commented 6 years ago

Good afternon. I have the same issue. For example:

log - sql-errors.log

2018-01-15 13:40:10 [6@corp-glpi-hmg]

  *** MySQL query error:
  SQL: INSERT INTO `glpi_tickets` (`content`,`name`,`urgency`,`requesttypes_id`,`entities_id`,`status`,`impact`,`priority`,`users_id_lastupdater`,`users_id_recipient`,`itilcategories_id`,`date`,`global_validation`,`locations_id`,`slas_ttr_id`,`slas_tto_id`,`ttr_slalevels_id`,`time_to_resolve`,`sla_waiting_duration`,`time_to_own`,`type`,`date_creation`,`date_mod`) VALUES ('teste **'aspas'** teste\n\nAtt,\n\nJeffe***** \nAnalista de Suporte\nBo**** Ho***is &amp; ****rts \n+55 41 2169-4768\n+55 41 99253-5789\njeff*******@******n.c***\nwww.bourbon.com.br','teste aspas 2','3','2','0','2','3','3','6','6','0','2018-01-15 13:40:02','1','21','2','1',0,'2018-01-18 10:10:02',0,'2018-01-18 10:10:02','2','2018-01-15 13:40:02','2018-01-15 13:40:02')
  Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'aspas' teste\n\nAtt,\n\nJefferson Butyn \nAnalista de Suporte\nBourbon Hotéis &' at line 2
  Backtrace :
  inc/commondbtm.class.php:504                       
  inc/commondbtm.class.php:928                       CommonDBTM->addToDB()
  inc/mailcollector.class.php:596                    CommonDBTM->add()
  front/mailcollector.form.php:81                    MailCollector->collect()

When is used ' "quotes" in body of mail, it happens this issue!!

I'm using GLPI 9.2.1 Mails Gmail Ubuntu Server 16.04

lgigant commented 6 years ago

Any news about this bug?

orthagh commented 6 years ago

Hello. Just did a bunch of tests with some of the sentences pasted here:

I tested also with glpi ui or via cron cli.

None of my tests failed, i didn't had any sql errors with current 9.2/bugfixes (future 9.2.2)

bigben386 commented 6 years ago

We are having a bunch of problems with this too. We had no mail receiver issues on 9.1.5. Now that we are on 9.2.x, we have many emails that do not import. This is causing many missed tickets. Like everyone else, we use g suite w/imap. The 1 thing in common with all the messages is that they contain a single quote.

lgigant commented 6 years ago

Exactly, this behavior is always on a reply (g-Suite also) to a open ticket with a single quote in the body of email

bigben386 commented 6 years ago

For us, it mostly affects new tickets as our help desk techs usually reply through the web. What can I do to help debug the issue so we can get this fixed?

trasher commented 6 years ago

Since we were not able to reproduce this issue; we need a clear and precise way to reproduce on current version.

bigben386 commented 6 years ago

I would be happy to provide access to any logs or even access to a dev server w/gmail account to get this resolved. We are missing many tickets because of this bug.

husisusi commented 6 years ago

We have the same issue... GLPI 9.2.2- If I click "Get email tickets now" it works. But if I run "/usr/bin/php5 /var/www/html/glpi/front/cron.php" no errors but no E-mails fetched!!! I tested it with POP and IMAP. In mailgate its "CLI" and its enabled.

Cron LOG: 2018-04-02 12:10:02 [@srvername] External #3: Launch taskscheduler 2018-04-02 12:14:37 [2@srvername] Internal #1: Launch infocom 2018-04-02 12:15:01 [@srvername] External #1: Launch queuednotification 2018-04-02 12:15:01 [@srvername] External #2: Launch taskscheduler 2018-04-02 12:15:01 [@srvername] External #3: Launch wakeupAgents

It is not a funny issue!!!

lolokai commented 6 years ago

Same error for me

bigben386 commented 6 years ago

I have tried multiple versions of PHP all the way up to 7.2 and it made no difference. Still the exact same error. This really needs to be a higher priority as a help desk is kinda useless if users cannot file tickets.

lolokai commented 6 years ago

I founded the solution : you must activate the option : Enable rich text for helpdesk (In french : Utiliser du texte riche pour l’assistance) on Configuration - General - Helpdesk

lolokai commented 6 years ago

Sorry : finded :D

apeyrou commented 6 years ago

Thanks for the solution. It's ok for our tickets now!

bigben386 commented 6 years ago

Thank you lolokai! Mail queue is now empty.

jcheger commented 6 years ago

I have the same issue for emails coming from Gmail. Single quotes are HTML encoded (&#39;) and are not backslashed by Toolbox::addslashes_deep, and MySQL receive the INSERT with single quotes (converted to text), which creates an error.

I think it's a non sense to confuse and mix « rich text » and handling HTML encoded quotes. Incomig emails should be correctly handled, whatever users want in their UI. Requesters send emails with their favorite app, and do not care how GLPI is configured.

Here is a quick patch that will patch HTML quotes (inc/mailcollector.class.php:966): $tkt = str_replace ("&#39;", "'", $tkt); $tkt = Toolbox::addslashes_deep($tkt);

trasher commented 6 years ago

So, to resume; this issue happens when an ticket is opened without rich text and when there is something like &#039; in the content. This is not directly related to the mail collector, same problem happens from the UI.

lgigant commented 6 years ago

Hi,

Not for me, this behavior occurs when a user reply to a ticket previusly opened and when the body of email contain an ' (apostrof) for example "L'Altet" in this case, we have on sql-errors.log the next message

" Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Altet - C/ dels Molins, 4 Apdo. de correos 914\n\n46870 Ontinyent / "

Only occurs on reply to tickets previusly opened, on new tickets this behavior not occur.

https://www.fileformat.info/info/unicode/char/27/index.htm

Regards

orthagh commented 6 years ago

To all participants, (maybe recent one btw, ping @lgigant & @jcheger).

Could you test the following change and let us know the resolution of this issue: https://github.com/trasher/glpi/commit/d9a58d2656475f598a941d5b8d2a76dcf6aa9103

dethorpe commented 6 years ago

Hey, I manually applied the changes from commit 0fbb2f005b22ed9fb24e7dcbc49dc165a00664de (we are running 9.2.1 and waiting for 9.2.4 to upgrade) but the issue still occurs. Are there dependencies I am not aware of or perhaps another place this str_replace needs to occur?

2018-06-07 10:33:22 [33@GLPI] *** MySQL query error: SQL: INSERT INTO glpi_tickets (content,name,urgency,requesttypes_id,entities_id,status,impact,priority,users_id_lastupdater,itilcategories_id,date,global_validation,type,date_creation,date_mod) VALUES ('Testing this function's functionality.\n\n','Re: [GLPI #0006397] Closing of the Ticket Test ticket, please ignore','3','0','0','1','3','3','33','0','2018-06-07 10:33:21','1','1','2018-06-07 10:33:21','2018-06-07 10:33:21') Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's functionality.\n\n' at line 2 Backtrace : inc/commondbtm.class.php:504
inc/commondbtm.class.php:928 CommonDBTM->addToDB() inc/mailcollector.class.php:596 CommonDBTM->add() front/mailcollector.form.php:81 MailCollector->collect()

trasher commented 6 years ago

Try with latest 9.2/bugfixes

dethorpe commented 6 years ago

I don't understand what you mean. That version is earlier then what I run, 9.2.1 and where this commit will be applied 9.2.4. Sorry if I am missing something obvious...

orthagh commented 6 years ago

@chaoservices, here is some nightly tarballs: https://forge.glpi-project.org/tarballs/

bigben386 commented 6 years ago

It doesn't seem that this is completely fixed yet. I upgraded to 9.2.4 and changed back to plain text mode. I have a stuck message with the same error. The body has the word "can't" in it.

bigben386 commented 6 years ago

@trasher Any way to reopen this? It is not fixed as of 9.2.4. Currently have 4 emails failing to import. All have a single quote. I looked at the patches for this and noticed that it attempts to remove &#039 but the gmail source shows &#39