Commit 0b071666 authored by Pieter Hintjens's avatar Pieter Hintjens Committed by Martin Sustrik

multiple vulnerabilities in xml paerser fixed

parent 8a4df431
...@@ -421,7 +421,7 @@ XMLNode XMLNode::openFileHelper(XMLCSTR filename, XMLCSTR tag) ...@@ -421,7 +421,7 @@ XMLNode XMLNode::openFileHelper(XMLCSTR filename, XMLCSTR tag)
// create message // create message
char message[2000],*s1=(char*)"",*s3=(char*)""; XMLCSTR s2=_CXML(""); char message[2000],*s1=(char*)"",*s3=(char*)""; XMLCSTR s2=_CXML("");
if (pResults.error==eXMLErrorFirstTagNotFound) { s1=(char*)"First Tag should be '"; s2=tag; s3=(char*)"'.\n"; } if (pResults.error==eXMLErrorFirstTagNotFound) { s1=(char*)"First Tag should be '"; s2=tag; s3=(char*)"'.\n"; }
sprintf(message, snprintf(message,2000,
#ifdef _XMLWIDECHAR #ifdef _XMLWIDECHAR
"XML Parsing error inside file '%S'.\n%S\nAt line %i, column %i.\n%s%S%s" "XML Parsing error inside file '%S'.\n%S\nAt line %i, column %i.\n%s%S%s"
#else #else
...@@ -608,11 +608,18 @@ XMLError XMLNode::writeToFile(XMLCSTR filename, const char *encoding, char nForm ...@@ -608,11 +608,18 @@ XMLError XMLNode::writeToFile(XMLCSTR filename, const char *encoding, char nForm
if (!f) return eXMLErrorCannotOpenWriteFile; if (!f) return eXMLErrorCannotOpenWriteFile;
#ifdef _XMLWIDECHAR #ifdef _XMLWIDECHAR
unsigned char h[2]={ 0xFF, 0xFE }; unsigned char h[2]={ 0xFF, 0xFE };
if (!fwrite(h,2,1,f)) return eXMLErrorCannotWriteFile; if (!fwrite(h,2,1,f))
{
fclose(f);
return eXMLErrorCannotWriteFile;
}
if ((!isDeclaration())&&((d->lpszName)||(!getChildNode().isDeclaration()))) if ((!isDeclaration())&&((d->lpszName)||(!getChildNode().isDeclaration())))
{ {
if (!fwrite(L"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n",sizeof(wchar_t)*40,1,f)) if (!fwrite(L"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n",sizeof(wchar_t)*40,1,f))
{
fclose(f);
return eXMLErrorCannotWriteFile; return eXMLErrorCannotWriteFile;
}
} }
#else #else
if ((!isDeclaration())&&((d->lpszName)||(!getChildNode().isDeclaration()))) if ((!isDeclaration())&&((d->lpszName)||(!getChildNode().isDeclaration())))
...@@ -620,23 +627,41 @@ XMLError XMLNode::writeToFile(XMLCSTR filename, const char *encoding, char nForm ...@@ -620,23 +627,41 @@ XMLError XMLNode::writeToFile(XMLCSTR filename, const char *encoding, char nForm
if (characterEncoding==char_encoding_UTF8) if (characterEncoding==char_encoding_UTF8)
{ {
// header so that windows recognize the file as UTF-8: // header so that windows recognize the file as UTF-8:
unsigned char h[3]={0xEF,0xBB,0xBF}; if (!fwrite(h,3,1,f)) return eXMLErrorCannotWriteFile; unsigned char h[3]={0xEF,0xBB,0xBF};
if (!fwrite(h,3,1,f))
{
fclose(f);
return eXMLErrorCannotWriteFile;
}
encoding="utf-8"; encoding="utf-8";
} else if (characterEncoding==char_encoding_ShiftJIS) encoding="SHIFT-JIS"; } else if (characterEncoding==char_encoding_ShiftJIS) encoding="SHIFT-JIS";
if (!encoding) encoding="ISO-8859-1"; if (!encoding) encoding="ISO-8859-1";
if (fprintf(f,"<?xml version=\"1.0\" encoding=\"%s\"?>\n",encoding)<0) return eXMLErrorCannotWriteFile; if (fprintf(f,"<?xml version=\"1.0\" encoding=\"%s\"?>\n",encoding)<0)
{
fclose(f);
return eXMLErrorCannotWriteFile;
}
} else } else
{ {
if (characterEncoding==char_encoding_UTF8) if (characterEncoding==char_encoding_UTF8)
{ {
unsigned char h[3]={0xEF,0xBB,0xBF}; if (!fwrite(h,3,1,f)) return eXMLErrorCannotWriteFile; unsigned char h[3]={0xEF,0xBB,0xBF};
if (!fwrite(h,3,1,f))
{
fclose(f);
return eXMLErrorCannotWriteFile;
}
} }
} }
#endif #endif
int i; int i;
XMLSTR t=createXMLString(nFormat,&i); XMLSTR t=createXMLString(nFormat,&i);
if (!fwrite(t,sizeof(XMLCHAR)*i,1,f)) return eXMLErrorCannotWriteFile; if (!fwrite(t,sizeof(XMLCHAR)*i,1,f))
{
fclose(f);
return eXMLErrorCannotWriteFile;
}
if (fclose(f)!=0) return eXMLErrorCannotWriteFile; if (fclose(f)!=0) return eXMLErrorCannotWriteFile;
free(t); free(t);
return eXMLErrorNone; return eXMLErrorNone;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment