summaryrefslogtreecommitdiff
path: root/lib/formats.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-03-12 21:57:50 +0000
committerjbj <devnull@localhost>2003-03-12 21:57:50 +0000
commited1cc2fa039332bc35517c3c7b433150da419ef6 (patch)
tree8231a6d8f354d5a14ae89a44bae9dbbcb882cda0 /lib/formats.c
parent521861e7443971e712fd292c7ccfe7b1cfddf2e7 (diff)
downloadlibrpm-tizen-ed1cc2fa039332bc35517c3c7b433150da419ef6.tar.gz
librpm-tizen-ed1cc2fa039332bc35517c3c7b433150da419ef6.tar.bz2
librpm-tizen-ed1cc2fa039332bc35517c3c7b433150da419ef6.zip
Sanity.
CVS patchset: 6680 CVS date: 2003/03/12 21:57:50
Diffstat (limited to 'lib/formats.c')
-rw-r--r--lib/formats.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/formats.c b/lib/formats.c
index 0ce0614f9..cf07474ca 100644
--- a/lib/formats.c
+++ b/lib/formats.c
@@ -237,6 +237,44 @@ static /*@only@*/ char * base64Format(int_32 type, const void * data,
}
/**
+ */
+static size_t xmlstrlen(const char * s)
+ /*@*/
+{
+ size_t len = 0;
+ int c;
+
+ while ((c = *s++) != '\0') {
+ switch (c) {
+ case '<': case '>': len += 4; /*@switchbreak@*/ break;
+ case '&': len += 5; /*@switchbreak@*/ break;
+ default: len += 1; /*@switchbreak@*/ break;
+ }
+ }
+ return len;
+}
+
+/**
+ */
+static char * xmlstrcpy(/*@returned@*/ char * t, const char * s)
+ /*@modifies t @*/
+{
+ char * te = t;
+ int c;
+
+ while ((c = *s++) != '\0') {
+ switch (c) {
+ case '<': te = stpcpy(te, "&lt;"); /*@switchbreak@*/ break;
+ case '>': te = stpcpy(te, "&gt;"); /*@switchbreak@*/ break;
+ case '&': te = stpcpy(te, "&amp;"); /*@switchbreak@*/ break;
+ default: *te++ = c; /*@switchbreak@*/ break;
+ }
+ }
+ *te = '\0';
+ return t;
+}
+
+/**
* Wrap tag data in simple header xml markup.
* @param type tag type
* @param data tag value
@@ -295,10 +333,11 @@ static /*@only@*/ char * xmlFormat(int_32 type, const void * data,
xtag = "integer";
}
- nb = 2 * strlen(xtag) + sizeof("\t<></>") + strlen(s);
+ nb = 2 * strlen(xtag) + sizeof("\t<></>") + xmlstrlen(s);
te = t = alloca(nb);
te = stpcpy( stpcpy( stpcpy(te, "\t<"), xtag), ">");
- te = stpcpy(te, s);
+ te = xmlstrcpy(te, s);
+ te += strlen(te);
te = stpcpy( stpcpy( stpcpy(te, "</"), xtag), ">");
/* XXX s was malloc'd */