Modify

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#12688 closed defect (fixed)

No effect if admin change(update) the parent node

Reported by: anonymous Owned by: falkb
Priority: normal Component: ComponentHierarchyPlugin
Severity: major Keywords: no changes, parent node
Cc: Trac Release: 1.2

Description (last modified by Jun Omae)

If we change a parent Node in Admin->Components the old value was shown if we click on save.

In model.py there was an Error?

Your model.py:

query = "UPDATE component_hierarchy SET parent_component='%s' WHERE component='%s'" % (component, parent_component)

the Column parent_component get the value of component and in the WHERE-Clausel the column component looks for content of variable parent_component.

If we change it to:

query = "UPDATE component_hierarchy SET parent_component='%s' WHERE component='%s'" % (parent_component,component)

no Errors any more

Attachments (0)

Change History (8)

comment:1 Changed 9 years ago by Jun Omae

Description: modified (diff)

comment:2 Changed 9 years ago by Jun Omae

The sql queries in that plugin have SQL injection. We should use trac:wiki:TracDev/DatabaseApi#Parameterpassing.

comment:3 Changed 8 years ago by falkb

Resolution: fixed
Status: newclosed

In 15747:

fixes #12688: applied patch proposed by anonym which fixed the setting of a new parent (many thanks!)

comment:4 Changed 8 years ago by Jun Omae

The SQL injection isn't fixed.

  • componenthierarchyplugin/trunk/componenthierarchy/model.py

    diff --git a/componenthierarchyplugin/trunk/componenthierarchy/model.py b/componenthierarchyplugin/trunk/componenthierarchy/model.py
    index 90bc40f..88a3057 100644
    a b class ComponentHierarchyModel(Component): 
    3838
    3939    def set_parent_component(self, component, parent_component):
    4040        if parent_component == None or parent_component == "":
    41             query = "DELETE FROM component_hierarchy WHERE component='%s'" % component
     41            query = "DELETE FROM component_hierarchy WHERE component=%s"
     42            args = (component,)
    4243        else:
    4344            if self.has_parent_component(component):
    44                 query = "UPDATE component_hierarchy SET parent_component='%s' WHERE component='%s'" % (component, parent_component)
     45                query = "UPDATE component_hierarchy SET parent_component=%s WHERE component=%s"
     46                args = (component, parent_component)
    4547            else:
    46                 query = "INSERT INTO component_hierarchy (component, parent_component) VALUES ('%s', '%s')" % (component, parent_co
     48                query = "INSERT INTO component_hierarchy (component, parent_component) VALUES (%s,%s)"
     49                args = (component, parent_component)
    4750
    4851        if VERSION < '0.12':
    4952            db = self.env.get_db_cnx()
    5053            cursor = db.cursor()
    51             cursor.execute(query)
     54            cursor.execute(query, args)
    5255            self.__start_transaction(db)
    5356        else:
    5457            @with_transaction(self.env)
    5558            def execute_sql_statement(db):
    5659                cursor = db.cursor()
    57                 cursor.execute(query)
     60                cursor.execute(query, args)
    5861
    5962    def rename_component(self, component, new_name):
    6063        query1 = "UPDATE component_hierarchy SET component='%s' WHERE component='%s'" % (new_name, component)
Last edited 8 years ago by Jun Omae (previous) (diff)

comment:5 Changed 8 years ago by falkb

Thanks for your patch, jun66j5! Actually, this was like another ticket for me. Can you confirm if the code works well, I mean, can I blindly commit it? I don't have access to the test bench at present.

comment:6 Changed 8 years ago by Jun Omae

In addition, with_transaction is not available with Trac 0.11.x. This plugin doesn't work with Trac 0.11.x due to ImportError.

  • componenthierarchyplugin/trunk/componenthierarchy/model.py

    diff --git a/componenthierarchyplugin/trunk/componenthierarchy/model.py b/componenthierarchyplugin/trunk/componenthierarchy/model.py
    index 90bc40f..2f8ec3b 100644
    a b  
    66from trac import __version__ as VERSION
    77from trac.core import *
    88from trac.ticket import model
    9 from trac.db import with_transaction
     9try:
     10    from trac.db import with_transaction
     11except ImportError:
     12    with_transaction = None
    1013
    1114class ComponentHierarchyModel(Component):
    1215
    1316    # DB Method
    1417    def __start_transaction(self):
    15         if VERSION < '0.12':
     18        if with_transaction is None:
    1619            # deprecated in newer versions
    1720            self.db.commit()
    1821            self.db.close()

comment:7 in reply to:  5 Changed 8 years ago by Jun Omae

Replying to falkb:

Thanks for your patch, jun66j5! Actually, this was like another ticket for me. Can you confirm if the code works well, I mean, can I blindly commit it? I don't have access to the test bench at present.

No. SQL Injections exist in other code of this plugin and should be fixed. This patch is just a sample to fix it.

comment:8 Changed 8 years ago by falkb

I'll make another ticket as reminder... The problem of #12688 is done.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain falkb.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.