cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Fabio M. Di Nitto <fdinitto@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] config: fix escaping of xml special characters
Date: Thu,  4 Aug 2011 12:23:59 +0200	[thread overview]
Message-ID: <1312453439-13320-1-git-send-email-fdinitto@redhat.com> (raw)

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, "&amp;");
+				break;
+			case '<':
+				snprintf(temp, PATH_MAX - 1, "&lt;");
+				break; 
+			case '>':
+				snprintf(temp, PATH_MAX - 1, "&gt;");
+				break; 
+			case '"':
+				snprintf(temp, PATH_MAX - 1, "&quot;");
+				break;
+			case '\'':
+				snprintf(temp, PATH_MAX - 1, "&apos;");
+				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("&amp;");
+				break;
+			case '<':
+				printf("&lt;");
+				break; 
+			case '>':
+				printf("&gt;");
+				break; 
+			case '"':
+				printf("&quot;");
+				break;
+			case '\'':
+				printf("&apos;");
+				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



                 reply	other threads:[~2011-08-04 10:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1312453439-13320-1-git-send-email-fdinitto@redhat.com \
    --to=fdinitto@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).