Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Patch to work with intel sgx enclaves.
Browse files Browse the repository at this point in the history
Define LIBXML2_WITH_SGXSDK with your intel sgxsdk folder
Disable all io functions and define HAVE_STDIO_FOPEN_H check to disable
them
  • Loading branch information
florianbecker committed May 24, 2021
1 parent a46e85f commit 9b418bb
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 3 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON)
option(LIBXML2_WITH_XPATH "Add the XPATH support" ON)
option(LIBXML2_WITH_XPTR "Add the XPointer support" ON)
option(LIBXML2_WITH_ZLIB "Use libz" ON)
option(LIBXML2_WITH_SGXSDX "Use with intel sgxsdk")
set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite")

if(LIBXML2_WITH_SGXSDK)
set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "")
set(CMAKE_C_FLAGS "-I${LIBXML2_WITH_SGXSDK}/include/tlibc -m64 -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type -Waddress -Wsequence-point -Wformat-security -Wmissing-include-dirs -Wundef -Wshadow -Wcast-align -Wredundant-decls -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wnested-externs -Winline -Wno-format-extra-args -Wno-stringop-overflow -Wno-stringop-truncation -Wno-unused-but-set-variable -nostdinc -fvisibility=hidden -fpie -fexceptions -ffunction-sections -fdata-sections -fstack-protector-strong")
endif()

if(LIBXML2_WITH_ICONV)
find_package(Iconv REQUIRED)
endif()
Expand Down Expand Up @@ -202,10 +208,13 @@ else()
check_function_exists(sprintf HAVE_SPRINTF)
check_function_exists(srand HAVE_SRAND)
check_function_exists(sscanf HAVE_SSCANF)
check_function_exists(stat HAVE_STAT)
if(NOT LIBXML2_WITH_SGXSDK)
check_function_exists(stat HAVE_STAT)
endif()
check_include_files(stdarg.h HAVE_STDARG_H)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(stdlib.h HAVE_STDLIB_H)
check_symbol_exists(fopen stdio.h HAVE_STDIO_FOPEN_H)
check_function_exists(strftime HAVE_STRFTIME)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(string.h HAVE_STRING_H)
Expand Down
2 changes: 2 additions & 0 deletions buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ xmlBufInflate(xmlBufPtr buf, size_t len) {
* Dumps an XML buffer to a FILE *.
* Returns the number of #xmlChar written
*/
#ifdef HAVE_STDIO_FOPEN_H
size_t
xmlBufDump(FILE *file, xmlBufPtr buf) {
size_t ret;
Expand All @@ -568,6 +569,7 @@ xmlBufDump(FILE *file, xmlBufPtr buf) {
ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file);
return(ret);
}
#endif

/**
* xmlBufContent:
Expand Down
2 changes: 2 additions & 0 deletions buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ int xmlBufErase(xmlBufPtr buf, size_t len);

xmlChar * xmlBufDetach(xmlBufPtr buf);

#ifdef HAVE_STDIO_FOPEN_H
size_t xmlBufDump(FILE *file, xmlBufPtr buf);
#endif

xmlBufPtr xmlBufFromBuffer(xmlBufferPtr buffer);
xmlBufferPtr xmlBufBackToBuffer(xmlBufPtr buf);
Expand Down
3 changes: 3 additions & 0 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H 1

/* Define to 1 if you have the <stdio.h> header file, and it defines `fopen`. */
#cmakedefine HAVE_STDIO_FOPEN_H 1

/* Define to 1 if you have the `strftime' function. */
#cmakedefine HAVE_STRFTIME 1

Expand Down
6 changes: 6 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ void XMLCDECL
xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
va_list args;

#ifdef HAVE_STDIO_FOPEN_H
if (xmlGenericErrorContext == NULL)
xmlGenericErrorContext = (void *) stderr;
#endif

va_start(args, msg);
#ifdef HAVE_STDIO_FOPEN_H
vfprintf((FILE *)xmlGenericErrorContext, msg, args);
#endif
va_end(args);
}

Expand Down Expand Up @@ -631,9 +635,11 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
(channel == xmlParserValidityError) ||
(channel == xmlParserValidityWarning))
xmlReportError(to, ctxt, str, NULL, NULL);
#ifdef HAVE_STDIO_FOPEN_H
else if (((void(*)(void)) channel == (void(*)(void)) fprintf) ||
(channel == xmlGenericErrorDefaultFunc))
xmlReportError(to, ctxt, str, channel, data);
#endif
else
channel(data, "%s", str);
}
Expand Down
4 changes: 4 additions & 0 deletions include/libxml/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,11 @@ XMLPUBFUN int XMLCALL
unsigned int size);
XMLPUBFUN void XMLCALL
xmlBufferFree (xmlBufferPtr buf);
#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN int XMLCALL
xmlBufferDump (FILE *file,
xmlBufferPtr buf);
#endif
XMLPUBFUN int XMLCALL
xmlBufferAdd (xmlBufferPtr buf,
const xmlChar *str,
Expand Down Expand Up @@ -1171,6 +1173,7 @@ XMLPUBFUN void XMLCALL
int * doc_txt_len,
const char *txt_encoding,
int format);
#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN int XMLCALL
xmlDocFormatDump (FILE *f,
xmlDocPtr cur,
Expand All @@ -1182,6 +1185,7 @@ XMLPUBFUN void XMLCALL
xmlElemDump (FILE *f,
xmlDocPtr doc,
xmlNodePtr cur);
#endif
XMLPUBFUN int XMLCALL
xmlSaveFile (const char *filename,
xmlDocPtr cur);
Expand Down
2 changes: 2 additions & 0 deletions include/libxml/uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ XMLPUBFUN int XMLCALL
const char *str);
XMLPUBFUN xmlChar * XMLCALL
xmlSaveUri (xmlURIPtr uri);
#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN void XMLCALL
xmlPrintURI (FILE *stream,
xmlURIPtr uri);
#endif
XMLPUBFUN xmlChar * XMLCALL
xmlURIEscapeStr (const xmlChar *str,
const xmlChar *list);
Expand Down
4 changes: 4 additions & 0 deletions include/libxml/xmlIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ XMLPUBFUN xmlParserInputBufferPtr XMLCALL
XMLPUBFUN xmlParserInputBufferPtr XMLCALL
xmlParserInputBufferCreateFilename (const char *URI,
xmlCharEncoding enc);
#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN xmlParserInputBufferPtr XMLCALL
xmlParserInputBufferCreateFile (FILE *file,
xmlCharEncoding enc);
#endif
XMLPUBFUN xmlParserInputBufferPtr XMLCALL
xmlParserInputBufferCreateFd (int fd,
xmlCharEncoding enc);
Expand Down Expand Up @@ -229,9 +231,11 @@ XMLPUBFUN xmlOutputBufferPtr XMLCALL
xmlCharEncodingHandlerPtr encoder,
int compression);

#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN xmlOutputBufferPtr XMLCALL
xmlOutputBufferCreateFile (FILE *file,
xmlCharEncodingHandlerPtr encoder);
#endif

XMLPUBFUN xmlOutputBufferPtr XMLCALL
xmlOutputBufferCreateBuffer (xmlBufferPtr buffer,
Expand Down
2 changes: 2 additions & 0 deletions include/libxml/xmlmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ XMLPUBFUN int XMLCALL
xmlMemUsed (void);
XMLPUBFUN int XMLCALL
xmlMemBlocks (void);
#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN void XMLCALL
xmlMemDisplay (FILE *fp);
XMLPUBFUN void XMLCALL
xmlMemDisplayLast(FILE *fp, long nbBytes);
XMLPUBFUN void XMLCALL
xmlMemShow (FILE *fp, int nr);
#endif
XMLPUBFUN void XMLCALL
xmlMemoryDump (void);
XMLPUBFUN void * XMLCALL
Expand Down
2 changes: 2 additions & 0 deletions include/libxml/xmlregexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ XMLPUBFUN void XMLCALL xmlRegFreeRegexp(xmlRegexpPtr regexp);
XMLPUBFUN int XMLCALL
xmlRegexpExec (xmlRegexpPtr comp,
const xmlChar *value);
#ifdef HAVE_STDIO_FOPEN_H
XMLPUBFUN void XMLCALL
xmlRegexpPrint (FILE *output,
xmlRegexpPtr regexp);
#endif
XMLPUBFUN int XMLCALL
xmlRegexpIsDeterminist(xmlRegexpPtr comp);

Expand Down
2 changes: 2 additions & 0 deletions parserInternals.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ xmlCheckVersion(int version) {
xmlGenericError(xmlGenericErrorContext,
"Fatal: program compiled against libxml %d using libxml %d\n",
(version / 10000), (myversion / 10000));
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr,
"Fatal: program compiled against libxml %d using libxml %d\n",
(version / 10000), (myversion / 10000));
#endif
}
if ((myversion / 100) < (version / 100)) {
xmlGenericError(xmlGenericErrorContext,
Expand Down
20 changes: 19 additions & 1 deletion relaxng.c
Original file line number Diff line number Diff line change
Expand Up @@ -3244,9 +3244,11 @@ xmlRelaxNGCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
case XML_RELAXNG_LIST:
case XML_RELAXNG_PARAM:
case XML_RELAXNG_VALUE:
/* This should not happen and generate an internal error */
#ifdef HAVE_STDIO_FOPEN_H
/* This should not happen and generate an internal error */
fprintf(stderr, "RNG internal error trying to compile %s\n",
xmlRelaxNGDefName(def));
#endif
break;
}
return (ret);
Expand Down Expand Up @@ -7969,24 +7971,32 @@ xmlRelaxNGValidateCompiledCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED,
"Compiled callback for: '%s'\n", token);
#endif
if (ctxt == NULL) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s missing context\n", token);
#endif
return;
}
if (define == NULL) {
if (token[0] == '#')
return;
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s missing define\n", token);
#endif
if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
return;
}
if ((ctxt == NULL) || (define == NULL)) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s missing info\n", token);
#endif
if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
return;
} else if (define->type != XML_RELAXNG_ELEMENT) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s define is not element\n", token);
#endif
if (ctxt->errNo == XML_RELAXNG_OK)
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
return;
Expand Down Expand Up @@ -8184,28 +8194,36 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec
"Progressive callback for: '%s'\n", token);
#endif
if (ctxt == NULL) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s missing context\n", token);
#endif
return;
}
node = ctxt->pnode;
ctxt->pstate = 1;
if (define == NULL) {
if (token[0] == '#')
return;
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s missing define\n", token);
#endif
if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
ctxt->pstate = -1;
return;
}
if ((ctxt == NULL) || (define == NULL)) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s missing info\n", token);
#endif
if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
ctxt->pstate = -1;
return;
} else if (define->type != XML_RELAXNG_ELEMENT) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "callback on %s define is not element\n", token);
#endif
if (ctxt->errNo == XML_RELAXNG_OK)
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
ctxt->pstate = -1;
Expand Down
2 changes: 2 additions & 0 deletions timsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ static void TIM_SORT_RESIZE(TEMP_STORAGE_T *store, const size_t new_size) {
SORT_TYPE *tempstore = (SORT_TYPE *)realloc(store->storage, new_size * sizeof(SORT_TYPE));

if (tempstore == NULL) {
#ifdef HAVE_STDIO_FOPEN_H
fprintf(stderr, "Error allocating temporary storage for tim sort: need %lu bytes",
(unsigned long)(sizeof(SORT_TYPE) * new_size));
#endif
exit(1);
}

Expand Down
2 changes: 2 additions & 0 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -7362,6 +7362,7 @@ xmlBufferGrow(xmlBufferPtr buf, unsigned int len) {
* Dumps an XML buffer to a FILE *.
* Returns the number of #xmlChar written
*/
#ifdef HAVE_STDIO_FOPEN_H
int
xmlBufferDump(FILE *file, xmlBufferPtr buf) {
int ret;
Expand All @@ -7385,6 +7386,7 @@ xmlBufferDump(FILE *file, xmlBufferPtr buf) {
ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file);
return(ret);
}
#endif

/**
* xmlBufferContent:
Expand Down
2 changes: 2 additions & 0 deletions uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ xmlSaveUri(xmlURIPtr uri) {
*
* Prints the URI in the stream @stream.
*/
#ifdef HAVE_STDIO_FOPEN_H
void
xmlPrintURI(FILE *stream, xmlURIPtr uri) {
xmlChar *out;
Expand All @@ -1346,6 +1347,7 @@ xmlPrintURI(FILE *stream, xmlURIPtr uri) {
xmlFree(out);
}
}
#endif

/**
* xmlCleanURI:
Expand Down
Loading

0 comments on commit 9b418bb

Please sign in to comment.