* [Cluster-devel] [PATCH] config: fix escaping of xml special characters
@ 2011-08-04 10:23 Fabio M. Di Nitto
0 siblings, 0 replies; only message in thread
From: Fabio M. Di Nitto @ 2011-08-04 10:23 UTC (permalink / raw)
To: cluster-devel.redhat.com
when transforming config data from objdb to xml, we need to parse CDATA sections
for &<>"' chars and make sure the are correctly transformed into escaped versions
or xml parser will refuse to load.
Resolves: rhbz#726065
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
config/libs/libccsconfdb/fullxpath.c | 34 +++++++++++++++++++++++++++++++++-
config/tools/xml/ccs_config_dump.c | 28 +++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/config/libs/libccsconfdb/fullxpath.c b/config/libs/libccsconfdb/fullxpath.c
index 994c8d8..577c74a 100644
--- a/config/libs/libccsconfdb/fullxpath.c
+++ b/config/libs/libccsconfdb/fullxpath.c
@@ -73,10 +73,42 @@ static int dump_objdb_buff(confdb_handle_t dump_handle, hdb_handle_t cluster_han
confdb_key_iter(dump_handle, parent_object_handle, key_name,
&key_name_len, key_value,
&key_value_len)) == CS_OK) {
+ int char_pos = 0;
key_name[key_name_len] = '\0';
key_value[key_value_len] = '\0';
- snprintf(temp, PATH_MAX - 1, " %s=\"%s\"", key_name, key_value);
+ snprintf(temp, PATH_MAX - 1, " %s=\"", key_name);
+ if (add_to_buffer(temp, buffer, bufsize))
+ return -1;
+
+ for (char_pos = 0; char_pos < key_value_len-1; char_pos++) {
+ switch (key_value[char_pos]) {
+
+ case '&':
+ snprintf(temp, PATH_MAX - 1, "&");
+ break;
+ case '<':
+ snprintf(temp, PATH_MAX - 1, "<");
+ break;
+ case '>':
+ snprintf(temp, PATH_MAX - 1, ">");
+ break;
+ case '"':
+ snprintf(temp, PATH_MAX - 1, """);
+ break;
+ case '\'':
+ snprintf(temp, PATH_MAX - 1, "'");
+ break;
+ default:
+ temp[0] = key_value[char_pos];
+ temp[1] = '\0';
+ break;
+ }
+ if (add_to_buffer(temp, buffer, bufsize))
+ return -1;
+ }
+
+ snprintf(temp, PATH_MAX - 1, "\"");
if (add_to_buffer(temp, buffer, bufsize))
return -1;
}
diff --git a/config/tools/xml/ccs_config_dump.c b/config/tools/xml/ccs_config_dump.c
index b6fe742..74c33c2 100644
--- a/config/tools/xml/ccs_config_dump.c
+++ b/config/tools/xml/ccs_config_dump.c
@@ -25,9 +25,35 @@ static int dump_objdb_buff(confdb_handle_t dump_handle, hdb_handle_t cluster_han
while (confdb_key_iter(dump_handle, parent_object_handle, key_name,
&key_name_len, key_value,
&key_value_len) == CS_OK) {
+ int char_pos = 0;
+
key_name[key_name_len] = '\0';
key_value[key_value_len] = '\0';
- printf(" %s=\"%s\"", key_name, key_value);
+ printf(" %s=\"", key_name);
+ for (char_pos = 0; char_pos < key_value_len-1; char_pos++) {
+ switch (key_value[char_pos]) {
+
+ case '&':
+ printf("&");
+ break;
+ case '<':
+ printf("<");
+ break;
+ case '>':
+ printf(">");
+ break;
+ case '"':
+ printf(""");
+ break;
+ case '\'':
+ printf("'");
+ break;
+ default:
+ putchar(key_value[char_pos]);
+ break;
+ }
+ }
+ printf("\"");
}
if (confdb_object_iter_start(dump_handle, parent_object_handle) != CS_OK)
--
1.7.4.4
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-08-04 10:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-04 10:23 [Cluster-devel] [PATCH] config: fix escaping of xml special characters Fabio M. Di Nitto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).