From f3fff9f59ba63de895394b41a88ce16dbd1a44ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kou=C5=99il?= Date: Tue, 19 Sep 2006 16:50:08 +0000 Subject: [PATCH] Fix for #18880 if a message is split into several pieces during processing, the pieces aren't unescaped independently but the whole message is reconstructed first before the unescaping procedure is applied. --- org.glite.lb.common/src/xml_conversions.c | 82 ++++++++++++++++++++++++------- org.glite.lb.common/src/xml_parse.c.T | 32 +++++------- 2 files changed, 77 insertions(+), 37 deletions(-) diff --git a/org.glite.lb.common/src/xml_conversions.c b/org.glite.lb.common/src/xml_conversions.c index d914cce..eac5b41 100644 --- a/org.glite.lb.common/src/xml_conversions.c +++ b/org.glite.lb.common/src/xml_conversions.c @@ -7,6 +7,7 @@ #include "trio.h" #include "xml_conversions.h" +#include "escape.h" @@ -515,16 +516,25 @@ void edg_wll_add_time_t_list_to_XMLBody(char **body, const time_t *toAdd, const /* XMLCtx->eventsOutGlobal[XMLCtx->position].any.prog = edg_wll_from_string_to_string(XMLCtx); */ char *edg_wll_from_string_to_string(edg_wll_XML_ctx *XMLCtx) { - return(XMLCtx->char_buf); + char *s; + + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + edg_wll_freeBuf(XMLCtx); + return ret; } /* XMLCtx->eventsOutGlobal[XMLCtx->position].any.jobId = edg_wll_from_string_to_dgJobId(XMLCtx); */ edg_wlc_JobId edg_wll_from_string_to_jobid(edg_wll_XML_ctx *XMLCtx) { - edg_wlc_JobId out; + edg_wlc_JobId out = NULL; + char *s; - edg_wlc_JobIdParse(XMLCtx->char_buf, &out); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + edg_wlc_JobIdParse(s, &out); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -534,9 +544,14 @@ edg_wlc_JobId edg_wll_from_string_to_jobid(edg_wll_XML_ctx *XMLCtx) edg_wll_NotifId edg_wll_from_string_to_notifid(edg_wll_XML_ctx *XMLCtx) { - edg_wll_NotifId out; + edg_wll_NotifId out = NULL; + char *s; - edg_wll_NotifIdParse(XMLCtx->char_buf, &out); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + edg_wll_NotifIdParse(s, &out); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -546,9 +561,14 @@ edg_wll_NotifId edg_wll_from_string_to_notifid(edg_wll_XML_ctx *XMLCtx) edg_wll_JobStatCode edg_wll_from_string_to_edg_wll_JobStatCode(edg_wll_XML_ctx *XMLCtx) { - edg_wll_JobStatCode out; + edg_wll_JobStatCode out = EDG_WLL_JOB_UNDEF; + char *s; - out = edg_wll_StringToStat(XMLCtx->char_buf); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + out = edg_wll_StringToStat(s); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -561,9 +581,14 @@ edg_wll_JobStatCode edg_wll_from_string_to_edg_wll_JobStatCode(edg_wll_XML_ctx * edg_wll_from_string_to_int(XMLCtx); */ int edg_wll_from_string_to_int(edg_wll_XML_ctx *XMLCtx) { - int out; + int out = -1; + char *s; - out = atoi(XMLCtx->char_buf); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + out = atoi(s); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -575,9 +600,14 @@ int edg_wll_from_string_to_int(edg_wll_XML_ctx *XMLCtx) edg_wll_from_string_to_int(XMLCtx); */ float edg_wll_from_string_to_float(edg_wll_XML_ctx *XMLCtx) { - float out; + float out = -1; + char *s; - out = strtof(XMLCtx->char_buf, (char **) NULL); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + out = strtof(s, (char **) NULL); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -587,9 +617,14 @@ float edg_wll_from_string_to_float(edg_wll_XML_ctx *XMLCtx) long edg_wll_from_string_to_long(edg_wll_XML_ctx *XMLCtx) { - long out; + long out = -1; + char *s; - out = atol(XMLCtx->char_buf); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + out = atol(s); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -604,11 +639,16 @@ uint16_t edg_wll_from_string_to_uint16_t(edg_wll_XML_ctx *XMLCtx) struct timeval edg_wll_from_string_to_timeval(edg_wll_XML_ctx *XMLCtx) { - struct timeval out; + struct timeval out = {0,0}; char *needle, *nil; + char *s; - out.tv_sec = strtol(XMLCtx->char_buf, &needle, 10); - out.tv_usec = strtol(needle+1, &nil, 10); + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + out.tv_sec = strtol(s, &needle, 10); + out.tv_usec = strtol(needle+1, &nil, 10); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); @@ -623,8 +663,14 @@ time_t edg_wll_from_string_to_time_t(edg_wll_XML_ctx *XMLCtx) edg_wll_Source edg_wll_from_string_to_logsrc(edg_wll_XML_ctx *XMLCtx) { - edg_wll_Source out = edg_wll_StringToSource(XMLCtx->char_buf); - + edg_wll_Source out = EDG_WLL_SOURCE_NONE; + char *s; + + s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf); + if (s) { + out = edg_wll_StringToSource(s); + free(s); + } edg_wll_freeBuf(XMLCtx); return(out); } diff --git a/org.glite.lb.common/src/xml_parse.c.T b/org.glite.lb.common/src/xml_parse.c.T index cf265ff..800fc12 100644 --- a/org.glite.lb.common/src/xml_parse.c.T +++ b/org.glite.lb.common/src/xml_parse.c.T @@ -728,8 +728,8 @@ static void startStatsResult(void *data, const char *el, const char **attr) static void char_handler(void *data, const char *s, int len) { edg_wll_XML_ctx *XMLCtx = data; - int i, found = -1, temp_len1; - char *temp_s, *temp_s1; + int i, found = -1; + char *temp_s; /* if date are only spaces, t\, \r, \n ... don't bother with them */ @@ -737,23 +737,15 @@ static void char_handler(void *data, const char *s, int len) if (!isspace(s[i])) { found = i; break; } if (found == -1) return; - temp_s = malloc((len+1) * sizeof(char)); - - /* otherwise use them */ - memcpy(temp_s,s,len); - temp_s[len] = 0; - temp_s1 = edg_wll_UnescapeXML((const char *) temp_s); - temp_len1 = strlen(temp_s1); - - if (XMLCtx->char_buf_len) - XMLCtx->char_buf = realloc(XMLCtx->char_buf,XMLCtx->char_buf_len+temp_len1 + 1); - else - XMLCtx->char_buf = (char *) malloc(temp_len1 + 1); - - memcpy(XMLCtx->char_buf+XMLCtx->char_buf_len,temp_s1,temp_len1 + 1); - XMLCtx->char_buf_len += temp_len1; - free(temp_s1); - free(temp_s); + temp_s = realloc(XMLCtx->char_buf, XMLCtx->char_buf_len + len + 1); + if (temp_s == NULL) { + /* XXX propagate ENOMEM somehow */ + return; + } + XMLCtx->char_buf = temp_s; + memcpy(XMLCtx->char_buf + XMLCtx->char_buf_len, s, len); + XMLCtx->char_buf[XMLCtx->char_buf_len + len] = '\0'; + XMLCtx->char_buf_len += len; } @@ -891,6 +883,7 @@ static void endUserJobs(void *data, const char *el UNUSED_VAR) break; default: /* only level 2 tags should contain text fields */ + /* XXX is it necessary to unescape the data first? */ for (i=0; i < XMLCtx->char_buf_len; i++) if (!isspace(XMLCtx->char_buf[i])) unexpWarning() edg_wll_freeBuf(XMLCtx); @@ -1162,6 +1155,7 @@ static void endPurgeResult(void *data, const char *el UNUSED_VAR) if ( (XMLCtx->purgeResultGlobal.jobs[XMLCtx->position++] = edg_wll_from_string_to_string(XMLCtx)) == NULL ) { + /* XXX char_buf contains an escaped value, unescaping is done within edg_wll_from_string_to_string(), which failed */ if (XMLCtx->errtxt) { asprintf(&e,"%s\n%s: invalid JobId at line %d", XMLCtx->errtxt, XMLCtx->char_buf, -- 1.8.2.3