Skip to content

Commit c0cddff

Browse files
committed
Detect encoded character entities in properties
1 parent 040a96b commit c0cddff

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

das2/descriptor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ DasErrCode _DasDesc_encode(
981981
DasBuf_puts(pBuf, DasProp_xmlValue(pProp, sDynaBuf, uEscapeSz));
982982
free(sDynaBuf);
983983
}
984-
else{
984+
else{
985+
memset(sStaticBuf, 0, _STACK_BUF_LEN);
985986
DasBuf_puts(pBuf, DasProp_xmlValue(pProp, sStaticBuf, _STACK_BUF_LEN-1));
986987
}
987988
}

das2/property.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,44 @@ const char* DasProp_value(const DasProp* pProp)
324324
return sBuf + uOffset;
325325
}
326326

327+
/* TODO: Add a unittest for this thing, it need's it */
327328
size_t DasProp_escapeSize(const DasProp* pProp)
328329
{
329330
size_t uEscapeSz = 0;
330331

331332
bool bNeedXlate = false;
332333
const char* p = DasProp_value(pProp);
333334

335+
static const char* entities[] = {"lt;", "gt;", "quot;", "apos;", "amp;"};
336+
size_t uEntLen = 0;
337+
bool bEnt = false;
338+
int i = 0;
339+
334340
while(*p != '\0'){
335-
if((*p == '"')||(*p == '\'')||(*p == '<')||(*p == '>')||(*p == '&')){
341+
if((*p == '"')||(*p == '\'')||(*p == '<')||(*p == '>')){
336342
bNeedXlate = true;
337343
uEscapeSz += 6;
338344
}
345+
else if(*p == '&'){
346+
/* This one is a pain, because the text may *already* be escaped
347+
and this is the start of a character entity (yay)
348+
349+
All the strlen checks etc. could be avoided below with extra
350+
loop state combined with a small lookup table on the stack
351+
but this will do for now.
352+
*/
353+
bEnt = false;
354+
for(i = 0; i < 5; ++i){
355+
uEntLen = strlen(entities[i]);
356+
if(strncmp(p+1, entities[i], uEntLen) == 0){
357+
p += (uEntLen + 1);
358+
uEscapeSz += (uEntLen + 1);
359+
bEnt = true;
360+
break;
361+
}
362+
}
363+
bNeedXlate = ! bEnt;
364+
}
339365
else{
340366
uEscapeSz += 1;
341367
}

das2/vector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const char* das_compsys_desc(ubyte uST)
117117
"if missing.";
118118
case DAS_VSYS_SPH:
119119
return "An ISO 31-11 standard spherical system. The full component set "
120-
"is (r,θ,φ) where r is the radial diretion, θ is the colatitude "
120+
"is (r,θ,φ) where r is the radial direction, θ is the colatitude "
121121
"(which is 0° at the north pole) and φ is the eastward angle. "
122122
"Both θ, φ are assumed to be 0° if missing and r is assumed to "
123123
"be 1 if missing.";

0 commit comments

Comments
 (0)