Ad Widget

Collapse

[1.3.9] Serious bug in the use of "LIMIT n" in an SQL query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Farzad FARID
    Member
    • Apr 2007
    • 79

    #1

    [1.3.9] Serious bug in the use of "LIMIT n" in an SQL query

    Hi,

    I created a test trigger that changes it's value every 3 or 4 minutes. It worked fine for a time, switching between TRUE and FALSE, along with "events" who also showed alternated TRUE and FALSE values.

    All of a sudden, after a few hours, the "events" table and web page stopped recording FALSE events, only TRUE events are recorded.

    After debugging, it appears that the problem lies in "src/libs/zbxdbhigh/db.c:et_latest_event_status()", around line:
    Code:
    	result = DBselectN(sql,20);
    When it is executed, like for example here:
    Code:
      3779:20070523:175531 Query [select eventid,value,clock from events where source=0 and object=0 and objectid=12456 order by clock limit 20]
    the sql query fetches the FIRST 20 values instead of the LAST 20 values. Therefore, because I have lots of events for this trigger, as soon as I have more than 20 events, this query does not work correctly anymore and always return bogus data...

    This is a serious bug because event logging will quickly stop working correctly.

    This bug was introduced by rev 4156, which suppressed "DESC" in the SQL query. But because "event_prev_status" is not used anymore in db.c (the line using it are commented), it is safe to add "DESC" again to get the code to work again.


    But, as LIMIT is used in many places in the code, I wanted to know if there are other places where the SQL query won't work correctly because of the "LIMIT" bug?

    Regards
  • Alexei
    Founder, CEO
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2004
    • 5654

    #2
    Fixed in the latest SVN code.
    Alexei Vladishev
    Creator of Zabbix, Product manager
    New York | Tokyo | Riga
    My Twitter

    Comment

    • Farzad FARID
      Member
      • Apr 2007
      • 79

      #3
      Small error in you patch

      Originally posted by Alexei
      Fixed in the latest SVN code.
      Almost

      Because I think:
      Code:
             result = DBselect(sql,2);
      should be
      Code:
             result = DBselectN(sql,2);
      You want "LIMIT 2" added to the SQL query, not a vararg formatting.

      Regards

      Comment

      • Alexei
        Founder, CEO
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2004
        • 5654

        #4
        Hey, please, send your CV to me! NOW!
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        Working...