#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 )
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
Description: | modified (diff) |
---|
comment:2 Changed 9 years ago by
comment:4 Changed 8 years ago by
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): 38 38 39 39 def set_parent_component(self, component, parent_component): 40 40 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,) 42 43 else: 43 44 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) 45 47 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) 47 50 48 51 if VERSION < '0.12': 49 52 db = self.env.get_db_cnx() 50 53 cursor = db.cursor() 51 cursor.execute(query )54 cursor.execute(query, args) 52 55 self.__start_transaction(db) 53 56 else: 54 57 @with_transaction(self.env) 55 58 def execute_sql_statement(db): 56 59 cursor = db.cursor() 57 cursor.execute(query )60 cursor.execute(query, args) 58 61 59 62 def rename_component(self, component, new_name): 60 63 query1 = "UPDATE component_hierarchy SET component='%s' WHERE component='%s'" % (new_name, component)
comment:5 follow-up: 7 Changed 8 years ago by
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
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 6 6 from trac import __version__ as VERSION 7 7 from trac.core import * 8 8 from trac.ticket import model 9 from trac.db import with_transaction 9 try: 10 from trac.db import with_transaction 11 except ImportError: 12 with_transaction = None 10 13 11 14 class ComponentHierarchyModel(Component): 12 15 13 16 # DB Method 14 17 def __start_transaction(self): 15 if VERSION < '0.12':18 if with_transaction is None: 16 19 # deprecated in newer versions 17 20 self.db.commit() 18 21 self.db.close()
comment:7 Changed 8 years ago by
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
I'll make another ticket as reminder... The problem of #12688 is done.
The sql queries in that plugin have SQL injection. We should use trac:wiki:TracDev/DatabaseApi#Parameterpassing.