From: jbj Date: Wed, 12 Mar 2003 21:57:50 +0000 (+0000) Subject: Sanity. X-Git-Tag: rpm-4.4-release~662 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ed1cc2fa039332bc35517c3c7b433150da419ef6;p=platform%2Fupstream%2Frpm.git Sanity. CVS patchset: 6680 CVS date: 2003/03/12 21:57:50 --- diff --git a/lib/formats.c b/lib/formats.c index 0ce0614..cf07474 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, "<"); /*@switchbreak@*/ break; + case '>': te = stpcpy(te, ">"); /*@switchbreak@*/ break; + case '&': te = stpcpy(te, "&"); /*@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, ""); /* XXX s was malloc'd */ diff --git a/rpmdb/header.c b/rpmdb/header.c index 5fe87a1..1bbc96e 100644 --- a/rpmdb/header.c +++ b/rpmdb/header.c @@ -3327,10 +3327,10 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token, if (isxml) { const char * tagN = tagName(spft->u.tag.tag); - need = strlen(tagN) + sizeof(" \n") - 1; + need = strlen(tagN) + sizeof(" \n") - 1; t = hsaReserve(hsa, need); /*@-boundswrite@*/ - te = stpcpy(t, " \n"); /*@=boundswrite@*/ @@ -3348,10 +3348,10 @@ static char * singleSprintf(headerSprintfArgs hsa, sprintfToken token, } if (isxml) { - need = sizeof(" \n") - 1; + need = sizeof(" \n") - 1; t = hsaReserve(hsa, need); /*@-boundswrite@*/ - te = stpcpy(t, " \n"); + te = stpcpy(t, " \n"); /*@=boundswrite@*/ hsa->vallen += (te - t); }