[PATCH 1/2] Issue #243: start/stop/display a VM whose name with "?"

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> create a VM with name ubuntu?guest4 start/stop/display this VM Kimchi will throw a exception: "Unexpected query string parameters: guest4" That's because the URL is not quoted when internal_redirect. Also unquote the ident before dispatch the resource. issue: https://github.com/kimchi-project/kimchi/issues/243 Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Hongliang Wang <hlwang@linux.vnet.ibm.com> --- src/kimchi/control/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py index 048dd34..50f8c43 100644 --- a/src/kimchi/control/base.py +++ b/src/kimchi/control/base.py @@ -54,7 +54,6 @@ class Resource(object): """ def __init__(self, model, ident=None): self.model = model - ident = ident if ident is None else urllib2.unquote(ident) self.ident = ident self.model_args = (ident,) self.update_params = [] @@ -76,7 +75,8 @@ class Resource(object): fn = getattr(self.model, model_fn(self, action_name)) ident = fn(*model_args) self._redirect(ident) - uri_params = tuple(self.model_args) + uri_params = tuple([urllib2.quote(arg.encode('utf-8'), safe="") + for arg in self.model_args]) raise internal_redirect(self.uri_fmt % uri_params) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message) @@ -238,6 +238,7 @@ class Collection(object): def _cp_dispatch(self, vpath): if vpath: ident = vpath.pop(0) + ident = urllib2.unquote(ident) # incoming text, from URL, is not unicode, need decode args = self.resource_args + [ident.decode("utf-8")] return self.resource(self.model, *args) -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Libvirt only does not allow "/" in storagepool name. For it will create a storagepool xml by this name. For example, if we create a name with "pool/name" Libvirt will try to create the follow storagepool configure file: /etc/libvirt/storage/pool/name.xml Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- po/en_US.po | 4 +--- po/kimchi.pot | 4 +--- po/pt_BR.po | 4 +--- po/zh_CN.po | 6 ++---- ui/js/src/kimchi.storagepool_add_main.js | 2 +- ui/pages/i18n.html.tmpl | 2 +- 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/po/en_US.po b/po/en_US.po index 8ac59c7..36971b6 100644 --- a/po/en_US.po +++ b/po/en_US.po @@ -281,9 +281,7 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "NFS server mount path can not be blank." -msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." +msgid "Invalid storage pool name. It should not contain '/'." msgstr "" msgid "Invalid NFS mount path." diff --git a/po/kimchi.pot b/po/kimchi.pot index f7b33ee..167911c 100755 --- a/po/kimchi.pot +++ b/po/kimchi.pot @@ -273,9 +273,7 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "" -msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." +msgid "Invalid storage pool name. It should not contain '/'." msgstr "" msgid "Invalid NFS mount path." diff --git a/po/pt_BR.po b/po/pt_BR.po index 0d924e3..502624a 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -299,9 +299,7 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "Caminho de montagem do servidor de NFS não pode ficar em branco." -msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." +msgid "Invalid storage pool name. It should not contain '/'." msgstr "" msgid "Invalid NFS mount path." diff --git a/po/zh_CN.po b/po/zh_CN.po index 361c11a..5cf9f2e 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -289,10 +289,8 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "NFS服务器挂载路径不能为空" -msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." -msgstr "" +msgid "Invalid storage pool name. It should not contain '/'." +msgstr "无效的存储池的名字。名字不能包含‘/’。" msgid "Invalid NFS mount path." msgstr "" diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js index b634ca6..203a3f5 100644 --- a/ui/js/src/kimchi.storagepool_add_main.js +++ b/ui/js/src/kimchi.storagepool_add_main.js @@ -144,7 +144,7 @@ kimchi.validateForm = function() { kimchi.message.error.code('KCHPOOL6001E'); return false; } - if (!/^[\w-]+$/.test(name)) { + if (name.contains("/")) { kimchi.message.error.code('KCHPOOL6004E'); return false; } diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl index 098a0a9..60d2c28 100644 --- a/ui/pages/i18n.html.tmpl +++ b/ui/pages/i18n.html.tmpl @@ -109,7 +109,7 @@ var i18n = { 'KCHPOOL6001E': "$_("The storage pool name can not be blank.")", 'KCHPOOL6002E': "$_("The storage pool path can not be blank.")", 'KCHPOOL6003E': "$_("NFS server mount path can not be blank.")", - 'KCHPOOL6004E': "$_("Invalid storage pool name. It may only contain letters, numbers, underscores, and hyphens.")", + 'KCHPOOL6004E': "$_("Invalid storage pool name. It should not contain '/'.")", 'KCHPOOL6005E': "$_("Invalid NFS mount path.")", 'KCHPOOL6006E': "$_("No logical device selected.")", 'KCHPOOL6007E': "$_("The iSCSI target can not be blank.")", -- 1.8.4.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> I am wondering if it does not apply to all resources: vms, networks and so. We also need to scape the strings we put in the xml. Otherwise we will have problems while creating resources. |>>>importcgi| |>>>cgi.escape("< & >")| |'< & >'| On 02/23/2014 11:58 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Libvirt only does not allow "/" in storagepool name. For it will create a storagepool xml by this name.
For example, if we create a name with "pool/name"
Libvirt will try to create the follow storagepool configure file: /etc/libvirt/storage/pool/name.xml
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- po/en_US.po | 4 +--- po/kimchi.pot | 4 +--- po/pt_BR.po | 4 +--- po/zh_CN.po | 6 ++---- ui/js/src/kimchi.storagepool_add_main.js | 2 +- ui/pages/i18n.html.tmpl | 2 +- 6 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/po/en_US.po b/po/en_US.po index 8ac59c7..36971b6 100644 --- a/po/en_US.po +++ b/po/en_US.po @@ -281,9 +281,7 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "NFS server mount path can not be blank."
-msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." +msgid "Invalid storage pool name. It should not contain '/'." msgstr ""
msgid "Invalid NFS mount path." diff --git a/po/kimchi.pot b/po/kimchi.pot index f7b33ee..167911c 100755 --- a/po/kimchi.pot +++ b/po/kimchi.pot @@ -273,9 +273,7 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr ""
-msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." +msgid "Invalid storage pool name. It should not contain '/'." msgstr ""
msgid "Invalid NFS mount path." diff --git a/po/pt_BR.po b/po/pt_BR.po index 0d924e3..502624a 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -299,9 +299,7 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "Caminho de montagem do servidor de NFS não pode ficar em branco."
-msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." +msgid "Invalid storage pool name. It should not contain '/'." msgstr ""
msgid "Invalid NFS mount path." diff --git a/po/zh_CN.po b/po/zh_CN.po index 361c11a..5cf9f2e 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -289,10 +289,8 @@ msgstr "" msgid "NFS server mount path can not be blank." msgstr "NFS服务器挂载路径不能为空"
-msgid "" -"Invalid storage pool name. It may only contain letters, numbers, " -"underscores, and hyphens." -msgstr "" +msgid "Invalid storage pool name. It should not contain '/'." +msgstr "无效的存储池的名字。名字不能包含‘/’。"
msgid "Invalid NFS mount path." msgstr "" diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js index b634ca6..203a3f5 100644 --- a/ui/js/src/kimchi.storagepool_add_main.js +++ b/ui/js/src/kimchi.storagepool_add_main.js @@ -144,7 +144,7 @@ kimchi.validateForm = function() { kimchi.message.error.code('KCHPOOL6001E'); return false; } - if (!/^[\w-]+$/.test(name)) { + if (name.contains("/")) { kimchi.message.error.code('KCHPOOL6004E'); return false; } diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl index 098a0a9..60d2c28 100644 --- a/ui/pages/i18n.html.tmpl +++ b/ui/pages/i18n.html.tmpl @@ -109,7 +109,7 @@ var i18n = { 'KCHPOOL6001E': "$_("The storage pool name can not be blank.")", 'KCHPOOL6002E': "$_("The storage pool path can not be blank.")", 'KCHPOOL6003E': "$_("NFS server mount path can not be blank.")", - 'KCHPOOL6004E': "$_("Invalid storage pool name. It may only contain letters, numbers, underscores, and hyphens.")", + 'KCHPOOL6004E': "$_("Invalid storage pool name. It should not contain '/'.")", 'KCHPOOL6005E': "$_("Invalid NFS mount path.")", 'KCHPOOL6006E': "$_("No logical device selected.")", 'KCHPOOL6007E': "$_("The iSCSI target can not be blank.")",

On 02/24/2014 10:58 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Tested-by: Hongliang Wang <hlwang@linux.vnet.ibm.com>
create a VM with name ubuntu?guest4 start/stop/display this VM
Kimchi will throw a exception: "Unexpected query string parameters: guest4"
That's because the URL is not quoted when internal_redirect.
Also unquote the ident before dispatch the resource.
issue: https://github.com/kimchi-project/kimchi/issues/243
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Hongliang Wang <hlwang@linux.vnet.ibm.com> --- src/kimchi/control/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py index 048dd34..50f8c43 100644 --- a/src/kimchi/control/base.py +++ b/src/kimchi/control/base.py @@ -54,7 +54,6 @@ class Resource(object): """ def __init__(self, model, ident=None): self.model = model - ident = ident if ident is None else urllib2.unquote(ident) self.ident = ident self.model_args = (ident,) self.update_params = [] @@ -76,7 +75,8 @@ class Resource(object): fn = getattr(self.model, model_fn(self, action_name)) ident = fn(*model_args) self._redirect(ident) - uri_params = tuple(self.model_args) + uri_params = tuple([urllib2.quote(arg.encode('utf-8'), safe="") + for arg in self.model_args]) raise internal_redirect(self.uri_fmt % uri_params) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message) @@ -238,6 +238,7 @@ class Collection(object): def _cp_dispatch(self, vpath): if vpath: ident = vpath.pop(0) + ident = urllib2.unquote(ident) # incoming text, from URL, is not unicode, need decode args = self.resource_args + [ident.decode("utf-8")] return self.resource(self.model, *args)

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 02/23/2014 11:58 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
create a VM with name ubuntu?guest4 start/stop/display this VM
Kimchi will throw a exception: "Unexpected query string parameters: guest4"
That's because the URL is not quoted when internal_redirect.
Also unquote the ident before dispatch the resource.
issue: https://github.com/kimchi-project/kimchi/issues/243
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Hongliang Wang <hlwang@linux.vnet.ibm.com> --- src/kimchi/control/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py index 048dd34..50f8c43 100644 --- a/src/kimchi/control/base.py +++ b/src/kimchi/control/base.py @@ -54,7 +54,6 @@ class Resource(object): """ def __init__(self, model, ident=None): self.model = model - ident = ident if ident is None else urllib2.unquote(ident) self.ident = ident self.model_args = (ident,) self.update_params = [] @@ -76,7 +75,8 @@ class Resource(object): fn = getattr(self.model, model_fn(self, action_name)) ident = fn(*model_args) self._redirect(ident) - uri_params = tuple(self.model_args) + uri_params = tuple([urllib2.quote(arg.encode('utf-8'), safe="") + for arg in self.model_args]) raise internal_redirect(self.uri_fmt % uri_params) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message) @@ -238,6 +238,7 @@ class Collection(object): def _cp_dispatch(self, vpath): if vpath: ident = vpath.pop(0) + ident = urllib2.unquote(ident) # incoming text, from URL, is not unicode, need decode args = self.resource_args + [ident.decode("utf-8")] return self.resource(self.model, *args)

Applied. Thanks. Regards, Aline Manera
participants (3)
-
Aline Manera
-
Hongliang Wang
-
shaohef@linux.vnet.ibm.com